-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_test.go
60 lines (55 loc) · 1.63 KB
/
table_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
55
56
57
58
59
60
package data
import (
"go4ml.xyz/lazy"
"gotest.tools/v3/assert"
"testing"
)
func Test1_TableFromChannel(t *testing.T) {
c := make(chan Color)
go func() {
for _, x := range colors {
c <- x
}
close(c)
}()
var x Table
lazy.Chan(c).Map1(StructToRow).MustDrain(x.Sink())
assert.Assert(t, x.Len() == len(colors))
for i, v := range colors {
assert.Assert(t, x.Col("Color").At(i).String() == v.Color)
assert.Assert(t, x.Col("Index").At(i).Int() == v.Index)
assert.Assert(t, x.Row(i).String() == structToRowString(v))
}
}
func Test1_TableFromList(t *testing.T) {
var x Table
lazy.List(colors).Map1(StructToRow).MustDrain(x.Sink())
assert.Assert(t, x.Len() == len(colors))
for i, v := range colors {
assert.Assert(t, x.Col("Color").At(i).String() == v.Color)
assert.Assert(t, x.Col("Index").At(i).Int() == v.Index)
assert.Assert(t, x.Row(i).String() == structToRowString(v))
}
}
func Test2_TableFromList(t *testing.T) {
var x Table
lazy.List(colors).Map1(StructToRow).MustDrain(x.Sink())
assert.Assert(t, x.Len() == len(colors))
for i, v := range colors {
assert.Assert(t, x.Col("Color").At(i).String() == v.Color)
assert.Assert(t, x.Col("Index").At(i).Int() == v.Index)
assert.Assert(t, x.Row(i).String() == structToRowString(v))
}
}
func Test1_ConcurrentTableSink(t *testing.T) {
var x Table
lazy.List(colors_N).
Map1(StructToRow).
MustDrain(x.Sink(), 8)
assert.Assert(t, x.Len() == len(colors_N))
for i, v := range colors_N {
//fmt.Println(x.Row(i), x.Col("Color").At(i).String(), v.Color)
assert.Assert(t, x.Col("Color").At(i).String() == v.Color)
assert.Assert(t, x.Col("Index").At(i).Int() == v.Index)
}
}