2 UnitTests addPrototype: #SkipList derivedFrom: {TestCase}.
4 tc@(UnitTests SkipList traits) isEmpty
7 tc assert: sl isEmpty description: 'new SkipList states that it is empty'.
10 tc@(UnitTests SkipList traits) size
13 tc assert: sl size = 0 description: 'empty SkipList has non-zero size'.
16 tc@(UnitTests SkipList traits) newPointerLength
20 10 timesRepeat: [ sum: sum + sl newPointerLength ].
21 tc assert: (sum between: 15 and: 25) description:
22 'pointerlength average is incorrect'.
25 tc@(UnitTests SkipList traits) forward
27 sln: SkipList Node clone.
28 sln pointers: (sln pointers newSize: 5).
29 0 upTo: 4 do: [| :i | sln pointers at: i put: i].
31 tc assert: (sln forward: i) = i description: 'forward answers wrong value'.].
34 tc@(UnitTests SkipList traits) add
38 tc assert: (sl size) = 1 description: 'added one item but size is not one'.
40 tc assert: (sl size) = 2 description: 'could not add item at last place'.
42 tc assert: (sl size) = 3 description: 'added as first does not increase size'.
45 tc@(UnitTests SkipList traits) includes
49 tc assert: (sl includes: 2) description: 'first added object is not included'.
51 tc assert: (sl includes: 5) description: 'second added object is not included'.
53 tc assert: (sl includes: 1) description: 'added as first not included'.
55 tc assert: (sl includes: 3) description: 'inserted not included'.
56 tc assert: (sl includes: 4) not description: 'includes unadded object'.
59 tc@(UnitTests SkipList traits) remove
64 tc assert: sl isEmpty description: 'not empty after add-remove'.
65 0 upTo: 10 do: [| :i | sl add: i].
66 tc assert: (sl size) = 11 description: 'pre-test check'.
68 tc assert: (sl size) = 10 description: 'remove does not decrease size'.
69 tc assert: (sl includes: 3) not description: 'found after removal'.
72 tc@(UnitTests SkipList traits) do
75 0 upTo: 9 do: [| :i | sl add: i].
77 sl do: [| :obj | obj < 5 ifTrue: [sum: sum + obj]].
78 tc assert: sum = 10 description: 'do on first elements failed'.
80 sl do: [| :obj | obj > 4 ifTrue: [sum: sum + obj]].
81 tc assert: sum = 35 description: 'do on last elements failed'.
85 obj < 5 /\ [counter < 5]
86 ifTrue: [sum: sum + obj. counter: counter + 1]].
87 tc assert: sum = 10 description: 'summed incorrect elements'.
90 tc@(UnitTests SkipList traits) reverseDoAndSequence
91 "Test reverseDo and sequence of elements."
94 0 upTo: 9 do: [| :i | sl add: i].
97 sl reverseDo: [| :obj |
100 obj < 8 ifTrue: [sum: sum + obj]]].
101 tc assert: sum = 18 description: 'reverse do on selected from first half failed'.
104 sl reverseDo: [| :obj |
105 counter < 8 ifTrue: [
106 counter: counter + 1.
107 obj < 5 ifTrue: [sum: sum + obj]]].
108 tc assert: sum = 9 description: 'reverse do on selection failed'.
111 tc@(UnitTests SkipList traits) addIfPresent
114 0 upTo: 9 do: [| :i | sl add: i].
116 0 upTo: 9 do: [| :i | sl add: i ifPresent: [counter: counter + 1]].
117 tc assert: counter = 10 description: 'added object when present'.
120 tc@(UnitTests SkipList traits) removeIfAbsent
124 0 upTo: 9 do: [| :i |
125 sl remove: i ifAbsent: [
126 counter: counter + 1.
128 0 upTo: 9 do: [| :i | sl remove: i ifAbsent: [counter: counter - 1]].
129 tc assert: counter = 10 description: 'removing absent object?'.
132 tc@(UnitTests SkipList traits) suite
133 [tc suiteForSelectors: {
142 #reverseDoAndSequence.