@@ -31,6 +31,69 @@ suite('Collections', () => {
3131 dict [ 'toString' ] = 123 ;
3232 collections . forEach ( dict , ( ) => count ++ ) ;
3333 assert . equal ( count , 1 ) ;
34+
35+ collections . forEach ( dict , ( ) => false ) ;
36+
37+ collections . forEach ( dict , ( x , remove ) => remove ( ) ) ;
38+ assert . equal ( dict [ 'toString' ] , null ) ;
39+
40+ // don't iterate over properties that are not on the object itself
41+ let test = Object . create ( { 'derived' : true } ) ;
42+ collections . forEach ( test , ( ) => assert ( false ) ) ;
43+ } ) ;
44+
45+ test ( 'lookupOrInsert - should not insert if found' , ( ) => {
46+ const property = 123 ;
47+
48+ let from = collections . createNumberDictionary ( ) ;
49+ from [ property ] = 'whatever' ;
50+
51+ collections . lookupOrInsert ( from , property , ( ) => assert ( false ) ) ;
52+ } ) ;
53+
54+ test ( 'lookupOrInsert - should insert if not found' , ( ) => {
55+
56+ const expected = 'alternate' , property = 'test' ;
57+
58+ let fromWithValue = collections . createStringDictionary ( ) ;
59+ collections . lookupOrInsert ( fromWithValue , property , expected ) ;
60+ assert . equal ( fromWithValue [ property ] , expected ) ;
61+
62+ let fromWithCallback = collections . createStringDictionary ( ) ;
63+ collections . lookupOrInsert ( fromWithCallback , property , ( ) => expected ) ;
64+ assert . equal ( fromWithCallback [ property ] , expected ) ;
65+ } ) ;
66+
67+ test ( 'groupBy' , ( ) => {
68+
69+ const group1 = 'a' , group2 = 'b' ;
70+ const value1 = 1 , value2 = 2 , value3 = 3 ;
71+ let source = [
72+ { key : group1 , value : value1 } ,
73+ { key : group1 , value : value2 } ,
74+ { key : group2 , value : value3 } ,
75+ ] ;
76+
77+ let grouped = collections . groupBy ( source , x => x . key ) ;
78+
79+ // Group 1
80+ assert . equal ( grouped [ group1 ] . length , 2 ) ;
81+ assert . equal ( grouped [ group1 ] [ 0 ] . value , value1 ) ;
82+ assert . equal ( grouped [ group1 ] [ 1 ] . value , value2 ) ;
83+
84+ // Group 2
85+ assert . equal ( grouped [ group2 ] . length , 1 ) ;
86+ assert . equal ( grouped [ group2 ] [ 0 ] . value , value3 ) ;
87+ } ) ;
88+
89+ test ( 'insert' , ( ) => {
90+
91+ const expected = 'value' , hashFn = x => x . toString ( ) ;
92+
93+ let into = collections . createStringDictionary ( ) ;
94+ collections . insert ( into , expected , hashFn ) ;
95+
96+ assert . equal ( into [ expected ] , expected ) ;
3497 } ) ;
3598
3699 test ( 'remove' , ( ) => {
0 commit comments