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
|
# testsuite_array_include section for BASIC256
# Modification History
# date programmer description
# 20160807 j.m.reneau split from test suite and added many new tests
# 20160908 j.m.reneau added serialize and unserialize
# 20161101 j.m.reneau added [] to all array passing to functions
# 20200403 j.m.reneau added all of the various ways to copy an array to an array
currentsuite = "array"
###################################################
call section("1D Array")
###################################################
dim c = {9,8,7,6,5,4,3,2,1,0}
dim a = explode("9=8=7=6=5=4=3=2=1=0","=")
for t = 0 to a[?]-1
call n("a["+t+"] = c["+t+"] after dim explode",a[t],c[t])
next t
unassign(a)
dim a = c[]
for t = 0 to a[?]-1
call n("a["+t+"] = c["+t+"] after dim copy",a[t],c[t])
next t
call n("c[1]=8 after immediate assign",c[1],8)
call n("c[8]=1 after immediate assign",c[8],1)
c[0] = c[0] + c[8] : call n("c[0] after c[0] = c[0] + c[8]", c[0], 10)
c[0] += c[7] : call n("c[0] after c[0] += c[7]", c[0], 12)
c[0] -= c[6] : call n("c[0] after c[0] -= c[6]", c[0], 9)
c[1] *= c[2] : call n("c[1] after c[1] *= c[2]", c[1], 56)
c[1] /= c[7] : call n("c[1] after c[1] /= c[7]", c[1], 28.0)
redim c(20)
call n("c[1]=28 after redim",c[1],28)
call n("c[9]=0 after redim",c[9],0)
input "Input the number -3.14 > ", c[2]
call n("c[2]=-3.14 after rinput",c[2],-3.14)
input "Input the string 'crap' > ", c[2]
call s("c[2]=crap after input crap",c[2],"crap")
a = implode(c,"|")
call s("implode c with delim",a,"9|28.0|crap|6|5|4|3|2|1|0||||||||||")
a = implode(c[])
call s("implode c with no delim",a,"928.0crap6543210")
b = serialize(c[])
print b
a = unserialize(b)
for t = 0 to a[?]-1
call n("a["+t+"] = c["+t+"] after serialize and unserialize",a[t],c[t])
next t
###################################################
call section("2D Array")
###################################################
dim twod(10,10)
for t = 0 to twod[?,]-1
for u = 0 to twod[,?]-1
twod[t,u] = t*100+u
next u
next t
call n("twod[5,7]=507 after assign",twod[5,7],507)
twod[5,7]+=7
call n("twod[5,7] after twod[5,7]+=7",twod[5,7],514)
twod[5,7]-=7
call n("twod[5,7] after twod[5,7]-=7",twod[5,7],507)
twod[5,7]*=7
call n("twod[5,7] after twod[5,7]*=7",twod[5,7],3549)
twod[5,7]/=7
call n("twod[5,7] after twod[5,7]/=7",twod[5,7],507)
twod[5,7]++
call n("twod[5,7] after twod[5,7]++",twod[5,7],508)
twod[5,7]--
call n("twod[5,7] after twod[5,7]--",twod[5,7],507)
for t = 0 to twod[?,]-1
for u = 0 to twod[,?]-1
call n("twod["+t+","+u+"] as originally assigned",twod[t,u],t*100+u)
next u
next t
input "Input the number -3.14 > ", twod[2,1]
call n("twod[2,1]=-3.14 after rinput",twod[2,1],-3.14)
input "Input the string 'crap' > ", twod[3,2]
call n("twod[3,2]=crap after input crap",twod[3,2],"crap")
call s("2d implode with two delim",implode(twod[],"~","|"),"0|1|2|3|4|5|6|7|8|9~100|101|102|103|104|105|106|107|108|109~200|-3.14|202|203|204|205|206|207|208|209~300|301|crap|303|304|305|306|307|308|309~400|401|402|403|404|405|406|407|408|409~500|501|502|503|504|505|506|507.0|508|509~600|601|602|603|604|605|606|607|608|609~700|701|702|703|704|705|706|707|708|709~800|801|802|803|804|805|806|807|808|809~900|901|902|903|904|905|906|907|908|909")
call s("2d implode with one delim",implode(twod[],"|"),"0|1|2|3|4|5|6|7|8|9|100|101|102|103|104|105|106|107|108|109|200|-3.14|202|203|204|205|206|207|208|209|300|301|crap|303|304|305|306|307|308|309|400|401|402|403|404|405|406|407|408|409|500|501|502|503|504|505|506|507.0|508|509|600|601|602|603|604|605|606|607|608|609|700|701|702|703|704|705|706|707|708|709|800|801|802|803|804|805|806|807|808|809|900|901|902|903|904|905|906|907|908|909")
call s("2d implode with no delim",implode(twod[]),"0123456789100101102103104105106107108109200-3.14202203204205206207208209300301crap303304305306307308309400401402403404405406407408409500501502503504505506507.0508509600601602603604605606607608609700701702703704705706707708709800801802803804805806807808809900901902903904905906907908909")
dim c = twod[]
for t = 0 to twod[?,]-1
for u = 0 to twod[,?]-1
call s("twod["+t+","+u+"] = c["+t+","+u+"] afer dim copy",twod[t,u],c[t,u])
next u
next t
b = serialize(twod[])
c = unserialize(b)
for t = 0 to twod[?,]-1
for u = 0 to twod[,?]-1
call s("twod["+t+","+u+"] = c["+t+","+u+"] afer serialize and unserialize",twod[t,u],c[t,u])
next u
next t
c = {{1,2,3},{4,5,6},{7,8,9}}
for t = 0 to c[?,]-1
for u = 0 to c[,?]-1
call s("c["+t+","+u+"] = "+(t*3+u+1)+"] afer dim listoflists",(t*3+u+1),c[t,u])
next u
next t
### all of the ways to assign an array
a[] = {1,2,3}
call s("assign var[] list","1.2.3",implode(a,'.'))
b = {1,2,3}
call s("assign var list","1.2.3",implode(b,'.'))
b=""
dim b[] = {1,2,3}
call s("assign dim var[] list","1.2.3",implode(b,'.'))
b = ""
dim b = {1,2,3}
call s("assign dim var","1.2.3",implode(b,'.'))
b = ""
b = a
call s("assign var = var (array)","1.2.3",implode(b,'.'))
b = ""
b = a[]
call s("assign var = var[]","1.2.3",implode(b,'.'))
b = ""
b[] = a
call s("assign var[] = var","1.2.3",implode(b,'.'))
b = ""
b[] = a[]
call s("assign var[] = var[]","1.2.3",implode(b,'.'))
b = ""
dim b[] = a
call s("assign dim var[] = var","1.2.3",implode(b,'.'))
b = ""
dim b = a
call s("assign dim var = var","1.2.3",implode(b,'.'))
b = ""
dim b[] = a[]
call s("assign dim var[] = var[]","1.2.3",implode(b,'.'))
b = ""
dim b = a[]
call s("assign dim var = var[]","1.2.3",implode(b,'.'))
|