Skip to content

Commit fd73b01

Browse files
[[ ArrayTests ]] Add test for combine command
1 parent 29c4a0b commit fd73b01

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
script "CoreArrayCombine"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
20+
on TestCombineStrings
21+
local tArray, tKeyList, tKeys, tValues
22+
local tUncombinedData
23+
24+
put testArrayData("stringKeys") into tKeys
25+
put testArrayData("stringValues") into tValues
26+
27+
set the itemDelimiter to tab
28+
repeat with x = 1 to the number of items in tKeys
29+
put item x of tValues into tArray[item x of tKeys]
30+
put item x of tKeys & tab & item x of tValues & return after tUncombinedData
31+
end repeat
32+
delete the last character of tUncombinedData
33+
34+
combine tArray with return and tab
35+
36+
sort lines of tArray by item 1 of each
37+
sort lines of tUncombinedData by item 1 of each
38+
39+
TestAssert "Combine strings", tUncombinedData is tArray
40+
end TestCombineStrings
41+
42+
43+
on TestCombineNumbers
44+
local tArray, tKeyList
45+
local tUncombinedData
46+
set the itemDel to tab
47+
repeat with x = 1 to 5
48+
put x into tArray[x]
49+
put x & tab & x & return after tUncombinedData
50+
end repeat
51+
delete the last character of tUncombinedData
52+
combine tArray with return and tab
53+
54+
TestAssert "Combine numbers", tUncombinedData is tArray
55+
end TestCombineNumbers
56+
57+
58+
on TestCombineMixed
59+
local tArray, tKeyList, tKeys, tValues
60+
local tUncombinedData
61+
62+
put testArrayData("stringKeys") into tKeys
63+
put testArrayData("stringValues") into tValues
64+
65+
set the itemDelimiter to tab
66+
repeat with x = 1 to the number of items in tKeys
67+
put item x of tValues into tArray[item x of tKeys]
68+
put item x of tKeys & tab & item x of tValues & return after tUncombinedData
69+
end repeat
70+
71+
repeat with x = 1 to 5
72+
put x into tArray[x]
73+
put x & tab & x & return after tUncombinedData
74+
end repeat
75+
76+
delete the last character of tUncombinedData
77+
combine tArray with return and tab
78+
79+
sort lines of tArray by item 1 of each
80+
sort lines of tUncombinedData by item 1 of each
81+
82+
TestAssert "Combine numbers and strings", tUncombinedData is tArray
83+
end TestCombineMixed
84+
85+
86+
on test_arrayCombineByRow
87+
local tArray, tKeyList, tValues
88+
local tUncombinedData
89+
90+
put testArrayData("stringValues") into tValues
91+
92+
set the itemDelimiter to tab
93+
repeat with x = 1 to the number of items in tValues
94+
put item x of tValues into tArray[x]
95+
put item x of tValues & the rowDelimiter after tUncombinedData
96+
end repeat
97+
delete the last character of tUncombinedData
98+
99+
combine tArray by row
100+
101+
sort lines of tArray by item 1 of each
102+
sort lines of tUncombinedData by item 1 of each
103+
104+
TestAssert "Combine by row", tUncombinedData is tArray
105+
end test_arrayCombineByRow
106+
107+
108+
on test_arrayCombineByRow
109+
local tArray, tKeyList, tValues
110+
local tUncombinedData
111+
112+
put testArrayData("stringValues") into tValues
113+
114+
set the itemDelimiter to tab
115+
repeat with x = 1 to the number of items in tValues
116+
put item x of tValues into tArray[x]
117+
put item x of tValues & the columnDelimiter after tUncombinedData
118+
end repeat
119+
delete the last character of tUncombinedData
120+
121+
combine tArray by column
122+
123+
sort lines of tArray by item 1 of each
124+
sort lines of tUncombinedData by item 1 of each
125+
126+
TestAssert "Combine by column", tUncombinedData is tArray
127+
end test_arrayCombineByRow

0 commit comments

Comments
 (0)