35 |
35 |
36 !CECollectionExtensionTest methodsFor:'collect as set'! |
36 !CECollectionExtensionTest methodsFor:'collect as set'! |
37 |
37 |
38 testCollectAsSet |
38 testCollectAsSet |
39 "self debug: #testCollectAsSet" |
39 "self debug: #testCollectAsSet" |
40 |
40 |
41 self assert: ((#() collectAsSet: [:each | each odd]) = Set new). |
41 self assert: ((#() collectAsSet: [:each | each odd]) = Set new). |
42 self assert: (#(1 2 3 4 5 6) collectAsSet: [:each | each odd]) |
42 self assert: (#(1 2 3 4 5 6) collectAsSet: [:each | each odd]) |
43 = (Set with: true with: false). |
43 = (Set with: true with: false). |
44 self assert: (#(1 3 5 7 9 11) collectAsSet: [:each | each odd]) |
44 self assert: (#(1 3 5 7 9 11) collectAsSet: [:each | each odd]) |
45 = (Set with: true). |
45 = (Set with: true). |
46 |
46 |
47 self assert: (#(1 2 3 4 5 4 3 2 1) collectAsSet: [:each | each]) = (1 to: 5) asSet. |
47 self assert: (#(1 2 3 4 5 4 3 2 1) collectAsSet: [:each | each]) = (1 to: 5) asSet. |
48 |
48 |
49 |
49 |
50 ! |
50 ! |
51 |
51 |
52 testCollectAsSetUsingSymbol |
52 testCollectAsSetUsingSymbol |
53 "self debug: #testCollectAsSetUsingSymbol" |
53 "self debug: #testCollectAsSetUsingSymbol" |
54 |
54 |
55 self assert: ((#() collectAsSet: #odd) = Set new). |
55 self assert: ((#() collectAsSet: #odd) = Set new). |
56 self assert: (#(1 2 3 4 5 6) collectAsSet: #odd) |
56 self assert: (#(1 2 3 4 5 6) collectAsSet: #odd) |
57 = (Set with: true with: false). |
57 = (Set with: true with: false). |
58 self assert: (#(1 3 5 7 9 11) collectAsSet: #odd) |
58 self assert: (#(1 3 5 7 9 11) collectAsSet: #odd) |
59 = (Set with: true). |
59 = (Set with: true). |
60 ! ! |
60 ! ! |
61 |
61 |
62 !CECollectionExtensionTest methodsFor:'flat collect'! |
62 !CECollectionExtensionTest methodsFor:'flat collect'! |
63 |
63 |
64 testFlatCollect |
64 testFlatCollect |
65 "self debug: #testFlatCollect" |
65 "self debug: #testFlatCollect" |
66 |
66 |
67 |
67 |
68 ! |
68 ! |
69 |
69 |
70 testFlatCollectArray |
70 testFlatCollectArray |
71 "self debug: #testFlatCollectArray" |
71 "self debug: #testFlatCollectArray" |
72 |
72 |
73 self assert: ((#((1 2) (3 4) (5 3)) flatCollect: [ :each | each ]) = #(1 2 3 4 5 3)). |
73 self assert: ((#((1 2) (3 4) (5 3)) flatCollect: [ :each | each ]) = #(1 2 3 4 5 3)). |
74 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each | each]) = #(1 2 2 3 1 3 4)). |
74 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each | each]) = #(1 2 2 3 1 3 4)). |
75 |
75 |
76 self assert: ((#((1 2) (2 3) () ()) flatCollect: [:each | each]) = #(1 2 2 3)). |
76 self assert: ((#((1 2) (2 3) () ()) flatCollect: [:each | each]) = #(1 2 2 3)). |
77 |
77 |
78 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each| Array with: each]) |
78 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each| Array with: each]) |
79 = #(#(1 2) #(2 3) #(1 3 4))). |
79 = #(#(1 2) #(2 3) #(1 3 4))). |
80 |
80 |
81 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each| Set with: each]) |
81 self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each| Set with: each]) |
82 = #(#(1 2) #(2 3) #(1 3 4))). |
82 = #(#(1 2) #(2 3) #(1 3 4))). |
83 |
83 |
84 ! |
84 ! |
85 |
85 |
86 testFlatCollectSet |
86 testFlatCollectSet |
87 "self debug: #testFlatCollectSet" |
87 "self debug: #testFlatCollectSet" |
88 |
88 |
89 self assert: ((#((1 2) (1 2) (1 3 4)) asSet flatCollect: [:each | each]) = #(1 1 2 3 4) asSet). |
89 self assert: ((#((1 2) (1 2) (1 3 4)) asSet flatCollect: [:each | each]) = #(1 1 2 3 4) asSet). |
90 self assert: ((#() asSet flatCollect: [:each]) = #() asSet). |
90 self assert: ((#((1)) asSet flatCollect: [:each | each]) = #() asSet). |
91 |
91 |
92 self assert: ((#((1 2) () (1 3 4)) asSet flatCollect: [:each | each]) = #(1 1 2 3 4) asSet). |
92 self assert: ((#((1 2) () (1 3 4)) asSet flatCollect: [:each | each]) = #(1 1 2 3 4) asSet). |
93 self assert: ((#((1 2) #((99)) (1 3 4)) asSet flatCollect: [:each | each]) |
93 self assert: ((#((1 2) #((99)) (1 3 4)) asSet flatCollect: [:each | each]) |
94 = #(1 1 2 3 4 (99)) asSet). |
94 = #(1 1 2 3 4 (99)) asSet). |
95 self assert: ((#((1 2) #(()) (1 3 4)) asSet flatCollect: [:each | each]) |
95 self assert: ((#((1 2) #(()) (1 3 4)) asSet flatCollect: [:each | each]) |
96 = #(1 1 2 3 4 ()) asSet). |
96 = #(1 1 2 3 4 ()) asSet). |
97 ! ! |
97 ! ! |
98 |
98 |
99 !CECollectionExtensionTest methodsFor:'flatten'! |
99 !CECollectionExtensionTest methodsFor:'flatten'! |
100 |
100 |
142 |
142 |
143 !CECollectionExtensionTest methodsFor:'groupedBy'! |
143 !CECollectionExtensionTest methodsFor:'groupedBy'! |
144 |
144 |
145 testGroupedBy |
145 testGroupedBy |
146 "self debug: #testGroupedBy" |
146 "self debug: #testGroupedBy" |
147 |
147 |
148 | res | |
148 | res | |
149 res := #(1 2 3 4 5) asOrderedCollection |
149 res := #(1 2 3 4 5) asOrderedCollection |
150 groupedBy: [:each | each odd]. |
150 groupedBy: [:each | each odd]. |
151 self assert: (res at: true) = #(1 3 5) asOrderedCollection. |
151 self assert: (res at: true) = #(1 3 5) asOrderedCollection. |
152 self assert: (res at: false) = #(2 4) asOrderedCollection |
152 self assert: (res at: false) = #(2 4) asOrderedCollection |
153 ! |
153 ! |
154 |
154 |
155 testGroupedByArray |
155 testGroupedByArray |
156 "self debug: #testGroupedByArray" |
156 "self debug: #testGroupedByArray" |
157 |
157 |
158 | res | |
158 | res | |
159 res := #(1 2 3 4 5) groupedBy: [:each | each odd]. |
159 res := #(1 2 3 4 5) groupedBy: [:each | each odd]. |
160 self assert: (res at: true) = #(1 3 5). |
160 self assert: (res at: true) = #(1 3 5). |
161 self assert: (res at: false) = #(2 4) |
161 self assert: (res at: false) = #(2 4) |
162 ! |
162 ! |
163 |
163 |
164 testGroupedBySet |
164 testGroupedBySet |
165 "self debug: #testGroupedBySet" |
165 "self debug: #testGroupedBySet" |
166 |
166 |
167 | res | |
167 | res | |
168 res := #(1 2 3 4 5 3 4 5) asSet groupedBy: [:each | each odd]. |
168 res := #(1 2 3 4 5 3 4 5) asSet groupedBy: [:each | each odd]. |
169 self assert: (res at: true) = #(1 3 5) asSet. |
169 self assert: (res at: true) = #(1 3 5) asSet. |
170 self assert: (res at: false) = #(2 4) asSet |
170 self assert: (res at: false) = #(2 4) asSet |
171 ! ! |
171 ! ! |
172 |
172 |
173 !CECollectionExtensionTest methodsFor:'symbol - value'! |
173 !CECollectionExtensionTest methodsFor:'symbol - value'! |
174 |
174 |
175 testSymbolInPlaceOfBlock |
175 testSymbolInPlaceOfBlock |
176 "self debug: #testSymbolInPlaceOfBlock" |
176 "self debug: #testSymbolInPlaceOfBlock" |
177 |
177 |
178 self assert: (#(1 2 3 4) collect: #odd) = #(true false true false). |
178 self assert: (#(1 2 3 4) collect: #odd) = #(true false true false). |
179 self assert: (#(1 2 3 4) select: #odd) = #(1 3). |
179 self assert: (#(1 2 3 4) select: #odd) = #(1 3). |
180 ! ! |
180 ! ! |
181 |
181 |
182 !CECollectionExtensionTest class methodsFor:'documentation'! |
182 !CECollectionExtensionTest class methodsFor:'documentation'! |