set x = [] set y = [:] set machinery = [#gears:6, #balls:3, #ramps:8] set nested = [1, 2, [3, 4], 5] set gList = ["car":1, "boat": 20] set a to [1, 2, 3] put a set gList = [point(70, 190), point(217, 66), point(364, 185)] set gBugList = [[energy: 10, mood: "Happy"], [energy: -10, mood: "Sad"], [energy: 60, mood: "Hungry"], [energy: 20, mood: "Sad"]] set b to [4, 5, 6, 7] scummvmAssertEqual(string(a + b), "[5, 7, 9]") scummvmAssertEqual(string(a - b), "[-3, -3, -3]") scummvmAssertEqual(string(a * b), "[4, 10, 18]") scummvmAssertEqual(string(b / a), "[4, 2, 2]") scummvmAssertEqual(string(b mod a), "[0, 1, 0]") scummvmAssertEqual(string(-a), "[-1, -2, -3]") set floats to [4.0, 5.0, 6.0, 7.0] set strings to ["4", "5", "6", "7"] scummvmAssertEqual(a + floats, [5.0, 7.0, 9.0]) scummvmAssertEqual(a + strings, [5.0, 7.0, 9.0]) scummvmAssertEqual(string(a + 1), "[2, 3, 4]") scummvmAssertEqual(string(1 + b), "[5, 6, 7, 8]") -- property Array tests set propArray to [501: "cast", 502: "value", 1.5: "script", a: "score", #b: "member", "color": "red"] set var to getPropAt(propArray, 1) scummvmAssertEqual(var, 501) set var to getAt(propArray, 1) scummvmAssertEqual(var, "cast") set var to getProp(propArray, 1.5) scummvmAssertEqual(var, "script") set var to getProp(propArray, #a) scummvmAssertEqual(var, "score") set var to getProp(propArray, "a") scummvmAssertEqual(var, "score") set var to getProp(propArray, #color) scummvmAssertEqual(var, "red") set var to getProp(propArray, #b) scummvmAssertEqual(var, "member") -- itemOf set string_array to "one,, three, four" set res to item 2 of string_array scummvmAssert(res="") set res to item 3 of string_array scummvmAssert(res=" three") set res to item 4 of string_array scummvmAssert(res=" four") -- itemOf check for float set res to item 3.4 of string_array scummvmAssert(res=" three") -- itemOf out of bounds checks set res to item 5 of string_array scummvmAssert(res="") set res to item -1 of string_array scummvmAssert(res=string_array) -- itemOf: test delimiter set save = the itemDelimiter set the itemDelimiter = ":" set delim_array to "one: two: three: four" set res to item 3 of delim_array scummvmAssert(res=" three") set the itemDelimiter = save -- rects set rct to rect(0, 0, 100, 100) set gA to getAt(rct, 2) scummvmAssertEqual(gA, 0) set gA to getAt(rct, 3) scummvmAssertEqual(gA, 100) setAt rct, 2, 20 scummvmAssertEqual(getAt(rct, 2), 20) -- array conversions set a to point(11, 12) set b to rect(21, 22, 23, 24) set c to [31] set d to [41, 42] set e to [51, 52, 53] set f to [61, 62, 63, 64] set g to [71, 72, 73, 74, 75] set h to 5 scummvmAssertEqual(string(a + a), "point(22, 24)") scummvmAssertEqual(string(a + b), "[32, 34]") scummvmAssertEqual(string(a + c), "[42]") scummvmAssertEqual(string(a + d), "point(52, 54)") scummvmAssertEqual(string(a + e), "[62, 64]") scummvmAssertEqual(string(a + f), "[72, 74]") scummvmAssertEqual(string(a + g), "[82, 84]") scummvmAssertEqual(string(a + h), "point(16, 17)") scummvmAssertEqual(string(b + a), "[32, 34]") scummvmAssertEqual(string(b + b), "rect(42, 44, 46, 48)") scummvmAssertEqual(string(b + c), "[52]") scummvmAssertEqual(string(b + d), "[62, 64]") scummvmAssertEqual(string(b + e), "[72, 74, 76]") scummvmAssertEqual(string(b + f), "rect(82, 84, 86, 88)") scummvmAssertEqual(string(b + g), "[92, 94, 96, 98]") scummvmAssertEqual(string(b + h), "rect(26, 27, 28, 29)") scummvmAssertEqual(string(c + a), "[42]") scummvmAssertEqual(string(c + b), "[52]") scummvmAssertEqual(string(c + c), "[62]") scummvmAssertEqual(string(c + d), "[72]") scummvmAssertEqual(string(c + e), "[82]") scummvmAssertEqual(string(c + f), "[92]") scummvmAssertEqual(string(c + g), "[102]") scummvmAssertEqual(string(c + h), "[36]") scummvmAssertEqual(string(d + a), "[52, 54]") scummvmAssertEqual(string(d + b), "[62, 64]") scummvmAssertEqual(string(d + c), "[72]") scummvmAssertEqual(string(d + d), "[82, 84]") scummvmAssertEqual(string(d + e), "[92, 94]") scummvmAssertEqual(string(d + f), "[102, 104]") scummvmAssertEqual(string(d + g), "[112, 114]") scummvmAssertEqual(string(d + h), "[46, 47]") scummvmAssertEqual(string(e + a), "[62, 64]") scummvmAssertEqual(string(e + b), "[72, 74, 76]") scummvmAssertEqual(string(e + c), "[82]") scummvmAssertEqual(string(e + d), "[92, 94]") scummvmAssertEqual(string(e + e), "[102, 104, 106]") scummvmAssertEqual(string(e + f), "[112, 114, 116]") scummvmAssertEqual(string(e + g), "[122, 124, 126]") scummvmAssertEqual(string(e + h), "[56, 57, 58]") scummvmAssertEqual(string(f + a), "[72, 74]") scummvmAssertEqual(string(f + b), "[82, 84, 86, 88]") scummvmAssertEqual(string(f + c), "[92]") scummvmAssertEqual(string(f + d), "[102, 104]") scummvmAssertEqual(string(f + e), "[112, 114, 116]") scummvmAssertEqual(string(f + f), "[122, 124, 126, 128]") scummvmAssertEqual(string(f + g), "[132, 134, 136, 138]") scummvmAssertEqual(string(f + h), "[66, 67, 68, 69]") scummvmAssertEqual(string(g + a), "[82, 84]") scummvmAssertEqual(string(g + b), "[92, 94, 96, 98]") scummvmAssertEqual(string(g + c), "[102]") scummvmAssertEqual(string(g + d), "[112, 114]") scummvmAssertEqual(string(g + e), "[122, 124, 126]") scummvmAssertEqual(string(g + f), "[132, 134, 136, 138]") scummvmAssertEqual(string(g + g), "[142, 144, 146, 148, 150]") scummvmAssertEqual(string(g + h), "[76, 77, 78, 79, 80]") scummvmAssertEqual(string(h + a), "point(16, 17)") scummvmAssertEqual(string(h + b), "rect(26, 27, 28, 29)") scummvmAssertEqual(string(h + c), "[36]") scummvmAssertEqual(string(h + d), "[46, 47]") scummvmAssertEqual(string(h + e), "[56, 57, 58]") scummvmAssertEqual(string(h + f), "[66, 67, 68, 69]") scummvmAssertEqual(string(h + g), "[76, 77, 78, 79, 80]") scummvmAssertEqual(string(h + h), "10") -- proplist with missing keys set proplist_without_keys = ["key": "value", "keyless expr 1", "keyless expr 2"] set proplist_with_keys = ["key": "value", 2: "keyless expr 1", 3: "keyless expr 2"] scummvmAssert(proplist_without_keys = proplist_with_keys) -- list with symbol or string as key set templst to [#mood: 1] set tempmood to the mood of templst scummvmAssert(tempmood = 1) put templst -- assign and check set the mood of templst to 2 set tempmood to the mood of templst scummvmAssert(tempmood = 2) put templst -- add set list1 = [1, 4, 2] add list1, 3 scummVMAssert(getPos(list1, 3) = 4) set list1 = [1, 4, 2] sort list1 add list1, 3 scummVMAssert(getPos(list1, 3) = 3) -- addAt -- addProp -- append -- count -- deleteAt (uses getAt as basis) set testList to [1, 2, 3, 4, 5] deleteAt testList, 3 scummvmAssertEqual(testList, [1, 2, 4, 5]) set testList to [#a: 1, #b: 2, #c: 3, #d: 4, #e: 5] deleteAt testList, 3 scummvmAssertEqual(testList, [#a: 1, #b: 2, #d: 4, #e: 5]) -- deleteOne (uses getOne as basis) set testList to [5, 4, 3, 1, 4] deleteOne testList, 4 scummvmAssertEqual(testList, [5, 3, 1, 4]) set testlist to [5, "4.0", 3, 1, 4] deleteOne testList, 4 scummvmAssertEqual(testList, [5, 3, 1, 4]) set testlist to [5, 4.0, 3, 1, 4] deleteOne testList, 4 scummvmAssertEqual(testList, [5, 3, 1, 4]) set testlist to [5, "urgh", 3, 1, "urgh"] deleteOne testList, "urgh" scummvmAssertEqual(testList, [5, 3, 1, "urgh"]) set testlist to [5, "URGH", 3, 1, "urgh"] deleteOne testList, "urgh" scummvmAssertEqual(testList, [5, "URGH", 3, 1]) -- deleteProp -- findPos set testList to [#a: 1, #b: 2, #bb: 3, #d: 4, #e: 5] scummvmAssertEqual(findPos(testList, #b), 2) scummvmAssertEqual(findPos(testList, #f), VOID) set testList to [] scummvmAssertEqual(findPos(testList, #3), 0) set testList to [1, 3, 0] scummvmAssertEqual(findPos(testList, 3), 3) scummvmAssertEqual(findPos(testList, 2), 2) scummvmAssertEqual(findPos(testList, 4), 0) scummvmAssertEqual(findPos(testList, -1), 0) scummvmAssertEqual(findPos(testList, 1), 1) sort testList scummvmAssertEqual(findPos(testList, 1), 2) scummvmAssertEqual(findPos(testList, 0), 1) scummvmAssertEqual(findPos(testList, 2), 0) scummvmAssertEqual(findPos(testList, 4), 0) -- findPosNear set testList to [#b: 2, #a: 1, #bb: 3, #d: 4, #e: 5] scummvmAssertEqual(findPosNear(testList, #b), 1) -- if the property list isn't sorted and the value isn't there, return the size of the list + 1 scummvmAssertEqual(findPosNear(testList, #missing), 6) scummvmAssertEqual(findPosNear(testList, #bbb), 6) sort testList scummvmAssertEqual(findPosNear(testList, #bbb), 4) set testList to [1: 2, 4: 8, 16: 32] scummvmAssertEqual(findPosNear(testList, 4), 2) scummvmAssertEqual(findPosNear(testList, 10), 4) sort testList scummvmAssertEqual(findPosNear(testList, 10), 3) -- the manual claims that findPosNear throws an error if you give it a regular list. the manual is wrong. set testList to [62, 5, 33] scummvmAssertEqual(findPosNear(testList, 5), 2) -- if the property list isn't sorted and the value isn't there, return the value scummvmAssertEqual(findPosNear(testList, 44), 44) sort testList scummvmAssertEqual(findPosNear(testList, 5), 1) scummvmAssertEqual(findPosNear(testList, 44), 3) -- getaProp set testList to [#a, #b, #c, #d, #e] scummvmAssertEqual(getaProp(testList, 4), #d) scummvmAssertError getaProp(testList, 7) set testList to [#a: 5, #b: 4, #c: 3, #d: 2, #e: 1] scummvmAssertEqual(getaProp(testList, #d), 2) scummvmAssert(voidp(getaProp(testList, #g))) -- getAt set testList to [5, 4, 3, 2, 1] scummvmAssertEqual(getAt(testList, 2), 4) scummvmAssertError getAt(testList, 7) set testList to [#a: 5, #b: 4, #c: 3, #d: 2, #e: 1] scummvmAssertEqual(getAt(testList, 2), 4) scummvmAssertError getAt(testList, 7) -- getLast set testList to [#a, #b, #c] scummvmAssertEqual(getLast(testList), #c) scummvmAssert(voidp(getLast([]))) set testList to [#a: 3, #b: 2, #c: 1] scummvmAssertEqual(getLast(testList), 1) scummvmAssert(voidp(getLast([:]))) -- getOne set testList to [#a, #b, #c, #d, #d, #e] scummvmAssertEqual(getOne(testList, #d), 4) scummvmAssertEqual(getOne(testList, #g), 0) set testList to [5, 4, 3, 1, 4] scummvmAssertEqual(getOne(testList, 4), 2) set testlist to [5, "4.0", 3, 1, 4] scummvmAssertEqual(getOne(testList, 4), 2) set testlist to [5, 4.0, 3, 1, 4] scummvmAssertEqual(getOne(testList, 4), 2) set testlist to [5, "urgh", 3, 1, "urgh"] scummvmAssertEqual(getOne(testList, "urgh"), 2) set testlist to [5, "URGH", 3, 1, "urgh"] scummvmAssertEqual(getOne(testList, "urgh"), 5) -- for finding ARRAY/PARRAY, check the pointer, not the contents set testList to [#a, #b, [1, 2, 3]] scummvmAssertEqual(getOne(testList, [1, 2, 3]), 0) set subItem to [1, 2, 3] set testList to [#a, #b, subItem] scummvmAssertEqual(getOne(testList, subItem), 3) -- getProp set testList to [#a, #b, #c, #d, #e] scummvmAssertEqual(getProp(testList, 3), #c) -- getPropAt -- ilk -- list -- listP -- max -- min -- setaProp -- setAt set lst to [] setAt lst,1,5 scummvmAssertEqual(lst, [5]) set lst to [] setAt lst,3,5 scummvmAssertEqual(lst, [0,0,5]) setAt lst,2,5 scummvmAssertEqual(lst, [0,5,5]) -- setProp -- sort