1 UnitTests definePrototype: #SkipList &basis: TestCase.
3 tc@(UnitTests SkipList traits) isEmpty
6 tc assert: sl isEmpty description: 'new SkipList states that it is empty'.
9 tc@(UnitTests SkipList traits) size
12 tc assert: sl size = 0 description: 'empty SkipList has non-zero size'.
15 tc@(UnitTests SkipList traits) newPointerLength
19 10 timesRepeat: [sum += sl newPointerLength].
20 tc assert: (sum between: 15 and: 25) description:
21 'pointerlength average is incorrect'.
24 tc@(UnitTests SkipList traits) forward
26 sln ::= SkipList Node clone.
27 sln pointers: (sln pointers newSize: 5).
28 0 upTo: 4 do: [| :i | sln pointers at: i put: i].
30 tc assert: (sln forward: i) = i description: 'forward answers wrong value'.].
33 tc@(UnitTests SkipList traits) add
37 tc assert: (sl size) = 1 description: 'added one item but size is not one'.
39 tc assert: (sl size) = 2 description: 'could not add item at last place'.
41 tc assert: (sl size) = 3 description: 'added as first does not increase size'.
44 tc@(UnitTests SkipList traits) includes
48 tc assert: (sl includes: 2) description: 'first added object is not included'.
50 tc assert: (sl includes: 5) description: 'second added object is not included'.
52 tc assert: (sl includes: 1) description: 'added as first not included'.
54 tc assert: (sl includes: 3) description: 'inserted not included'.
55 tc assert: (sl includes: 4) not description: 'includes unadded object'.
58 tc@(UnitTests SkipList traits) remove
63 tc assert: sl isEmpty description: 'not empty after add-remove'.
64 0 upTo: 10 do: [| :i | sl add: i].
65 tc assert: (sl size) = 11 description: 'pre-test check'.
67 tc assert: (sl size) = 10 description: 'remove does not decrease size'.
68 tc assert: (sl includes: 3) not description: 'found after removal'.
71 tc@(UnitTests SkipList traits) do
74 0 upTo: 9 do: [| :i | sl add: i].
76 sl do: [| :obj | obj < 5 ifTrue: [sum += obj]].
77 tc assert: sum = 10 description: 'do on first elements failed'.
79 sl do: [| :obj | obj > 4 ifTrue: [sum += obj]].
80 tc assert: sum = 35 description: 'do on last elements failed'.
84 obj < 5 /\ [counter < 5]
85 ifTrue: [sum += obj. counter += 1]].
86 tc assert: sum = 10 description: 'summed incorrect elements'.
89 tc@(UnitTests SkipList traits) reverseDoAndSequence
90 "Test reverseDo and sequence of elements."
93 0 upTo: 9 do: [| :i | sl add: i].
96 sl reverseDo: [| :obj |
99 obj < 8 ifTrue: [sum += obj]]].
100 tc assert: sum = 18 description: 'reverse do on selected from first half failed'.
103 sl reverseDo: [| :obj |
104 counter < 8 ifTrue: [
106 obj < 5 ifTrue: [sum += obj]]].
107 tc assert: sum = 9 description: 'reverse do on selection failed'.
110 tc@(UnitTests SkipList traits) addIfPresent
113 0 upTo: 9 do: [| :i | sl add: i].
115 0 upTo: 9 do: [| :i | sl add: i ifPresent: [counter += 1]].
116 tc assert: counter = 10 description: 'added object when present'.
119 tc@(UnitTests SkipList traits) removeIfAbsent
123 0 upTo: 9 do: [| :i |
124 sl remove: i ifAbsent: [
127 0 upTo: 9 do: [| :i | sl remove: i ifAbsent: [counter -= 1]].
128 tc assert: counter = 10 description: 'removing absent object?'.
131 tc@(UnitTests SkipList traits) suite
132 [tc suiteForSelectors: {
141 #reverseDoAndSequence.