|
2 | 2 |
|
3 | 3 |
|
4 | 4 | (function () {
|
| 5 | + "use strict"; |
5 | 6 |
|
6 | 7 | var HashSet = mx.HashSet,
|
7 | 8 | EqualityComparer = mx.EqualityComparer;
|
|
17 | 18 |
|
18 | 19 |
|
19 | 20 | function CreateObjectHashSet() {
|
20 |
| - var _items = [{ name: "A", val: 1 }, { name: "A", val: 2 }, { name: "B", val: 3 }, { name: "B", val: 4 }], |
| 21 | + var _items = [{ name: "A", value: 1 }, { name: "A", value: 2 }, { name: "B", value: 3 }, { name: "B", value: 4 }], |
21 | 22 | _comparer = {
|
22 | 23 | hash: function (o) { return mx.hash(o.name); },
|
23 | 24 | equals: function (a, b) { return a.name === b.name; }
|
|
50 | 51 |
|
51 | 52 | assert.ok(_hash1.add(6) === true, "add item to a HashSet of numbers!");
|
52 | 53 | assert.ok(_hash1.add(1) === false, "add existing item to a HashSet of numbers!");
|
53 |
| - assert.ok(_hash2.add({ name: "C", val: 5 }) === true, "add item to a HashSet of objects!"); |
54 |
| - assert.ok(_hash2.add({ name: "A", val: 5 }) === false, "add an existing item to a HashSet of objects!"); |
| 54 | + assert.ok(_hash2.add({ name: "C", value: 5 }) === true, "add item to a HashSet of objects!"); |
| 55 | + assert.ok(_hash2.add({ name: "A", value: 5 }) === false, "add an existing item to a HashSet of objects!"); |
55 | 56 | });
|
56 | 57 |
|
57 | 58 |
|
|
71 | 72 |
|
72 | 73 | assert.ok(_hash1.contains(1) === true, "HashSet of numbers contains an item!");
|
73 | 74 | assert.ok(_hash1.contains(6) === false, "HashSet of numbers does not contain an item!");
|
74 |
| - assert.ok(_hash2.contains({ name: "A", val: 5 }) === true, "HashSet of objects contains an item!"); |
75 |
| - assert.ok(_hash2.contains({ name: "C", val: 5 }) === false, "HashSet of objects does not contain an item!"); |
| 75 | + assert.ok(_hash2.contains({ name: "A", value: 5 }) === true, "HashSet of objects contains an item!"); |
| 76 | + assert.ok(_hash2.contains({ name: "C", value: 5 }) === false, "HashSet of objects does not contain an item!"); |
76 | 77 | });
|
77 | 78 |
|
78 | 79 |
|
|
96 | 97 | _hash2 = CreateObjectHashSet();
|
97 | 98 |
|
98 | 99 | assert.ok(_hash1.comparer() === EqualityComparer.defaultComparer, "HashSet default comparer!");
|
99 |
| - assert.ok(_hash2.comparer().equals({ name: "A", val: 1 }, { name: "A", val: 2 }), "HashSet custom comparer!"); |
| 100 | + assert.ok(_hash2.comparer().equals({ name: "A", value: 1 }, { name: "A", value: 2 }), "HashSet custom comparer!"); |
100 | 101 | });
|
101 | 102 |
|
102 | 103 |
|
|
107 | 108 |
|
108 | 109 | assert.ok(_hash1.remove(1) === true, "HashSet of numbers remove an item!");
|
109 | 110 | assert.ok(_hash1.remove(1) === false, "HashSet of numbers remove non existing item!");
|
110 |
| - assert.ok(_hash2.remove({ name: "A", val: 1 }) === true, "HashSet of objects remove an item!"); |
111 |
| - assert.ok(_hash2.remove({ name: "A", val: 1 }) === false, "HashSet of objects remove non existing item!"); |
| 111 | + assert.ok(_hash2.remove({ name: "A", value: 1 }) === true, "HashSet of objects remove an item!"); |
| 112 | + assert.ok(_hash2.remove({ name: "A", value: 1 }) === false, "HashSet of objects remove non existing item!"); |
112 | 113 | });
|
113 | 114 |
|
114 | 115 |
|
|
121 | 122 | assert.ok(_hash1.removeWhere("t => t < 3") === 0, "HashSet of numbers remove with invalid predicate, get number of items removed!");
|
122 | 123 | assert.ok(_hash1.count() === 3, "HashSet of numbers remove with predicate, get count!");
|
123 | 124 |
|
124 |
| - assert.ok(_hash2.removeWhere("t => t.val < 3") === 1, "HashSet of objects remove with predicate, get number of items removed!"); |
125 |
| - assert.ok(_hash2.removeWhere("t => t.val < 3") === 0, "HashSet of objects remove with invalid predicate, get number of items removed!"); |
| 125 | + assert.ok(_hash2.removeWhere("t => t.value < 3") === 1, "HashSet of objects remove with predicate, get number of items removed!"); |
| 126 | + assert.ok(_hash2.removeWhere("t => t.value < 3") === 0, "HashSet of objects remove with invalid predicate, get number of items removed!"); |
126 | 127 | assert.ok(_hash2.count() === 1, "HashSet of objects remove with predicate, get count!");
|
127 | 128 | });
|
128 | 129 |
|
|
134 | 135 | _hash3 = CreateNumericHashSet();
|
135 | 136 |
|
136 | 137 | _hash1.exceptWith([1, 2, 3]);
|
137 |
| - _hash2.exceptWith([{ name: "A", val: 0 }]); |
| 138 | + _hash2.exceptWith([{ name: "A", value: 0 }]); |
138 | 139 | _hash3.exceptWith(CreateNumericHashSet());
|
139 | 140 |
|
140 | 141 | assert.ok(_hash1.count() === 2 && _hash1.contains(1) === false, "HashSet of numbers except a collection, get count!");
|
141 |
| - assert.ok(_hash2.count() === 1 && _hash2.contains({ name: "A", val: 0 }) === false, "HashSet of objects except a collection, get count!"); |
| 142 | + assert.ok(_hash2.count() === 1 && _hash2.contains({ name: "A", value: 0 }) === false, "HashSet of objects except a collection, get count!"); |
142 | 143 | assert.ok(_hash3.count() === 0, "HashSet of numbers except an equal set, get count!");
|
143 | 144 | });
|
144 | 145 |
|
|
150 | 151 | _hash3 = CreateNumericHashSet();
|
151 | 152 |
|
152 | 153 | _hash1.intersectWith([1, 2, 3]);
|
153 |
| - _hash2.intersectWith([{ name: "A", val: 0 }]); |
| 154 | + _hash2.intersectWith([{ name: "A", value: 0 }]); |
154 | 155 | _hash3.intersectWith(CreateNumericHashSet());
|
155 | 156 |
|
156 | 157 | assert.ok(_hash1.count() === 3 && _hash1.contains(1) === true, "HashSet of numbers intersect with a collection, get count!");
|
157 |
| - assert.ok(_hash2.count() === 1 && _hash2.contains({ name: "A", val: 0 }) === true, "HashSet of objects intersect with a collection, get count!"); |
| 158 | + assert.ok(_hash2.count() === 1 && _hash2.contains({ name: "A", value: 0 }) === true, "HashSet of objects intersect with a collection, get count!"); |
158 | 159 | assert.ok(_hash3.count() === 5, "HashSet of numbers intersect with an equal set, get count!");
|
159 | 160 | });
|
160 | 161 |
|
|
213 | 214 | _hash2 = CreateObjectHashSet();
|
214 | 215 |
|
215 | 216 | assert.ok(_hash1.overlaps([1, 2, 3]) === true, "HashSet of numbers overlaps with another collection!");
|
216 |
| - assert.ok(_hash2.overlaps([{ name: "A", val: 0 }]) === true, "HashSet of objects overlaps with another collection!"); |
| 217 | + assert.ok(_hash2.overlaps([{ name: "A", value: 0 }]) === true, "HashSet of objects overlaps with another collection!"); |
217 | 218 | assert.ok(new HashSet().overlaps([1, 2, 3]) === false, "an empty HashSet does not overlap with another collection!");
|
218 | 219 | });
|
219 | 220 |
|
|
237 | 238 | _hash3 = CreateNumericHashSet();
|
238 | 239 |
|
239 | 240 | _hash1.symmetricExceptWith([2, 3, 4]);
|
240 |
| - _hash2.symmetricExceptWith([{ name: "A", val: 0 }]); |
| 241 | + _hash2.symmetricExceptWith([{ name: "A", value: 0 }]); |
241 | 242 | _hash3.exceptWith(CreateNumericHashSet());
|
242 | 243 |
|
243 | 244 | assert.ok(_hash1.count() === 2, "HashSet of numbers symmetric except another collection, get count!");
|
244 | 245 | assert.ok(_hash1.contains(1) === true && _hash1.contains(5) === true, "HashSet of numbers symmetric except another collection, check contains!");
|
245 | 246 | assert.ok(_hash2.count() === 1, "HashSet of objects symmetric except another collection, get count!");
|
246 |
| - assert.ok(_hash2.contains({ name: "A", val: 0 }) === false && _hash2.contains({ name: "B", val: 0 }) === true, "HashSet of objects symmetric except another collection, check contains!"); |
| 247 | + assert.ok(_hash2.contains({ name: "A", value: 0 }) === false && _hash2.contains({ name: "B", value: 0 }) === true, "HashSet of objects symmetric except another collection, check contains!"); |
247 | 248 | assert.ok(_hash3.count() === 0, "HashSet of numbers symmetric except an equal set, get count!");
|
248 | 249 | });
|
249 | 250 |
|
|
255 | 256 | _hash3 = CreateNumericHashSet();
|
256 | 257 |
|
257 | 258 | _hash1.unionWith([5, 6, 7, 8]);
|
258 |
| - _hash2.unionWith([{ name: "A", val: 5 }, { name: "B", val: 6 }, { name: "C", val: 7 }, { name: "D", val: 8 }]); |
| 259 | + _hash2.unionWith([{ name: "A", value: 5 }, { name: "B", value: 6 }, { name: "C", value: 7 }, { name: "D", value: 8 }]); |
259 | 260 | _hash3.unionWith(CreateNumericHashSet());
|
260 | 261 |
|
261 | 262 | assert.ok(_hash1.count() === 8, "HashSet of numbers union with another collection, get count!");
|
262 | 263 | assert.ok(_hash1.contains(1) === true && _hash1.contains(8) === true, "HashSet of numbers union with another collection, check contains!");
|
263 | 264 | assert.ok(_hash2.count() === 4, "HashSet of objects union with another collection, get count!");
|
264 |
| - assert.ok(_hash2.contains({ name: "A", val: 0 }) === true && _hash2.contains({ name: "D", val: 0 }) === true, "HashSet of objects union with another collection, check contains!"); |
| 265 | + assert.ok(_hash2.contains({ name: "A", value: 0 }) === true && _hash2.contains({ name: "D", value: 0 }) === true, "HashSet of objects union with another collection, check contains!"); |
265 | 266 | assert.ok(_hash3.count() === 5, "HashSet of numbers union with an equal set, get count!");
|
266 | 267 | });
|
267 | 268 |
|
|
272 | 273 | _hash2 = CreateObjectHashSet();
|
273 | 274 |
|
274 | 275 | assert.deepEqual(_hash1.select("t => t * 2").where("t => t > 5").toArray(), [6, 8, 10], "select-where-toArray over a HashSet of numbers!");
|
275 |
| - assert.deepEqual(_hash2.select("t => t.val * 2").where("t => t > 5").toArray(), [6], "select-where-toArray over a HashSet of objects!"); |
| 276 | + assert.deepEqual(_hash2.select("t => t.value * 2").where("t => t > 5").toArray(), [6], "select-where-toArray over a HashSet of objects!"); |
276 | 277 | });
|
277 | 278 |
|
278 | 279 |
|
|
0 commit comments