1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
# testsuite_types_include section for BASIC256
# Modification History
# date programmer description
# 20151123 j.m.reneau original coding 1.99.99.1
# 20151129 j.m.reneau combined vartype and typeof
# 20151205 j.m.reneau addec constants for types and added type_int
# added tests for integer save and non safe operations
# added test for integer safe for loops
# 20160208 j.m.reneau added input and prompt for new "Variant" input action
# 20160807 j.m.reneau removed typeof check on an array
# 20200421 j.m.reneau moved input testing to inputkey
# 20200423 j.m.reneau added map type and assigned (as it is rerlated to type)
currentsuite = "types"
# variable types and data types from the stack
# types are 0-unassigned, 1-numeric, 2-string, 3-array, and 4-a reference to a variable
## check vartype and typeof for a simple variable
call n("typeof unassigned newvar ", typeof(newvar), TYPE_UNASSIGNED)
call boolean("assigned unassigned newvar ", not assigned(newvar))
newvar = 983749823
call n("typeof int newvar ", typeof(newvar), TYPE_INT)
call boolean("assigned newvar ", assigned(newvar))
newvar = 983749823/2
call n("typeof float newvar ", typeof(newvar), TYPE_FLOAT)
newvar = "9988"
call n("typeof string newvar ", typeof(newvar), TYPE_STRING)
# check vartype and typeof for array elements
dim newvar(5)
newvar[1] = 213123
newvar[2] = newvar[1] / 11
newvar[3] = "dsdf"
call n("typeof array newvar ", typeof(newvar), TYPE_ARRAY)
call n("typeof unassigned newvar[0] ", typeof(newvar[0]), TYPE_UNASSIGNED)
call boolean("not assigned newvar[0] ", not assigned(newvar[0]))
call n("typeof int newvar[1] ", typeof(newvar[1]), TYPE_INT)
call boolean("assigned newvar[1] ", assigned(newvar[1]))
call n("typeof float newvar[2] ", typeof(newvar[2]), TYPE_FLOAT)
call n("typeof string newvar[3] ", typeof(newvar[3]), TYPE_STRING)
unassign newvar[1]
call boolean("not assigned newvar[1] after unassign", not assigned(newvar[1]))
map newvar
newvar['foo'] = 'bar'
newvar['you'] = 11
newvar['who'] = 6.8
call n("typeof map newvar ", typeof(newvar), TYPE_MAP)
call n("typeof unassigned newvar['can'] ", typeof(newvar['can']), TYPE_UNASSIGNED)
call boolean("not assigned newvar['can'] ", not assigned(newvar['can']))
call n("typeof int newvar['you'] ", typeof(newvar['you']), TYPE_INT)
call boolean("assigned newvar['you'] ", assigned(newvar['you']))
call n("typeof float newvar['who'] ", typeof(newvar['who']), TYPE_FLOAT)
call n("typeof string newvar['foo'] ", typeof(newvar['foo']), TYPE_STRING)
unassign newvar['you']
call boolean("not assigned newvar['you'] after unassign", not assigned(newvar['you']))
unassign newvar
call boolean("not assigned newvar after unassign", not assigned(newvar))
# check typeof for various mathematical operations and values one more time
## add (integer safe) and concat
a = 1 + 2
call n("a = 1 + 2 == 3", a, 3)
call n("typeof a = 1 + 2", typeof(a), TYPE_INT)
a = 1.1 + 2
call n("a = 1.1 + 2 == 3.1", a, 3.1)
call n("typeof a = 1.1 + 2", typeof(a), TYPE_FLOAT)
a = 1 + 2.2
call n("a = 1 + 2.2 == 3.2", a, 3.2)
call n("typeof a = 1 + 2.2", typeof(a), TYPE_FLOAT)
a = 1.1 + 2.2
call n("a = 1.1 + 2.2 == 3.3", a, 3.3)
call n("typeof a = 1.1 + 2.2", typeof(a), TYPE_FLOAT)
a = 'a' + 2
call s("a = 'a' + 2 == 'a2'", a, 'a2')
call n("typeof a = 'a' + 2", typeof(a), TYPE_STRING)
a = 1 + 'b'
call s("a = 1 + 'b' == '1b'", a, '1b')
call n("typeof a = 1 + 'b'", typeof(a), TYPE_STRING)
a = 'a' + 'b'
call s("a = 'a' + 'b' == 'ab'", a, 'ab')
call n("typeof a = 'a' + 'b'", typeof(a), TYPE_STRING)
## subtract (integer safe)
a = 1 - 2
call n("a = 1 - 2 == 3", a, -1)
call n("typeof a = 1 - 2", typeof(a), TYPE_INT)
a = 1.1 - 2
call n("a = 1.1 - 2 == -0.9", a, -0.9)
call n("typeof a = 1.1 - 2", typeof(a), TYPE_FLOAT)
a = 1 - 2.2
call n("a = 1 - 2.2 == -1.2", a, -1.2)
call n("typeof a = 1 - 2.2", typeof(a), TYPE_FLOAT)
a = 1.1 - 2.2
call n("a = 1.1 - 2.2 == -1.1", a, -1.1)
call n("typeof a = 1.1 - 2.2", typeof(a), TYPE_FLOAT)
## multiply (integer safe)
a = 1 * 2
call n("a = 1 * 2 == 2", a, 2)
call n("typeof a = 1 * 2", typeof(a), TYPE_INT)
a = 1.1 * 2
call n("a = 1.1 * 2 == 2.2", a, 2.2)
call n("typeof a = 1.1 * 2", typeof(a), TYPE_FLOAT)
a = 1 * 2.2
call n("a = 1 * 2.2 == 2.2", a, 2.2)
call n("typeof a = 1 * 2.2", typeof(a), TYPE_FLOAT)
a = 1.1 * 2.2
call n("a = 1.1 * 2.2 == 2.42", a, 2.42)
call n("typeof a = 1.1 * 2.2", typeof(a), TYPE_FLOAT)
## Modulo (integer safe)
a = 1 % 2
call n("a = 1 % 2 == 1", a, 1)
call n("typeof a = 1 % 2", typeof(a), TYPE_INT)
a = 1.1 % 2
call n("a = 1.1 % 2 == 1", a, 1)
call n("typeof a = 1.1 % 2", typeof(a), TYPE_INT)
a = 1 % 2.2
call n("a = 1 % 2.2 == 1", a, 1)
call n("typeof a = 1 % 2.2", typeof(a), TYPE_INT)
a = 1.1 % 2.2
call n("a = 1.1 % 2.2 == 1", a, 1)
call n("typeof a = 1.1 % 2.2", typeof(a), TYPE_INT)
## negate
a = 1
a = -a
call n("a = -a (1)", a, -1)
call n("typeof a = -a (1)", typeof(a), TYPE_INT)
a = 1.1
a = -a
call n("a = -a (1.1)", a, -1.1)
call n("typeof a = 0a (1.1)", typeof(a), TYPE_FLOAT)
## exp (ALAWYS A FLOAT)
a = 1 ^ 2
call n("a = 1 ^ 2 == 1", a, 1)
call n("typeof a = 1 ^ 2", typeof(a), TYPE_FLOAT)
a = 1.1 ^ 2
call n("a = 1.1 ^ 2 == 1.21", a, 1.21)
call n("typeof a = 1.1 ^ 2", typeof(a), TYPE_FLOAT)
a = 1 ^ 2.2
call n("a = 1 ^ 2.2 == 1", a, 1)
call n("typeof a = 1 ^ 2.2", typeof(a), TYPE_FLOAT)
a = 1.1 ^ 2.2
call n("a = 1.1 ^ 2.2 == 1.2332863005546625109890005879521", a, 1.2332863005546625109890005879521)
call n("typeof a = 1.1 ^ 2.2", typeof(a), TYPE_FLOAT)
## testing integer safe and not for loops
t = 0
for i = 1 to 10
call n("int1-10 i", typeof(i), TYPE_INT)
t+=i
next i
call n("int1-10 t", typeof(t), TYPE_INT)
call n("int1-10 total", t, 55)
t = 0
for i = 10 to 1 step -1
call n("int10-1 i="+i, typeof(i), TYPE_INT)
t+=i
next i
call n("int10-1 t", typeof(t), TYPE_INT)
call n("int10-1 total", t, 55)
t = 0
for i = 1 to 10 step 2
call n("int1-10,2 i="+i, typeof(i), TYPE_INT)
t+=i
next i
call n("int1-10,2 t", typeof(t), TYPE_INT)
call n("int1-10,2 total", t, 25)
t = 0
for i = 9 to -1 step -2
call n("int9-0,-2 i="+i, typeof(i), TYPE_INT)
t+=i
next i
call n("int9-0,-2 t", typeof(t), TYPE_INT)
call n("int9-0,-2 total", t, 24)
t = 0
for i = .5 to 9.5 step .5
call n("float.5-9,5,.5 i="+i, typeof(i), TYPE_FLOAT)
t+=i
next i
call n("float.5-9,5,.5 t", typeof(t), TYPE_FLOAT)
call n("float.5-9,5,.5 total", t, 95)
t = 0
for i = 9.5 to .5 step -.5
call n("float9.5-,5,-.5 i="+i, typeof(i), TYPE_FLOAT)
t+=i
next i
call n("float9.5-,5,-.5 t", typeof(t), TYPE_FLOAT)
call n("float9.5-,5,-.5 total", t, 95)
#isnumeric convert
a = 0
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " int*1 self", int(a)*1, a)
a = -12312
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " int*1 self", int(a)*1, a)
a = 42342342
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " int*1 self", int(a)*1, a)
a = 2345.3424
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = -12123.324
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = "0"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " int*1 self", int(a)*1, a)
a = "-120"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " int*1 self", int(a)*1, a)
a = "123234"
call n(a; " int*1 self", int(a)*1, a)
call n(a; " isnumeric", isnumeric(a), true)
a = "23423.12"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = "-2342.234"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = "2e7"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = "+2e7"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
a = "-2.345e-7"
call n(a; " isnumeric", isnumeric(a), true)
call n(a; " float*1 self", float(a)*1, a)
|