-
Notifications
You must be signed in to change notification settings - Fork 1
/
lazy_coll_test.go
54 lines (42 loc) · 1.03 KB
/
lazy_coll_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gg_test
import (
"testing"
"github.com/mitranim/gg"
"github.com/mitranim/gg/gtest"
)
func TestLazyColl(t *testing.T) {
defer gtest.Catch(t)
testColl[*gg.LazyColl[SomeKey, SomeModel]]()
}
func TestLazyCollOf(t *testing.T) {
defer gtest.Catch(t)
gtest.Zero(gg.LazyCollOf[SomeKey, SomeModel]())
testLazyCollMake(func(src ...SomeModel) SomeLazyColl {
return gg.LazyCollOf[SomeKey, SomeModel](src...)
})
}
func testLazyCollMake[Coll AnyColl](fun func(...SomeModel) Coll) {
test := func(slice []SomeModel, index map[SomeKey]int) {
tar := fun(slice...)
testCollEqual(tar, SomeColl{Slice: slice, Index: index})
gtest.Is(getCollSlice(tar), slice)
}
test(
[]SomeModel{SomeModel{10, `one`}},
nil,
)
test(
[]SomeModel{
SomeModel{10, `one`},
SomeModel{20, `two`},
},
nil,
)
}
func TestLazyCollFrom(t *testing.T) {
defer gtest.Catch(t)
gtest.Zero(gg.LazyCollFrom[SomeKey, SomeModel, []SomeModel]())
testLazyCollMake(func(src ...SomeModel) SomeLazyColl {
return gg.LazyCollFrom[SomeKey, SomeModel](src)
})
}