You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assert.ok(newHashSet<number>().count()===0,"initialize an empty HashSet!");
29
+
assert.ok(newHashSet<number>(mx.range(1,5)).count()===5,"initialize a HashSet using specified collection!");
30
+
assert.ok(newHashSet<number>(mx.EqualityComparer.defaultComparer).count()===0,"initialize a HashSet using specified equality comparer!");
31
+
assert.ok(CreateObjectHashSet().count()===2,"initialize a HashSet using specified collection and equality comparer!");
32
+
});
33
+
34
+
35
+
QUnit.test("add",function(assert){
36
+
37
+
var_hash1=CreateNumericHashSet(),
38
+
_hash2=CreateObjectHashSet();
39
+
40
+
assert.ok(_hash1.add(6)===true,"add item to a HashSet of numbers!");
41
+
assert.ok(_hash1.add(1)===false,"add existing item to a HashSet of numbers!");
42
+
assert.ok(_hash2.add({name: "C",val: 5})===true,"add item to a HashSet of objects!");
43
+
assert.ok(_hash2.add({name: "A",val: 5})===false,"add an existing item to a HashSet of objects!");
44
+
});
45
+
46
+
47
+
QUnit.test("clear",function(assert){
48
+
49
+
var_hash=CreateNumericHashSet();
50
+
51
+
_hash.clear();
52
+
assert.ok(_hash.count()===0,"clear a HashSet!");
53
+
});
54
+
55
+
56
+
QUnit.test("contains",function(assert){
57
+
58
+
var_hash1=CreateNumericHashSet(),
59
+
_hash2=CreateObjectHashSet();
60
+
61
+
assert.ok(_hash1.contains(1)===true,"HashSet of numbers contains an item!");
62
+
assert.ok(_hash1.contains(6)===false,"HashSet of numbers does not contain an item!");
63
+
assert.ok(_hash2.contains({name: "A",val: 5})===true,"HashSet of objects contains an item!");
64
+
assert.ok(_hash2.contains({name: "C",val: 5})===false,"HashSet of objects does not contain an item!");
65
+
});
66
+
67
+
68
+
QUnit.test("copyTo",function(assert){
69
+
70
+
var_hash=CreateNumericHashSet(),
71
+
_arr=newArray(_hash.count());
72
+
73
+
_hash.copyTo(_arr,0);
74
+
75
+
assert.deepEqual(_arr,[1,2,3,4,5],"HashSet copy to an array!");
76
+
assert.throws(()=>_hash.copyTo([],0),"throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
assert.ok(_hash1.remove(1)===true,"HashSet of numbers remove an item!");
96
+
assert.ok(_hash1.remove(1)===false,"HashSet of numbers remove non existing item!");
97
+
assert.ok(_hash2.remove({name: "A",val: 1})===true,"HashSet of objects remove an item!");
98
+
assert.ok(_hash2.remove({name: "A",val: 1})===false,"HashSet of objects remove non existing item!");
99
+
});
100
+
101
+
102
+
QUnit.test("removeWhere",function(assert){
103
+
104
+
var_hash1=CreateNumericHashSet(),
105
+
_hash2=CreateObjectHashSet();
106
+
107
+
assert.ok(_hash1.removeWhere(t=>t<3)===2,"HashSet of numbers remove with predicate, get number of items removed!");
108
+
assert.ok(_hash1.removeWhere(t=>t<3)===0,"HashSet of numbers remove with invalid predicate, get number of items removed!");
109
+
assert.ok(_hash1.count()===3,"HashSet of numbers remove with predicate, get count!");
110
+
111
+
assert.ok(_hash2.removeWhere(t=>t.val<3)===1,"HashSet of objects remove with predicate, get number of items removed!");
112
+
assert.ok(_hash2.removeWhere(t=>t.val<3)===0,"HashSet of objects remove with invalid predicate, get number of items removed!");
113
+
assert.ok(_hash2.count()===1,"HashSet of objects remove with predicate, get count!");
114
+
});
115
+
116
+
117
+
QUnit.test("exceptWith",function(assert){
118
+
119
+
var_hash1=CreateNumericHashSet(),
120
+
_hash2=CreateObjectHashSet(),
121
+
_hash3=CreateNumericHashSet();
122
+
123
+
_hash1.exceptWith([1,2,3]);
124
+
_hash2.exceptWith([{name: "A",val: 0}]);
125
+
_hash3.exceptWith(CreateNumericHashSet());
126
+
127
+
assert.ok(_hash1.count()===2&&_hash1.contains(1)===false,"HashSet of numbers except a collection, get count!");
128
+
assert.ok(_hash2.count()===1&&_hash2.contains({name: "A",val: 0})===false,"HashSet of objects except a collection, get count!");
129
+
assert.ok(_hash3.count()===0,"HashSet of numbers except an equal set, get count!");
130
+
});
131
+
132
+
133
+
QUnit.test("intersectWith",function(assert){
134
+
135
+
var_hash1=CreateNumericHashSet(),
136
+
_hash2=CreateObjectHashSet(),
137
+
_hash3=CreateNumericHashSet();
138
+
139
+
_hash1.intersectWith([1,2,3]);
140
+
_hash2.intersectWith([{name: "A",val: 0}]);
141
+
_hash3.intersectWith(CreateNumericHashSet());
142
+
143
+
assert.ok(_hash1.count()===3&&_hash1.contains(1)===true,"HashSet of numbers intersect with a collection, get count!");
144
+
assert.ok(_hash2.count()===1&&_hash2.contains({name: "A",val: 0})===true,"HashSet of objects intersect with a collection, get count!");
145
+
assert.ok(_hash3.count()===5,"HashSet of numbers intersect with an equal set, get count!");
146
+
});
147
+
148
+
149
+
QUnit.test("isProperSubsetOf",function(assert){
150
+
151
+
var_hash=CreateNumericHashSet();
152
+
153
+
assert.ok(newHashSet<number>().isProperSubsetOf([1,2,3])===true,"an empty set is a proper subset of any other collection!");
154
+
assert.ok(newHashSet<number>().isProperSubsetOf([])===false,"an empty set is not a proper subset of another empty collection!");
155
+
assert.ok(_hash.isProperSubsetOf([1,2,3,4])===false,"a hash set is not a proper subset of another collection when count is greater than the number of elements in other!");
156
+
assert.ok(_hash.isProperSubsetOf([1,2,3,4,5])===false,"a hash set is not a proper subset of another collection when count is equal to the number of elements in other!");
157
+
assert.ok(_hash.isProperSubsetOf([1,2,3,4,5,6])===true,"hash set proper subset!");
158
+
});
159
+
160
+
161
+
QUnit.test("isProperSupersetOf",function(assert){
162
+
163
+
var_hash=CreateNumericHashSet();
164
+
165
+
assert.ok(newHashSet<number>().isProperSupersetOf([1,2,3])===false,"an empty set is a not superset of any other collection!");
166
+
assert.ok(newHashSet<number>().isProperSupersetOf([])===false,"an empty set is not a proper superset of another empty collection!");
167
+
assert.ok(_hash.isProperSupersetOf([1,2,3,4,5,6])===false,"a hash set is not a proper superset of another collection when count is less than the number of elements in other!");
168
+
assert.ok(_hash.isProperSupersetOf([1,2,3,4,5])===false,"a hash set is not a proper superset of another collection when count is equal to the number of elements in other!");
169
+
assert.ok(_hash.isProperSupersetOf([1,2,3])===true,"hash set proper superset!");
170
+
});
171
+
172
+
173
+
QUnit.test("isSubsetOf",function(assert){
174
+
175
+
var_hash=CreateNumericHashSet();
176
+
177
+
assert.ok(newHashSet<number>().isSubsetOf([1,2,3])===true,"an empty set is a subset of any other collection!");
178
+
assert.ok(newHashSet<number>().isSubsetOf([])===true,"an empty set is a subset of another empty collection!");
179
+
assert.ok(_hash.isSubsetOf([1,2,3,4])===false,"a hash set is not a subset of another collection when count is greater than the number of elements in other!");
180
+
assert.ok(_hash.isSubsetOf([1,2,3,4,5])===true,"a hash set is a proper subset of another collection when count is equal to the number of elements in other!");
181
+
assert.ok(_hash.isSubsetOf([1,2,3,4,5,6])===true,"hash set subset!");
182
+
});
183
+
184
+
185
+
QUnit.test("isSupersetOf",function(assert){
186
+
187
+
var_hash=CreateNumericHashSet();
188
+
189
+
assert.ok(newHashSet<number>().isSupersetOf([1,2,3])===false,"an empty set is a not superset of any other collection!");
190
+
assert.ok(newHashSet<number>().isSupersetOf([])===true,"an empty set is superset of another empty collection!");
191
+
assert.ok(_hash.isSupersetOf([1,2,3,4,5,6])===false,"a hash set is not a superset of another collection when count is less than the number of elements in other!");
192
+
assert.ok(_hash.isSupersetOf([1,2,3,4,5])===true,"a hash set is a proper superset of another collection when count is equal to the number of elements in other!");
193
+
assert.ok(_hash.isSupersetOf([1,2,3])===true,"hash set superset!");
194
+
});
195
+
196
+
197
+
QUnit.test("overlaps",function(assert){
198
+
199
+
var_hash1=CreateNumericHashSet(),
200
+
_hash2=CreateObjectHashSet();
201
+
202
+
assert.ok(_hash1.overlaps([1,2,3])===true,"HashSet of numbers overlaps with another collection!");
203
+
assert.ok(_hash2.overlaps([{name: "A",val: 0}])===true,"HashSet of objects overlaps with another collection!");
204
+
assert.ok(newHashSet().overlaps([1,2,3])===false,"an empty HashSet does not overlap with another collection!");
205
+
});
206
+
207
+
208
+
QUnit.test("setEquals",function(assert){
209
+
210
+
var_hash1=CreateNumericHashSet(),
211
+
_hash2=CreateNumericHashSet();
212
+
213
+
assert.ok(_hash1.setEquals(_hash2)===true,"HashSet of numbers equals with another HashSet!");
214
+
assert.ok(_hash1.setEquals([1,2,3,4,5])===true,"HashSet of numbers equals with another collection!");
215
+
assert.ok(newHashSet<number>().setEquals([])===true,"an empty HashSet equals with an empty collection!");
216
+
assert.ok(newHashSet<number>().setEquals([1,2,3])===false,"an empty HashSet does not equals with another collection!");
assert.ok(_hash1.count()===8,"HashSet of numbers union with another collection, get count!");
249
+
assert.ok(_hash1.contains(1)===true&&_hash1.contains(8)===true,"HashSet of numbers union with another collection, check contains!");
250
+
assert.ok(_hash2.count()===4,"HashSet of objects union with another collection, get count!");
251
+
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!");
252
+
assert.ok(_hash3.count()===5,"HashSet of numbers union with an equal set, get count!");
253
+
});
254
+
255
+
256
+
QUnit.test("set enumerable",function(assert){
257
+
258
+
var_hash1=CreateNumericHashSet(),
259
+
_hash2=CreateObjectHashSet();
260
+
261
+
assert.deepEqual(_hash1.select(t=>t*2).where(t=>t>5).toArray(),[6,8,10],"select-where-toArray over a HashSet of numbers!");
262
+
assert.deepEqual(_hash2.select(t=>t.val*2).where(t=>t>5).toArray(),[6],"select-where-toArray over a HashSet of objects!");
0 commit comments