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
|
# testsuite_if_include section for BASIC256
# Modification History
# date programmer description
# 20140203 j.m.reneau added crazy if structures when if/then/else
# moved to a statement and not a stand alone line (1010002)
# 201603330 j.m.reneau added section to test values for true/false
# 20160807 j.m.reneau added tests of and, or, xor, and not
currentsuite = "if"
s = 0
for t = 1 to 10
if t <= 5 then
if t <=3 then
s = s + 1
else
s = s + 10
end if
else
if t <= 8 then
s = s + 100
else
s = s + 1000
end if
end if
next t
call n("multi line if", s, 2323)
# multi line all with :
s = 0:for t = 1 to 10:if t <= 5 then:if t <=3 then:s = s + 1:else:s = s + 10:end if:else:if t <= 8 then:s = s + 100:else:s = s + 1000:end if:end if:next t
call n("multi line if compound (one line :)", s, 2323)
# multi line with ITE
s = 0
for t = 1 to 10
if t <= 5 then
if t <=3 then s = s + 1 else s = s + 10
else
if t <= 8 then s = s + 100 else s = s + 1000
end if
next t
call n("multi line if (with single line if then elses)", s, 2323)
# multi line with ITE with :
# cant combine three lines because the compound statement in else clause of the ITE
s = 0:for t = 1 to 10:if t <= 5 then:if t <=3 then s = s + 1 else s = s + 10
else :if t <= 8 then s = s + 100 else s = s + 1000
end if:next t
call n("multi line if compound (with single line if then elses)", s, 2323)
# single line ITE (cant put next on end as part of last else compound
# else is associated with closest then without an else
s = 0:for t = 1 to 10:if t <= 5 then if t <=3 then s = s + 1 else s = s + 10 else if t <= 8 then s = s + 100 else s = s + 1000
next t
call n("single line if then else nested", s, 2323)
# test case
s = 0
for t = 1 to 10
begin case
case t <=3
s+=1
case t <=5
s+=10
case t <=8
s+=100
else
s+=1000
end case
next t
call n("case", s, 2323)
# test case single line
s = 0:for t = 1 to 10:begin case:case t<=3:s+=1:case t <=5:s+=10:case t<=8:s+=100:else:s+=1000:end case:next t
call n("case compound", s, 2323)
# test values as true and false
a = {"", "hello", 0, 1223, -112, 0.00, 0.0000000001, 12312.23, 1233123123124234.123123 }
b = {false, true, false, true, true, false, false, true, true }
for i = 0 to a[?]-1
call n(a[i] ; " is "; b[i], not not a[i], b[i])
next i
# test OR
call n("0 or 0",0 or 0, 0)
call n("0 or 1",0 or 1, 1)
call n("1 or 0",1 or 0, 1)
call n("1 or 1",1 or 1, 1)
# test Xor
call n("0 xor 0",0 xor 0, 0)
call n("0 xor 1",0 xor 1, 1)
call n("1 xor 0",1 xor 0, 1)
call n("1 xor 1",1 xor 1, 0)
# test and
call n("0 and 0",0 and 0, 0)
call n("0 and 1",0 and 1, 0)
call n("1 and 0",1 and 0, 0)
call n("1 and 1",1 and 1, 1)
# test not
call n("not 0",not 0, 1)
call n("not 1",not 1, 0)
|