|
18 | 18 |
|
19 | 19 | heap = [[GSMinHeap alloc] init]; |
20 | 20 |
|
21 | | - PASS(heap != nil, "can create heap with default init"); |
| 21 | + PASS(heap != nil, "can create heap with default init") |
22 | 22 |
|
23 | | - PASS([heap peek] == nil, "peek on empty heap returns nil"); |
24 | | - PASS([heap pop] == nil, "pop on empty heap returns nil"); |
| 23 | + PASS([heap peek] == nil, "peek on empty heap returns nil") |
| 24 | + PASS([heap pop] == nil, "pop on empty heap returns nil") |
25 | 25 |
|
26 | | - PASS([heap push: nil] == NO, "cannot push nil"); |
27 | | - PASS([heap count] == 0, "heap count zero after push:nil"); |
28 | | - PASS([heap peek] == nil, "heap still empty after push:nil"); |
| 26 | + PASS([heap push: nil] == NO, "cannot push nil") |
| 27 | + PASS([heap count] == 0, "heap count zero after push:nil") |
| 28 | + PASS([heap peek] == nil, "heap still empty after push:nil") |
29 | 29 |
|
30 | | - PASS([heap push: @"c"] == YES, "push first object"); |
31 | | - PASS([heap count] == 1, "heap count one after push first object"); |
32 | | - PASS([[heap peek] isEqual: @"c"], "peek returns first object"); |
| 30 | + PASS([heap push: @"c"] == YES, "push first object") |
| 31 | + PASS([heap count] == 1, "heap count one after push first object") |
| 32 | + PASS([[heap peek] isEqual: @"c"], "peek returns first object") |
33 | 33 |
|
34 | | - PASS([heap push: @"a"] == YES, "push smaller object"); |
35 | | - PASS([heap count] == 2, "heap count two after push second object"); |
36 | | - PASS([[heap peek] isEqual: @"a"], "peek returns minimum object"); |
| 34 | + PASS([heap push: @"a"] == YES, "push smaller object") |
| 35 | + PASS([heap count] == 2, "heap count two after push second object") |
| 36 | + PASS([[heap peek] isEqual: @"a"], "peek returns minimum object") |
37 | 37 |
|
38 | | - PASS([heap push: @"b"] == YES, "push third object"); |
39 | | - PASS([heap count] == 3, "heap count three after push third object"); |
| 38 | + PASS([heap push: @"b"] == YES, "push third object") |
| 39 | + PASS([heap count] == 3, "heap count three after push third object") |
40 | 40 |
|
41 | 41 | obj = [heap pop]; |
42 | | - PASS([obj isEqual: @"a"], "first pop returns smallest object"); |
43 | | - PASS([heap count] == 2, "heap count two after pop one object"); |
| 42 | + PASS([obj isEqual: @"a"], "first pop returns smallest object") |
| 43 | + PASS([heap count] == 2, "heap count two after pop one object") |
44 | 44 |
|
45 | 45 | obj = [heap pop]; |
46 | | - PASS([obj isEqual: @"b"], "second pop returns second smallest object"); |
47 | | - PASS([heap count] == 1, "heap count two after pop two objects"); |
| 46 | + PASS([obj isEqual: @"b"], "second pop returns second smallest object") |
| 47 | + PASS([heap count] == 1, "heap count two after pop two objects") |
48 | 48 |
|
49 | 49 | obj = [heap pop]; |
50 | | - PASS([obj isEqual: @"c"], "third pop returns largest object"); |
51 | | - PASS([heap count] == 0, "heap count two after pop three objects"); |
| 50 | + PASS([obj isEqual: @"c"], "third pop returns largest object") |
| 51 | + PASS([heap count] == 0, "heap count two after pop three objects") |
52 | 52 |
|
53 | | - PASS([heap pop] == nil, "heap empty after removing all objects"); |
| 53 | + PASS([heap pop] == nil, "heap empty after removing all objects") |
| 54 | + |
| 55 | + [heap push: @"a"]; |
| 56 | + [heap drop]; |
| 57 | + PASS([heap count] == 0, "heap count 0 after push drop sequence") |
| 58 | + |
| 59 | + [heap push: @"a"]; |
| 60 | + [heap push: @"b"]; |
| 61 | + PASS_EQUAL([heap next], @"b", "heap -next of a,b returns b") |
| 62 | + PASS([heap count] == 1, "heap count 1 after push push next") |
54 | 63 |
|
55 | 64 | DESTROY(heap); |
56 | 65 |
|
|
65 | 74 | for (i = 100; i >= 0; i--) |
66 | 75 | { |
67 | 76 | PASS([heap push: [NSNumber numberWithInt: i]] == YES, |
68 | | - "push succeeds"); |
| 77 | + "push succeeds") |
69 | 78 | } |
70 | 79 |
|
71 | 80 | PASS_EQUAL([[heap peek] stringValue], @"0", |
72 | | - "minimum survives resizing"); |
| 81 | + "minimum survives resizing") |
73 | 82 |
|
74 | 83 | for (i = 0; i <= 100; i++) |
75 | 84 | { |
76 | 85 | NSNumber *n = [heap pop]; |
77 | | - PASS([n intValue] == i, "pop returns values in ascending order"); |
| 86 | + PASS([n intValue] == i, "pop returns values in ascending order") |
78 | 87 | } |
79 | 88 |
|
80 | | - PASS([heap pop] == nil, "heap empty after growth test"); |
| 89 | + PASS([heap pop] == nil, "heap empty after growth test") |
81 | 90 |
|
82 | 91 | DESTROY(heap); |
83 | 92 |
|
|
93 | 102 | [heap push: @"b"]; |
94 | 103 |
|
95 | 104 | PASS([[heap peek] isEqual: @"c"], |
96 | | - "custom comparator changes ordering"); |
| 105 | + "custom comparator changes ordering") |
97 | 106 |
|
98 | 107 | obj = [heap pop]; |
99 | | - PASS([obj isEqual: @"c"], "first pop uses custom comparator"); |
| 108 | + PASS([obj isEqual: @"c"], "first pop uses custom comparator") |
100 | 109 |
|
101 | 110 | obj = [heap pop]; |
102 | | - PASS([obj isEqual: @"b"], "second pop uses custom comparator"); |
| 111 | + PASS([obj isEqual: @"b"], "second pop uses custom comparator") |
103 | 112 |
|
104 | 113 | obj = [heap pop]; |
105 | | - PASS([obj isEqual: @"a"], "third pop uses custom comparator"); |
| 114 | + PASS([obj isEqual: @"a"], "third pop uses custom comparator") |
106 | 115 |
|
107 | 116 | DESTROY(heap); |
108 | 117 |
|
|
118 | 127 |
|
119 | 128 | [heap empty]; |
120 | 129 |
|
121 | | - PASS([heap peek] == nil, "peek after empty returns nil"); |
122 | | - PASS([heap pop] == nil, "pop after empty returns nil"); |
| 130 | + PASS([heap peek] == nil, "peek after empty returns nil") |
| 131 | + PASS([heap pop] == nil, "pop after empty returns nil") |
123 | 132 |
|
124 | 133 | PASS([heap push: @"x"] == YES, |
125 | | - "heap remains usable after empty"); |
| 134 | + "heap remains usable after empty") |
126 | 135 |
|
127 | 136 | PASS([[heap pop] isEqual: @"x"], |
128 | | - "heap functions correctly after empty"); |
| 137 | + "heap functions correctly after empty") |
129 | 138 |
|
130 | 139 | DESTROY(heap); |
131 | 140 |
|
|
0 commit comments