@@ -77,225 +77,4 @@ private function __keysAreEqual pLeftKeys, pRightKeys
7777 return pLeftKeys is pRightKeys
7878end __keysAreEqual
7979
80- // pArrayType: one of kStringArray, kNumericArray, kSequenceArray
81- private command __testIntersect pArrayType
82- local tStringArray , tNumberArray , tCommonArray
83- local tValues , tKeys , tTemplateArray
84-
85- if pArrayType is kStringArray then
86- put testArrayData("stringKeys" ) into tKeys
87- put __stringTemplate() into tTemplateArray
88- else if pArrayType is kNumericArray then
89- put kNumericKeys into tKeys
90- put __numericTemplate() into tTemplateArray
91- else
92- put kSequenceKeys into tKeys
93- put __sequenceTemplate() into tTemplateArray
94- end if
95-
96- put testArrayData("stringValues" ) into tValues
97-
98- // Only the first item will match the template
99- put item 1 of tValues into tCommonArray [item 1 of tKeys ]
100- put item 2 of tValues into tCommonArray [item 2 of tKeys ]
101-
102- // Now add a key that will not intersect with the template array
103- // and a matching key - even if the value is not the same as it common array)
104- // ( we have non-matching keys in both String and Template array)
105- put tCommonArray into tStringArray
106- put item 3 of tValues into tStringArray [item 2 of tKeys ]
107- put item 3 of tValues into tStringArray [item 3 of tKeys & "other" ]
108-
109- intersect tStringArray with tTemplateArray
110-
111- TestAssert merge ("Intersect [[pArrayType]] arrays" ), __keysAreEqual(the keys of tStringArray , the keys of tCommonArray )
112- end __testIntersect
113-
114- on TestIntersectString
115- __testIntersect kStringArray
116- end TestIntersectString
117-
118- on TestIntersectSequence
119- __testIntersect kSequenceArray
120- end TestIntersectSequence
121-
122- on TestIntersectNumeric
123- __testIntersect kNumericArray
124- end TestIntersectNumeric
125-
126- // pArrayType: one of kStringArray, kNumericArray, kSequenceArray
127- private command __testIntersectRecursive pArrayType
128- local tLeftArray , tRightArray , tCommonArray
129- local tKeys
130-
131- if pArrayType is kStringArray then
132- put testArrayData("stringKeys" ) into tKeys
133- else if pArrayType is kNumericArray then
134- put kNumericKeys into tKeys
135- else
136- put kSequenceKeys into tKeys
137- end if
138-
139- // Set the common array
140- put __numericTemplate() into tCommonArray [item 1 of tKeys ]
141- put __sequenceTemplate() into tCommonArray [item 2 of tKeys ]
142- put __stringTemplate() into tCommonArray [item 3 of tKeys ]
143-
144- put tCommonArray into tLeftArray
145- put tCommonArray into tRightArray
146-
147- // Create sub-array that misses one key
148- local tCrippledStringArray
149- put __stringTemplate() into tCrippledStringArray
150- delete local tCrippledStringArray [line 1 of the keys of tCrippledStringArray ]
151-
152- put tCrippledStringArray into tRightArray [item 4 of tKeys ]
153- put tCrippledStringArray into tCommonArray [item 4 of tKeys ]
154- put __stringTemplate() into tLeftArray [item 4 of tKeys ]
155-
156- intersect tLeftArray with tRightArray recursively
157-
158- local tSuccess
159- put __keysAreEqual(the keys of tLeftArray , the keys of tCommonArray ) into tSuccess
160-
161- if tSuccess then
162- repeat for each key tKey in tLeftArray
163- if not __keysAreEqual(the keys of tLeftArray [tKey ], the keys of tCommonArray [tKey ]) then
164- put false into tSuccess
165- exit repeat
166- end if
167- end repeat
168- end if
169-
170- testAssert merge ("Recursice intersect for [[pArrayType]] array" ), tSuccess
171- end __testIntersectRecursive
172-
173- // Test with string keys
174- on TestIntersectStringRecursive
175- __testIntersectRecursive kStringArray
176- end TestIntersectStringRecursive
177-
178-
179- // Test with numeric keys
180- on TestIntersectSequenceRecursive
181- __testIntersectRecursive kSequenceArray
182- end TestIntersectSequenceRecursive
183-
184- on TestIntersectNumberRecursive
185- __testIntersectRecursive kNumericArray
186- end TestIntersectNumberRecursive
187-
188-
189- // pArrayType: one of kStringArray, kNumericArray, kSequenceArray
190- private command __testUnion pArrayType
191- local tLeftArray
192- local tValues , tKeys , tTemplateArray , tLeftOnlyKey
193-
194- if pArrayType is kStringArray then
195- put testArrayData("stringKeys" ) into tKeys
196- put __stringTemplate() into tTemplateArray
197- put "other key" & the milliseconds into tLeftOnlyKey
198- else if pArrayType is kNumericArray then
199- put kNumericKeys into tKeys
200- put __numericTemplate() into tTemplateArray
201- put the milliseconds into tLeftOnlyKey
202- else
203- put kSequenceKeys into tKeys
204- put __sequenceTemplate() into tTemplateArray
205- put 6 into tLeftOnlyKey
206- end if
207-
208- put testArrayData("stringValues" ) into tValues
209-
210- // We have a different value in the first key, and a key specific for the union'd array
211- put the milliseconds into tLeftOnlyKey
212- put "value" into tLeftArray [tLeftOnlyKey ]
213- put the seconds into tLeftArray [item 1 of tKeys ]
214-
215- local tUnionKeys
216- put the keys of tTemplateArray & LF & tLeftOnlyKey into tUnionKeys
217-
218- union tLeftArray with tTemplateArray
219-
220- TestAssert merge ("union [[pArrayType]] arrays" ), __keysAreEqual(the keys of tLeftArray , tUnionKeys )
221- TestAssert "Left array value has not been overwritten" , tLeftArray [item 1 of tKeys ] is not tTemplateArray [item 1 of tKeys ]
222- end __testUnion
223-
224- on TestUnionString
225- __testUnion kStringArray
226- end TestUnionString
227-
228- on TestUnionSequence
229- __testUnion kSequenceArray
230- end TestUnionSequence
231-
232- on TestUnionNumeric
233- __testUnion kNumericArray
234- end TestUnionNumeric
235-
236-
237- // pArrayType: one of kStringArray, kNumericArray, kSequenceArray
238- private command __testUnionRecursive pArrayType
239- local tLeftArray , tRightArray , tCommonArray
240- local tKeys
241-
242- if pArrayType is kStringArray then
243- put testArrayData("stringKeys" ) into tKeys
244- else if pArrayType is kNumericArray then
245- put kNumericKeys into tKeys
246- else
247- put kSequenceKeys into tKeys
248- end if
249-
250- // Set the common array
251- put __numericTemplate() into tLeftArray [item 1 of tKeys ]
252- put __numericTemplate() into tRightArray [item 1 of tKeys ]
253- put __numericTemplate() into tCommonArray [item 1 of tKeys ]
254-
255- put __sequenceTemplate() into tLeftArray [item 2 of tKeys ]
256- put __sequenceTemplate() into tCommonArray [item 2 of tKeys ]
257-
258- put __stringTemplate() into tRightArray [item 3 of tKeys ]
259- put __stringTemplate() into tCommonArray [item 3 of tKeys ]
260-
261- // Create sub-array that misses one key
262- local tCrippledStringArray
263- put __stringTemplate() into tCrippledStringArray
264- delete local tCrippledStringArray [line 1 of the keys of tCrippledStringArray ]
265-
266- // The common array will have the string template, not the crippled version
267- put tCrippledStringArray into tRightArray [item 4 of tKeys ]
268- put __stringTemplate() into tCommonArray [item 4 of tKeys ]
269- put __stringTemplate() into tLeftArray [item 4 of tKeys ]
270-
271- union tLeftArray with tRightArray recursively
272-
273- local tSuccess
274- put __keysAreEqual(the keys of tLeftArray , the keys of tCommonArray ) into tSuccess
275-
276- if tSuccess then
277- repeat for each key tKey in tLeftArray
278- if not __keysAreEqual(the keys of tLeftArray [tKey ], the keys of tCommonArray [tKey ]) then
279- put false into tSuccess
280- exit repeat
281- end if
282- end repeat
283- end if
284-
285- testAssert merge ("Recursice union for [[pArrayType]] array" ), tSuccess
286- end __testUnionRecursive
287-
288- // Test with string keys
289- on TestUnionStringRecursive
290- __testUnionRecursive kStringArray
291- end TestUnionStringRecursive
292-
293-
294- // Test with numeric keys
295- on TestUnionSequenceRecursive
296- __testIntersectRecursive kSequenceArray
297- end TestUnionSequenceRecursive
298-
299- on TestUnionNumberRecursive
300- __testUnionRecursive kNumericArray
301- end TestUnionNumberRecursive
80+ // Keeping the file, for non-yet-implemented tests for arrays
0 commit comments