Skip to content

Commit d074f15

Browse files
committed
improve code coverage of SlotList class
1 parent e30d62b commit d074f15

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

test/org/osflash/signals/SlotListTest.test.ts

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("SlotListTest", () => {
1414
let listenerA: Function;
1515
let listenerB: Function;
1616
let listenerC: Function;
17+
let listenerD: Function;
1718
let slotA: ISlot;
1819
let slotB: ISlot;
1920
let slotC: ISlot;
@@ -29,6 +30,8 @@ describe("SlotListTest", () => {
2930
};
3031
listenerC = function(e: any = null): void {
3132
};
33+
listenerD = function(e: any = null): void {
34+
};
3235
slotA = new Slot(listenerA, signal);
3336
slotB = new Slot(listenerB, signal);
3437
slotC = new Slot(listenerC, signal);
@@ -59,6 +62,10 @@ describe("SlotListTest", () => {
5962
assert.throws(() => new SlotList(null, null), Error);
6063
});
6164

65+
it("contains_should_return_false_when_listener_is_not_part_of_list", () => {
66+
assert.isFalse(listOfABC.contains(listenerD));
67+
});
68+
6269
it("list_with_one_listener_contains_it", () => {
6370
assert.isTrue(listOfA.contains(listenerA));
6471
});
@@ -75,135 +82,121 @@ describe("SlotListTest", () => {
7582
assert.equal(listenerA, listOfA.head.listener);
7683
});
7784

78-
7985
it("NIL_does_not_contain_anonymous_listener", () => {
8086
assert.isFalse(SlotList.NIL.contains(new Function()));
8187
});
8288

83-
8489
it("find_in_empty_list_yields_null", () => {
8590
assert.isNull(SlotList.NIL.find(listenerA));
8691
});
8792

88-
8993
it("NIL_does_not_contain_null_listener", () => {
9094
assert.isFalse(SlotList.NIL.contains(null));
9195
});
9296

93-
9497
it("find_the_1st_of_2_listeners_yields_its_slot", () => {
9598
assert.equal(slotA, listOfAB.find(listenerA));
9699
});
97100

98-
99101
it("find_the_2nd_of_2_listeners_yields_its_slot", () => {
100102
assert.equal(slotB, listOfAB.find(listenerB));
101103
});
102104

103-
104105
it("find_the_1st_of_3_listeners_yields_its_slot", () => {
105106
assert.equal(slotA, listOfABC.find(listenerA));
106107
});
107108

108-
109109
it("find_the_2nd_of_3_listeners_yields_its_slot", () => {
110110
assert.equal(slotB, listOfABC.find(listenerB));
111111
});
112112

113-
114113
it("find_the_3rd_of_3_listeners_yields_its_slot", () => {
115114
assert.equal(slotC, listOfABC.find(listenerC));
116115
});
117116

118-
119117
it("prepend_a_slot_makes_it_head_of_new_list", () => {
120118
let newList: SlotList = listOfA.prepend(slotB);
121119
assert.equal(slotB, newList.head);
122120
});
123121

124-
125122
it("prepend_a_slot_makes_the_old_list_the_tail", () => {
126123
let newList: SlotList = listOfA.prepend(slotB);
127124
assert.equal(listOfA, newList.tail);
128125
});
129126

130-
131127
it("after_prepend_slot_new_list_contains_its_listener", () => {
132128
let newList: SlotList = listOfA.prepend(slotB);
133129
assert.isTrue(newList.contains(slotB.listener));
134130
});
135131

136-
137132
it("append_a_slot_yields_new_list_with_same_head", () => {
138133
let oldHead: ISlot = listOfA.head;
139134
let newList: SlotList = listOfA.append(slotB);
140135
assert.equal(oldHead, newList.head);
141136
});
142137

143-
144138
it("append_to_list_of_one_yields_list_of_length_two", () => {
145139
let newList: SlotList = listOfA.append(slotB);
146140
assert.equal(2, newList.length);
147141
});
148142

149-
150143
it("after_append_slot_new_list_contains_its_listener", () => {
151144
let newList: SlotList = listOfA.append(slotB);
152145
assert.isTrue(newList.contains(slotB.listener));
153146
});
154147

155-
156148
it("append_slot_yields_a_different_list", () => {
157149
let newList: SlotList = listOfA.append(slotB);
158150
assert.notEqual(listOfA, newList);
159151
});
160152

161-
162153
it("append_null_yields_same_list", () => {
163154
let newList: SlotList = listOfA.append(null);
164155
assert.equal(listOfA, newList);
165156
});
166157

167-
168158
it("filterNot_on_empty_list_yields_same_list", () => {
169159
let newList: SlotList = SlotList.NIL.filterNot(listenerA);
170160
assert.equal(SlotList.NIL, newList);
171161
});
172162

173-
174163
it("filterNot_null_yields_same_list", () => {
175164
let newList: SlotList = listOfA.filterNot(null);
176165
assert.equal(listOfA, newList);
177166
});
178167

179-
180168
it("filterNot_head_from_list_of_1_yields_empty_list", () => {
181169
let newList: SlotList = listOfA.filterNot(listOfA.head.listener);
182170
assert.equal(SlotList.NIL, newList);
183171
});
184172

185-
186173
it("filterNot_1st_listener_from_list_of_2_yields_list_of_2nd_listener", () => {
187174
let newList: SlotList = listOfAB.filterNot(listenerA);
188175
assert.equal(listenerB, newList.head.listener);
189176
assert.equal(1, newList.length);
190177
});
191178

192-
193179
it("filterNot_2nd_listener_from_list_of_2_yields_list_of_head", () => {
194180
let newList: SlotList = listOfAB.filterNot(listenerB);
195181
assert.equal(listenerA, newList.head.listener);
196182
assert.equal(1, newList.length);
197183
});
198184

199-
200185
it("filterNot_2nd_listener_from_list_of_3_yields_list_of_1st_and_3rd", () => {
201186
let newList: SlotList = listOfABC.filterNot(listenerB);
202187
assert.equal(listenerA, newList.head.listener);
203188
assert.equal(listenerC, newList.tail.head.listener);
204189
assert.equal(2, newList.length);
205190
});
206191

192+
it("filterNot_with_unknow_listener_should_not_change_list", () => {
193+
let newList: SlotList = listOfABC.filterNot(listenerD);
194+
assert.equal(listenerA, newList.head.listener);
195+
assert.equal(listenerB, newList.tail.head.listener);
196+
assert.equal(listenerC, newList.tail.tail.head.listener);
197+
assert.equal(3, newList.length);
198+
assert.equal(listOfABC, newList);
199+
});
207200

208201
// Issue #56
209202
it("insertWithPriority_adds_4_slots_without_losing_any", () => {
@@ -227,11 +220,10 @@ describe("SlotListTest", () => {
227220
assert.equal(slot4, list.tail.tail.head);
228221
assert.equal(slot2, list.tail.tail.tail.head);
229222
});
230-
});
231-
232-
233-
234-
235-
236-
237223

224+
it("toString_should_return_string", () => {
225+
assert.isString(listOfA.toString());
226+
assert.isString(listOfAB.toString());
227+
assert.isString(listOfABC.toString());
228+
});
229+
});

0 commit comments

Comments
 (0)