@@ -12,27 +12,54 @@ import (
1212
1313var _ = Describe ("Utils Tests" , func () {
1414
15- Context ("ProjectSlice " , func () {
15+ Context ("ProjectSliceToSlice " , func () {
1616
1717 projectFunc := func (i int ) int {
1818 return i * 2
1919 }
2020
2121 It ("should use the projection function on each element of the slice" , func () {
2222 src := []int {1 , 2 , 3 , 4 }
23- projected := collections .ProjectSlice (src , projectFunc )
23+ projected := collections .ProjectSliceToSlice (src , projectFunc )
2424 Expect (projected ).To (Equal ([]int {2 , 4 , 6 , 8 }))
2525 Expect (src ).To (Equal ([]int {1 , 2 , 3 , 4 }), "original slice should not be modified" )
2626 })
2727
2828 It ("should return an empty slice for an empty or nil input slice" , func () {
29- Expect (collections .ProjectSlice (nil , projectFunc )).To (BeEmpty ())
30- Expect (collections .ProjectSlice ([]int {}, projectFunc )).To (BeEmpty ())
29+ Expect (collections .ProjectSliceToSlice (nil , projectFunc )).To (BeEmpty ())
30+ Expect (collections .ProjectSliceToSlice ([]int {}, projectFunc )).To (BeEmpty ())
3131 })
3232
3333 It ("should return nil for a nil projection function" , func () {
3434 src := []int {1 , 2 , 3 , 4 }
35- projected := collections .ProjectSlice [int , int ](src , nil )
35+ projected := collections .ProjectSliceToSlice [int , int ](src , nil )
36+ Expect (projected ).To (BeNil ())
37+ Expect (src ).To (Equal ([]int {1 , 2 , 3 , 4 }), "original slice should not be modified" )
38+ })
39+
40+ })
41+
42+ Context ("ProjectSliceToMap" , func () {
43+
44+ projectFunc := func (i int ) (int , int ) {
45+ return i , i * 2
46+ }
47+
48+ It ("should use the projection function on each element of the slice" , func () {
49+ src := []int {1 , 2 , 3 , 4 }
50+ projected := collections .ProjectSliceToMap (src , projectFunc )
51+ Expect (projected ).To (Equal (map [int ]int {1 : 2 , 2 : 4 , 3 : 6 , 4 : 8 }))
52+ Expect (src ).To (Equal ([]int {1 , 2 , 3 , 4 }), "original slice should not be modified" )
53+ })
54+
55+ It ("should return an empty slice for an empty or nil input slice" , func () {
56+ Expect (collections .ProjectSliceToMap (nil , projectFunc )).To (BeEmpty ())
57+ Expect (collections .ProjectSliceToMap ([]int {}, projectFunc )).To (BeEmpty ())
58+ })
59+
60+ It ("should return nil for a nil projection function" , func () {
61+ src := []int {1 , 2 , 3 , 4 }
62+ projected := collections .ProjectSliceToMap [int , int , int ](src , nil )
3663 Expect (projected ).To (BeNil ())
3764 Expect (src ).To (Equal ([]int {1 , 2 , 3 , 4 }), "original slice should not be modified" )
3865 })
0 commit comments