11module MxTests {
2+ "use strict" ;
23
34 import HashSet = mx . HashSet ;
4- import EqualityComparer = mx . EqualityComparer ;
55
6+ var HashSet = mx . HashSet ,
7+ EqualityComparer = mx . EqualityComparer ;
68
79
810 /* Factory methods
911 ---------------------------------------------------------------------- */
1012
1113 interface SimpleObject {
1214 name : string ;
13- val : number ;
15+ value : number ;
1416 }
1517
1618
2123
2224 function CreateObjectHashSet ( ) : HashSet < SimpleObject > {
2325
24- var _items : SimpleObject [ ] = [ { name : "A" , val : 1 } , { name : "A" , val : 2 } , { name : "B" , val : 3 } , { name : "B" , val : 4 } ] ,
26+ var _items : SimpleObject [ ] = [ { name : "A" , value : 1 } , { name : "A" , value : 2 } , { name : "B" , value : 3 } , { name : "B" , value : 4 } ] ,
2527 _comparer = EqualityComparer . create < SimpleObject > ( obj => mx . hash ( obj . name ) , ( a , b ) => a . name === b . name ) ;
2628
2729 return new HashSet < SimpleObject > ( _items , _comparer ) ;
2830 }
29-
31+
3032
3133
3234 /* Tests
5153
5254 assert . ok ( _hash1 . add ( 6 ) === true , "add item to a HashSet of numbers!" ) ;
5355 assert . ok ( _hash1 . add ( 1 ) === false , "add existing item to a HashSet of numbers!" ) ;
54- assert . ok ( _hash2 . add ( { name : "C" , val : 5 } ) === true , "add item to a HashSet of objects!" ) ;
55- assert . ok ( _hash2 . add ( { name : "A" , val : 5 } ) === false , "add an existing item to a HashSet of objects!" ) ;
56+ assert . ok ( _hash2 . add ( { name : "C" , value : 5 } ) === true , "add item to a HashSet of objects!" ) ;
57+ assert . ok ( _hash2 . add ( { name : "A" , value : 5 } ) === false , "add an existing item to a HashSet of objects!" ) ;
5658 } ) ;
5759
5860
7274
7375 assert . ok ( _hash1 . contains ( 1 ) === true , "HashSet of numbers contains an item!" ) ;
7476 assert . ok ( _hash1 . contains ( 6 ) === false , "HashSet of numbers does not contain an item!" ) ;
75- assert . ok ( _hash2 . contains ( { name : "A" , val : 5 } ) === true , "HashSet of objects contains an item!" ) ;
76- assert . ok ( _hash2 . contains ( { name : "C" , val : 5 } ) === false , "HashSet of objects does not contain an item!" ) ;
77+ assert . ok ( _hash2 . contains ( { name : "A" , value : 5 } ) === true , "HashSet of objects contains an item!" ) ;
78+ assert . ok ( _hash2 . contains ( { name : "C" , value : 5 } ) === false , "HashSet of objects does not contain an item!" ) ;
7779 } ) ;
7880
7981
9597 _hash2 = CreateObjectHashSet ( ) ;
9698
9799 assert . ok ( _hash1 . comparer ( ) === mx . EqualityComparer . defaultComparer , "HashSet default comparer!" ) ;
98- 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!" ) ;
99101 } ) ;
100102
101103
106108
107109 assert . ok ( _hash1 . remove ( 1 ) === true , "HashSet of numbers remove an item!" ) ;
108110 assert . ok ( _hash1 . remove ( 1 ) === false , "HashSet of numbers remove non existing item!" ) ;
109- assert . ok ( _hash2 . remove ( { name : "A" , val : 1 } ) === true , "HashSet of objects remove an item!" ) ;
110- 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!" ) ;
111113 } ) ;
112114
113115
120122 assert . ok ( _hash1 . removeWhere ( t => t < 3 ) === 0 , "HashSet of numbers remove with invalid predicate, get number of items removed!" ) ;
121123 assert . ok ( _hash1 . count ( ) === 3 , "HashSet of numbers remove with predicate, get count!" ) ;
122124
123- assert . ok ( _hash2 . removeWhere ( t => t . val < 3 ) === 1 , "HashSet of objects remove with predicate, get number of items removed!" ) ;
124- 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!" ) ;
125127 assert . ok ( _hash2 . count ( ) === 1 , "HashSet of objects remove with predicate, get count!" ) ;
126128 } ) ;
127129
133135 _hash3 = CreateNumericHashSet ( ) ;
134136
135137 _hash1 . exceptWith ( [ 1 , 2 , 3 ] ) ;
136- _hash2 . exceptWith ( [ { name : "A" , val : 0 } ] ) ;
138+ _hash2 . exceptWith ( [ { name : "A" , value : 0 } ] ) ;
137139 _hash3 . exceptWith ( CreateNumericHashSet ( ) ) ;
138140
139141 assert . ok ( _hash1 . count ( ) === 2 && _hash1 . contains ( 1 ) === false , "HashSet of numbers except a collection, get count!" ) ;
140- 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!" ) ;
141143 assert . ok ( _hash3 . count ( ) === 0 , "HashSet of numbers except an equal set, get count!" ) ;
142144 } ) ;
143145
149151 _hash3 = CreateNumericHashSet ( ) ;
150152
151153 _hash1 . intersectWith ( [ 1 , 2 , 3 ] ) ;
152- _hash2 . intersectWith ( [ { name : "A" , val : 0 } ] ) ;
154+ _hash2 . intersectWith ( [ { name : "A" , value : 0 } ] ) ;
153155 _hash3 . intersectWith ( CreateNumericHashSet ( ) ) ;
154156
155157 assert . ok ( _hash1 . count ( ) === 3 && _hash1 . contains ( 1 ) === true , "HashSet of numbers intersect with a collection, get count!" ) ;
156- 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!" ) ;
157159 assert . ok ( _hash3 . count ( ) === 5 , "HashSet of numbers intersect with an equal set, get count!" ) ;
158160 } ) ;
159161
212214 _hash2 = CreateObjectHashSet ( ) ;
213215
214216 assert . ok ( _hash1 . overlaps ( [ 1 , 2 , 3 ] ) === true , "HashSet of numbers overlaps with another collection!" ) ;
215- 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!" ) ;
216218 assert . ok ( new HashSet ( ) . overlaps ( [ 1 , 2 , 3 ] ) === false , "an empty HashSet does not overlap with another collection!" ) ;
217219 } ) ;
218220
236238 _hash3 = CreateNumericHashSet ( ) ;
237239
238240 _hash1 . symmetricExceptWith ( [ 2 , 3 , 4 ] ) ;
239- _hash2 . symmetricExceptWith ( [ { name : "A" , val : 0 } ] ) ;
241+ _hash2 . symmetricExceptWith ( [ { name : "A" , value : 0 } ] ) ;
240242 _hash3 . exceptWith ( CreateNumericHashSet ( ) ) ;
241243
242244 assert . ok ( _hash1 . count ( ) === 2 , "HashSet of numbers symmetric except another collection, get count!" ) ;
243245 assert . ok ( _hash1 . contains ( 1 ) === true && _hash1 . contains ( 5 ) === true , "HashSet of numbers symmetric except another collection, check contains!" ) ;
244246 assert . ok ( _hash2 . count ( ) === 1 , "HashSet of objects symmetric except another collection, get count!" ) ;
245- 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!" ) ;
246248 assert . ok ( _hash3 . count ( ) === 0 , "HashSet of numbers symmetric except an equal set, get count!" ) ;
247249 } ) ;
248250
254256 _hash3 = CreateNumericHashSet ( ) ;
255257
256258 _hash1 . unionWith ( [ 5 , 6 , 7 , 8 ] ) ;
257- _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 } ] ) ;
258260 _hash3 . unionWith ( CreateNumericHashSet ( ) ) ;
259261
260262 assert . ok ( _hash1 . count ( ) === 8 , "HashSet of numbers union with another collection, get count!" ) ;
261263 assert . ok ( _hash1 . contains ( 1 ) === true && _hash1 . contains ( 8 ) === true , "HashSet of numbers union with another collection, check contains!" ) ;
262264 assert . ok ( _hash2 . count ( ) === 4 , "HashSet of objects union with another collection, get count!" ) ;
263- 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!" ) ;
264266 assert . ok ( _hash3 . count ( ) === 5 , "HashSet of numbers union with an equal set, get count!" ) ;
265267 } ) ;
266268
271273 _hash2 = CreateObjectHashSet ( ) ;
272274
273275 assert . deepEqual ( _hash1 . select ( t => t * 2 ) . where ( t => t > 5 ) . toArray ( ) , [ 6 , 8 , 10 ] , "select-where-toArray over a HashSet of numbers!" ) ;
274- 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!" ) ;
275277 } ) ;
276278}
0 commit comments