-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutils_test.go
52 lines (42 loc) · 1.53 KB
/
utils_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
package datatable_test
import (
"testing"
"github.com/datasweet/datatable"
"github.com/stretchr/testify/assert"
)
// checkTable to check if a table contains cells
func checkTable(t *testing.T, tb *datatable.DataTable, cells ...interface{}) {
ncols := tb.NumCols()
nrows := tb.NumRows()
assert.Len(t, cells, ncols*(nrows+1)) // + headers
cols := tb.Columns()
rows := tb.Rows()
for i, v := range cells {
r := i/ncols - 1
c := i % ncols
if r == -1 {
assert.Equal(t, v, cols[c], "HEADER COL #%d", r, c)
continue
}
assert.Equal(t, v, rows[r][cols[c]], "ROW #%d, COL #%d", r, c)
}
}
func New(t *testing.T) *datatable.DataTable {
tb := datatable.New("test")
tb.AddColumn("champ", datatable.String, datatable.Values("Malzahar", "Xerath", "Teemo"))
tb.AddColumn("champion", datatable.String, datatable.Expr("upper(`champ`)"))
tb.AddColumn("win", datatable.Int, datatable.Values(10, 20, 666))
tb.AddColumn("loose", datatable.Int, datatable.Values(6, 5, 666))
tb.AddColumn("winRate", datatable.String, datatable.Expr("(`win` * 100 / (`win` + `loose`)) ~ \" %\""))
tb.AddColumn("sum", datatable.Float64, datatable.Expr("sum(`win`)"))
tb.AddColumn("ok", datatable.Bool, datatable.Expr("true"))
tb.AddColumn("hidden", datatable.Bool, datatable.Expr("false"))
tb.HideColumn("hidden")
checkTable(t, tb,
"champ", "champion", "win", "loose", "winRate", "sum", "ok",
"Malzahar", "MALZAHAR", 10, 6, "62.5 %", 696.0, true,
"Xerath", "XERATH", 20, 5, "80 %", 696.0, true,
"Teemo", "TEEMO", 666, 666, "50 %", 696.0, true,
)
return tb
}