This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathlist.lcb
More file actions
746 lines (615 loc) · 26.5 KB
/
list.lcb
File metadata and controls
746 lines (615 loc) · 26.5 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
/*
Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
module com.livecode.list.tests
use com.livecode.list
use com.livecode.__INTERNAL._testlib
public handler TestEmpty()
variable tList
put the empty list into tList
test "empty (empty)" when tList is empty
test "empty (empty list)" when tList is the empty list
test "empty (empty literal)" when tList is []
test "empty (no elements)" when the number of elements in tList is 0
end handler
public handler TestLiteral()
variable tList
put [[], "x", 1, true] into tList
test "literal" when the number of elements in tList is 4
end handler
public handler TestIs()
test "is" when [[], "x", 1, true] is [[], "x", 1, true]
test "is not" when [[], "x", 1, true] is not [[1], "x", 1, true]
end handler
handler TestHead_Empty()
return the head of []
end handler
handler TestHead_FirstEmpty()
return the first element of []
end handler
public handler TestHead()
variable tList
put ["x", 1, true] into tList
test "head" when the head of tList is "x"
test "first" when the first element of tList is "x"
MCUnitTestHandlerThrows(TestHead_Empty, "head (empty)")
MCUnitTestHandlerThrows(TestHead_FirstEmpty, "first (empty)")
end handler
handler TestTail_Empty()
return the tail of []
end handler
handler TestTail_LastEmpty()
return the last element of []
end handler
public handler TestTail()
variable tList
put ["x", 1, true] into tList
test "tail" when the tail of tList
test "last" when the last element of tList
MCUnitTestHandlerThrows(TestTail_Empty, "tail (empty)")
MCUnitTestHandlerThrows(TestTail_LastEmpty, "last (empty)")
end handler
public handler TestPush()
variable tList
put ["x", 1, true] into tList
push "y" onto tList
test "push" when the tail of tList is "y"
push "z" onto front of tList
test "push front" when the head of tList is "z"
push "w" onto back of tList
test "push back" when the tail of tList is "w"
test "push (result)" when tList is ["z", "x", 1, true, "y", "w"]
end handler
handler TestPop_Empty()
variable tList
put [] into tList
pop tList
end handler
handler TestPop_FrontEmpty()
variable tList
put [] into tList
pop front of tList
end handler
handler TestPop_BackEmpty()
variable tList
put [] into tList
pop back of tList
end handler
public handler TestPop()
variable tList
variable tPopped
put ["x", 1, 2, true] into tList
pop tList into tPopped
test "pop" when tPopped
pop front of tList into tPopped
test "pop front" when tPopped is "x"
pop back of tList into tPopped
test "pop back" when tPopped is 2
test "pop (result)" when tList is [1]
pop tList
test "pop (no output)" when tList is empty
MCUnitTestHandlerThrows(TestPop_Empty, "pop (empty)")
MCUnitTestHandlerThrows(TestPop_FrontEmpty, "pop front (empty)")
MCUnitTestHandlerThrows(TestPop_BackEmpty, "pop back (empty)")
end handler
public handler TestCount()
test "count" when the number of elements in [1, 2, ["a", "b"]] is 3
end handler
public handler TestContainsELement()
variable tList
put ["x", 1, true] into tList
test "element is in" when "x" is in tList
test "element is not in" when not [] is in tList
end handler
public handler TestContainsList()
variable tList
put ["x", 1, true, []] into tList
test "contains" when tList contains ["x", 1]
test "contains (missing)" when not tList contains [1, "x"]
test "contains (empty)" when not [] contains []
-- Bug 14596
test "contains (missing, overlap)" when not ["x", 1, true, ""] contains ["", true]
end handler
public handler TestBeginsWith()
variable tList
put ["x", 1, true, []] into tList
test "begins with" when tList begins with ["x", 1]
test "begins with (missing)" when not tList begins with [1, true]
test "begins with (empty)" when tList begins with []
end handler
public handler TestEndsWith()
variable tList
put ["x", 1, true, []] into tList
test "ends with" when tList ends with [true, []]
test "ends with (missing)" when not tList ends with [1, true]
test "ends with (empty)" when tList ends with []
end handler
handler TestSubscript_Zero()
return [1][0]
end handler
handler TestSubscript_Empty()
return [][1]
end handler
handler TestSubscript_After()
return[1][2]
end handler
handler TestSubscript_Before()
return[1][-2]
end handler
public handler TestSubscript()
variable tList
put ["x", 1, true, []] into tList
test "subscript (syntax, +ve)" when element 2 of tList is 1
test "subscript (syntax, -ve)" when element -2 of tList is true
test "subscript (operator, +ve)" when tList[4] is []
test "subscript (operator, -ve)" when tList[-4] is "x"
test "subscript (operator literal)" when [4][1] is 4
MCUnitTestHandlerThrows(TestSubscript_Zero, "subscript (operator, zero)")
MCUnitTestHandlerThrows(TestSubscript_Empty, "subscript (operator, empty)")
MCUnitTestHandlerThrows(TestSubscript_After, "subscript (operator, after)")
MCUnitTestHandlerThrows(TestSubscript_Before, "subscript (operator, before)")
end handler
handler TestRange_Zero()
return element 0 to 0 of [1]
end handler
handler TestRange_Before()
variable tList
put element -4 to -3 of ["x", 1, true] into tList
end handler
handler TestRange_After()
return element 3 to 4 of ["x", 1, true]
end handler
public handler TestRange()
variable tList
put ["x", 1, true, []] into tList
test "range (+ve)" when element 2 to 3 of tList is [1, true]
test "range (+ve, same)" when element 2 to 2 of tList is [1]
test "range (-ve)" when element -3 to -2 of tList is [1, true]
test "range (-ve, same)" when element -2 to -2 of tList is [true]
MCUnitTestHandlerThrows(TestRange_Zero, "range (zero)")
MCUnitTestHandlerThrows(TestRange_After, "range (after)")
MCUnitTestHandlerThrows(TestRange_Before, "range (before)")
end handler
handler TestDeleteSingle_Zero()
variable tList
put ["x", 1, true, []] into tList
delete element 0 of tList
end handler
handler TestDeleteSingle_Before()
variable tList
put ["x", 1, true, []] into tList
delete element -5 of tList
end handler
handler TestDeleteSingle_After()
variable tList
put ["x", 1, true, []] into tList
delete element 5 of tList
end handler
public handler TestDeleteSingle()
variable tList
variable tTemplate
put ["x", 1, true, []] into tTemplate
put tTemplate into tList
delete element 3 of tList
test "delete single (+ve)" when tList is ["x", 1, []]
put tTemplate into tList
delete element -3 of tList
test "delete single (-ve)" when tList is ["x", true, []]
put tTemplate into tList
delete the first element of tList
test "delete first" when tList is [1, true, []]
put tTemplate into tList
delete the last element of tList
test "delete last" when tList is ["x", 1, true]
MCUnitTestHandlerThrows(TestDeleteSingle_Zero, "delete single (zero)")
MCUnitTestHandlerThrows(TestDeleteSingle_Before, "delete single (before)")
MCUnitTestHandlerThrows(TestDeleteSingle_After, "delete single (after)")
end handler
handler TestDeleteRange_Zero()
variable tList
put ["x", 1, true, []] into tList
delete element 0 to 0 of tList
end handler
handler TestDeleteRange_Before()
variable tList
put ["x", 1, true, []] into tList
delete element -5 to -4 of tList
end handler
handler TestDeleteRange_After()
variable tList
put ["x", 1, true, []] into tList
delete element 4 to 5 of tList
end handler
public handler TestDeleteRange()
variable tList
variable tTemplate
put ["x", 1, true, []] into tTemplate
put tTemplate into tList
delete element 2 to 3 of tList
test "delete range (+ve)" when tList is ["x", []]
put tTemplate into tList
delete element -3 to -2 of tList
test "delete range (-ve)" when tList is ["x", []]
MCUnitTestHandlerThrows(TestDeleteRange_Zero, "delete range (zero)")
MCUnitTestHandlerThrows(TestDeleteRange_Before, "delete range (before)")
MCUnitTestHandlerThrows(TestDeleteRange_After, "delete range (after)")
end handler
public handler TestSplice()
variable tList
variable tTemplate
put [1, 1, 1, 1] into tTemplate
put tTemplate into tList
splice [2, 2] into element 2 to 3 of tList
test "splice (+ve)" when tList is [1, 2, 2, 1]
put tTemplate into tList
splice [2, 2] into element -3 to -2 of tList
test "splice (-ve)" when tList is [1, 2, 2, 1]
put tTemplate into tList
splice [2, 2] into element 2 to 2 of tList
test "splice (+ve, same)" when tList is [1, 2, 2, 1, 1]
put tTemplate into tList
splice [2, 2] into element 2 of tList
test "splice (+ve, single)" when tList is [1, 2, 2, 1, 1]
put tTemplate into tList
splice the empty list into element 1 to 4 of tList
test "splice (+ve, empty)" when tList is empty
end handler
handler TestSpliceBefore_Zero()
variable tList
put [1] into tList
splice tList before element 0 of tList
end handler
handler TestSpliceAfter_Limit()
variable tList
put [1] into tList
splice tList after element 2 of tList
end handler
public handler TestSpliceBefore()
variable tList
variable tTemplate
put [1, 1, 1, 1] into tTemplate
put tTemplate into tList
splice [2, 2] before element 2 of tList
test "splice before" when tList is [1, 2, 2, 1, 1, 1]
put tTemplate into tList
splice the empty list before element 2 of tList
test "splice before (empty)" when tList is tTemplate
MCUnitTestHandlerThrows(TestSpliceBefore_Zero, "splice before (zero)")
end handler
public handler TestSpliceAfter()
variable tList
variable tTemplate
put [1, 1, 1, 1] into tTemplate
put tTemplate into tList
splice [2, 2] after element 2 of tList
test "splice after" when tList is [1, 1, 2, 2, 1, 1]
put tTemplate into tList
splice the empty list after element 2 of tList
test "splice after (empty)" when tList is tTemplate
MCUnitTestHandlerThrows(TestSpliceAfter_Limit, "splice after (limit)")
end handler
public handler TestRepeatElement()
variable tIter
variable tCount
put 0 into tCount
repeat for each element tIter in [1, 1, 1, 1]
test "repeat element (iter)" when tIter is 1
add 1 to tCount
end repeat
test "repeat element (count)" when tCount is 4
end handler
----------------------------------------------------------------
-- Finding indices
----------------------------------------------------------------
public handler TestIndex()
variable tList
put ["x", 1, true, [], []] into tList
test "index" when the index of 1 in tList is 2
test "index (list)" when the index of [] in tList is 4
test "index (missing)" when the index of false in tList is 0
test "first index" when the first index of [] in tList is 4
test "last index" when the last index of [] in tList is 5
test "index (empty)" when the index of 1 in [] is 0
end handler
----------------------------------------------------------------
handler TestIndexAfter_InvalidPositive()
return the index of true after 2 in [true]
end handler
handler TestIndexAfter_InvalidNegative()
return the index of true after -3 in [true]
end handler
handler TestFirstIndexAfter_InvalidPositive()
return the first index of true after 2 in [true]
end handler
handler TestFirstIndexAfter_InvalidNegative()
return the first index of true after -3 in [true]
end handler
handler TestLastIndexAfter_InvalidPositive()
return the last index of true after 2 in [true]
end handler
handler TestLastIndexAfter_InvalidNegative()
return the last index of true after -3 in [true]
end handler
public handler TestIndexAfter()
variable tList
put [true, false, true, true, false] into tList
test "index after (+ve)" when the index of true after 1 in tList is 3
test "index after (-ve)" when the index of true after -5 in tList is 3
test "index after (-ve, limit)" when the index of true after -6 in tList is 1
test "index after (+ve, missing)" when the index of true after 4 in tList is 0
test "index after (-ve, missing)" when the index of true after -2 in tList is 0
MCUnitTestHandlerThrows(TestIndexAfter_InvalidPositive, "index after (+ve, invalid)")
MCUnitTestHandlerThrows(TestIndexAfter_InvalidNegative, "index after (-ve, invalid)")
end handler
public handler TestFirstIndexAfter()
variable tList
put [true, false, true, true, false] into tList
test "first index after (+ve)" when the first index of true after 1 in tList is 3
test "first index after (-ve)" when the first index of true after -5 in tList is 3
test "first index after (-ve, limit)" when the first index of true after -6 in tList is 1
test "first index after (+ve, missing)" when the first index of true after 4 in tList is 0
test "first index after (-ve, missing)" when the first index of true after -2 in tList is 0
MCUnitTestHandlerThrows(TestFirstIndexAfter_InvalidPositive, "first index after (+ve, invalid)")
MCUnitTestHandlerThrows(TestFirstIndexAfter_InvalidNegative, "first index after (-ve, invalid)")
end handler
public handler TestLastIndexAfter()
variable tList
put [true, false, true, true, false] into tList
test "last index after (+ve)" when the last index of true after 1 in tList is 4
test "last index after (-ve)" when the last index of true after -5 in tList is 4
test "last index after (-ve, limit)" when the last index of true after -6 in tList is 4
test "last index after (+ve, missing)" when the last index of true after 4 in tList is 0
test "last index after (-ve, missing)" when the last index of true after -2 in tList is 0
MCUnitTestHandlerThrows(TestLastIndexAfter_InvalidPositive, "last index after (+ve, invalid)")
MCUnitTestHandlerThrows(TestLastIndexAfter_InvalidNegative, "last index after (-ve, invalid)")
end handler
public handler TestIndexAfterZero()
-- "index of _ after 0 in _" should be equivalent to "index of _ in _"
variable tList
put [true, false, true, true, false] into tList
variable tNoAfter
put the index of true in tList into tNoAfter
test "index after (+ve, 0)" when the index of true after 0 in tList is tNoAfter
put the first index of true in tList into tNoAfter
test "first index after (+ve, 0)" when the first index of true after 0 in tList is tNoAfter
put the last index of true in tList into tNoAfter
test "last index after (+ve, 0)" when the last index of true after 0 in tList is tNoAfter
end handler
----------------------------------------------------------------
handler TestIndexBefore_InvalidPositive()
return the index of true before 3 in [true]
end handler
handler TestIndexBefore_InvalidNegative()
return the index of true before -2 in [true]
end handler
handler TestFirstIndexBefore_InvalidPositive()
return the first index of true before 3 in [true]
end handler
handler TestFirstIndexBefore_InvalidNegative()
return the first index of true before -2 in [true]
end handler
handler TestLastIndexBefore_InvalidPositive()
return the last index of true before 3 in [true]
end handler
handler TestLastIndexBefore_InvalidNegative()
return the last index of true before -2 in [true]
end handler
public handler TestIndexBefore()
variable tList
put [false, true, true, false, true] into tList
test "index before (+ve)" when the index of true before 4 in tList is 3
test "index before (-ve)" when the index of true before -2 in tList is 3
test "index before (+ve, limit)" when the index of true before 6 in tList is 5
test "index before (+ve, missing)" when the index of true before 2 in tList is 0
test "index before (-ve, missing)" when the index of true before -4 in tList is 0
MCUnitTestHandlerThrows(TestIndexBefore_InvalidPositive, "index before (+ve, invalid)")
MCUnitTestHandlerThrows(TestIndexBefore_InvalidNegative, "index before (-ve, invalid)")
end handler
public handler TestFirstIndexBefore()
variable tList
put [false, true, true, false, true] into tList
test "first index before (+ve)" when the first index of true before 4 in tList is 2
test "first index before (-ve)" when the first index of true before -2 in tList is 2
test "first index before (+ve, limit)" when the first index of true before 6 in tList is 2
test "first index before (+ve, missing)" when the first index of true before 2 in tList is 0
test "first index before (-ve, missing)" when the first index of true before -4 in tList is 0
MCUnitTestHandlerThrows(TestFirstIndexBefore_InvalidPositive, "first index before (+ve, invalid)")
MCUnitTestHandlerThrows(TestFirstIndexBefore_InvalidNegative, "first index before (-ve, invalid)")
end handler
public handler TestLastIndexBefore()
variable tList
put [false, true, true, false, true] into tList
test "last index before (+ve)" when the last index of true before 4 in tList is 3
test "last index before (-ve)" when the last index of true before -2 in tList is 3
test "last index before (+ve, limit)" when the last index of true before 6 in tList is 5
test "last index before (+ve, missing)" when the last index of true before 2 in tList is 0
test "last index before (-ve, missing)" when the last index of true before -4 in tList is 0
MCUnitTestHandlerThrows(TestLastIndexBefore_InvalidPositive, "last index before (+ve, invalid)")
MCUnitTestHandlerThrows(TestLastIndexBefore_InvalidNegative, "last index before (-ve, invalid)")
end handler
public handler TestIndexBeforeZero()
-- "index of _ before 0 in _" should be equivalent to
-- "last index of _ in _"
variable tList
put [false, true, true, false, true] into tList
variable tNoBefore
put the last index of true in tList into tNoBefore
test "index before (+ve, 0)" when the index of true before 0 in tList is tNoBefore
put the first index of true in tList into tNoBefore
test "first index before (+ve, 0)" when the first index of true before 0 in tList is tNoBefore
put the last index of true in tList into tNoBefore
test "last index before (+ve, 0)" when the last index of true before 0 in tList is tNoBefore
end handler
----------------------------------------------------------------
-- Finding subsequence offsets
----------------------------------------------------------------
public handler TestOffset()
variable tList
put ["x", 1, true, [], []] into tList
test "offset" when the offset of [1, true] in tList is 2
test "offset (missing)" when the offset of [true, 1] in tList is 0
test "offset (missing, overlap start)" when the offset of [false, "x"] in tList is 0
test "offset (missing, overlap end)" when the offset of [[], [], false] in tList is 0
test "first offset" when the first offset of [[]] in tList is 4
test "last offset" when the last offset of [[]] in tList is 5
test "offset (empty)" when the offset of [] in tList is 0
end handler
----------------------------------------------------------------
handler TestOffsetAfter_InvalidPositive()
return the offset of [true] after 2 in [true]
end handler
handler TestOffsetAfter_InvalidNegative()
return the offset of [true] after -3 in [true]
end handler
handler TestFirstOffsetAfter_InvalidPositive()
return the first offset of [true] after 2 in [true]
end handler
handler TestFirstOffsetAfter_InvalidNegative()
return the first offset of [true] after -3 in [true]
end handler
handler TestLastOffsetAfter_InvalidPositive()
return the last offset of [true] after 2 in [true]
end handler
handler TestLastOffsetAfter_InvalidNegative()
return the last offset of [true] after -3 in [true]
end handler
public handler TestOffsetAfter()
variable tList
put [true, false, true, true, false] into tList
test "offset after (+ve)" when the offset of [true,false] after 1 in tList is 4
test "offset after (-ve)" when the offset of [true,false] after -5 in tList is 4
test "offset after (-ve, limit)" when the offset of [true,false] after -6 in tList is 1
test "offset after (+ve, missing)" when the offset of [false,true] after 2 in tList is 0
test "offset after (-ve, missing)" when the offset of [false,true] after -4 in tList is 0
MCUnitTestHandlerThrows(TestOffsetAfter_InvalidPositive, "offset after (+ve, invalid)")
MCUnitTestHandlerThrows(TestOffsetAfter_InvalidNegative, "offset after (-ve, invalid)")
end handler
public handler TestFirstOffsetAfter()
variable tList
put [true, false, true, true, false] into tList
test "first offset after (+ve)" when the first offset of [true,false] after 1 in tList is 4
test "first offset after (-ve)" when the first offset of [true,false] after -5 in tList is 4
test "first offset after (-ve, limit)" when the first offset of [true,false] after -6 in tList is 1
test "first offset after (+ve, missing)" when the first offset of [false,true] after 2 in tList is 0
test "first offset after (-ve, missing)" when the first offset of [false,true] after -4 in tList is 0
MCUnitTestHandlerThrows(TestFirstOffsetAfter_InvalidPositive, "first offset after (+ve, invalid)")
MCUnitTestHandlerThrows(TestFirstOffsetAfter_InvalidNegative, "first offset after (-ve, invalid)")
end handler
public handler TestLastOffsetAfter()
variable tList
put [true, false, true, true, false] into tList
test "last offset after (+ve)" when the last offset of [true] after 1 in tList is 4
test "last offset after (-ve)" when the last offset of [true] after -5 in tList is 4
test "last offset after (-ve, limit)" when the last offset of [true] after -6 in tList is 4
test "last offset after (+ve, missing)" when the last offset of [true] after 4 in tList is 0
test "last offset after (-ve, missing)" when the last offset of [true] after -2 in tList is 0
MCUnitTestHandlerThrows(TestLastOffsetAfter_InvalidPositive, "last offset after (+ve, invalid)")
MCUnitTestHandlerThrows(TestLastOffsetAfter_InvalidNegative, "last offset after (-ve, invalid)")
end handler
public handler TestOffsetAfterZero()
-- "offset of _ after 0 in _" should be equivalent to "offset of _ in _"
variable tList
put [true, false, true, true, false] into tList
variable tNoAfter
put the offset of [true,false] in tList into tNoAfter
test "offset after (+ve, 0)" when the offset of [true,false] after 0 in tList is tNoAfter
put the first offset of [true,false] in tList into tNoAfter
test "first offset after (+ve, 0)" when the first offset of [true,false] after 0 in tList is tNoAfter
put the last offset of [true,false] in tList into tNoAfter
test "last offset after (+ve, 0)" when the last offset of [true,false] after 0 in tList is tNoAfter
end handler
----------------------------------------------------------------
handler TestOffsetBefore_InvalidPositive()
return the offset of [true] before 3 in [true]
end handler
handler TestOffsetBefore_InvalidNegative()
return the offset of [true] before -2 in [true]
end handler
handler TestFirstOffsetBefore_InvalidPositive()
return the first offset of [true] before 3 in [true]
end handler
handler TestFirstOffsetBefore_InvalidNegative()
return the first offset of [true] before -2 in [true]
end handler
handler TestLastOffsetBefore_InvalidPositive()
return the last offset of [true] before 3 in [true]
end handler
handler TestLastOffsetBefore_InvalidNegative()
return the last offset of [true] before -2 in [true]
end handler
public handler TestOffsetBefore()
variable tList
put [true, false, true, true, false] into tList
test "offset before (+ve)" when the offset of [true,false] before 4 in tList is 1
test "offset before (-ve)" when the offset of [true,false] before -2 in tList is 1
test "offset before (+ve, limit)" when the offset of [true,false] before 6 in tList is 4
test "offset before (+ve, missing)" when the offset of [false,true] before 2 in tList is 0
test "offset before (-ve, missing)" when the offset of [false,true] before -4 in tList is 0
MCUnitTestHandlerThrows(TestOffsetBefore_InvalidPositive, "offset before (+ve, invalid)")
MCUnitTestHandlerThrows(TestOffsetBefore_InvalidNegative, "offset before (-ve, invalid)")
end handler
public handler TestFirstOffsetBefore()
variable tList
put [true, false, true, true, false] into tList
test "first offset before (+ve)" when the first offset of [true,false] before 5 in tList is 1
test "first offset before (-ve)" when the first offset of [true,false] before -1 in tList is 1
test "first offset before (+ve, limit)" when the first offset of [true,false] before 6 in tList is 1
test "first offset before (+ve, missing)" when the first offset of [false,true] before 2 in tList is 0
test "first offset before (-ve, missing)" when the first offset of [false,true] before -4 in tList is 0
MCUnitTestHandlerThrows(TestFirstOffsetBefore_InvalidPositive, "first offset before (+ve, invalid)")
MCUnitTestHandlerThrows(TestFirstOffsetBefore_InvalidNegative, "first offset before (-ve, invalid)")
end handler
public handler TestLastOffsetBefore()
variable tList
put [true, false, true, true, false] into tList
test "last offset before (+ve)" when the last offset of [true,false] before 4 in tList is 1
test "last offset before (-ve)" when the last offset of [true,false] before -2 in tList is 1
test "last offset before (+ve, limit)" when the last offset of [true,false] before 6 in tList is 4
test "last offset before (+ve, missing)" when the last offset of [false,true] before 2 in tList is 0
test "last offset before (-ve, missing)" when the last offset of [false,true] before -4 in tList is 0
MCUnitTestHandlerThrows(TestLastOffsetBefore_InvalidPositive, "last offset before (+ve, invalid)")
MCUnitTestHandlerThrows(TestLastOffsetBefore_InvalidNegative, "last offset before (-ve, invalid)")
end handler
public handler TestOffsetBeforeZero()
-- "offset of _ before 0 in _" should be equivalent to "last offset of _ in _"
variable tList
put [true, false, true, true, false] into tList
variable tNoBefore
put the last offset of [true,false] in tList into tNoBefore
test "offset before (+ve, 0)" when the offset of [true,false] before 0 in tList is tNoBefore
put the first offset of [true,false] in tList into tNoBefore
test "first offset before (+ve, 0)" when the first offset of [true,false] before 0 in tList is tNoBefore
put the last offset of [true,false] in tList into tNoBefore
test "last offset before (+ve, 0)" when the last offset of [true,false] before 0 in tList is tNoBefore
end handler
----------------------------------------------------------------
public handler TestConcat()
test "concat" when ["x"] & ["y"] is ["x", "y"]
end handler
----------------------------------------------------------------
public handler TestReverse()
variable tReversed
put [1, 2, 3] into tReversed
reverse tReversed
test "reverse in-place (odd)" when tReversed is [3, 2, 1]
reverse tReversed
test "rereverse in-place (odd)" when tReversed is [1, 2, 3]
put [1, 2, 3, 4] into tReversed
reverse tReversed
test "reverse in-place (even)" when tReversed is [4, 3, 2, 1]
reverse tReversed
test "rereverse in-place (even)" when tReversed is [1, 2, 3, 4]
put [] into tReversed
reverse tReversed
test "reverse in-place (empty)" when tReversed is empty
end handler
end module