-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult_test.go
96 lines (91 loc) · 2.31 KB
/
result_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package crud
import (
"strconv"
"testing"
)
func genRowsMap(field string, args ...int) *RowsMap {
rm := RowsMap{}
for _, v := range args {
rm = append(rm, RowMap{field: strconv.Itoa(v)})
}
return &rm
}
func checkMap(rma, rmb RowsMap, field string) bool {
for i := 0; i < len(rma); i++ {
if rma[i][field] != rmb[i][field] {
return false
}
}
return true
}
func TestRowsMap_SortFunc(t *testing.T) {
type args struct {
f func(RowsMap, int, int) bool
}
tests := []struct {
name string
rm *RowsMap
args args
}{
{"001", genRowsMap("id", 74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586), args{func(rm RowsMap, i, j int) bool {
return rm[i].Int("id") > rm[j].Int("id")
}}},
}
for _, tt := range tests {
tt.rm.SortFunc(tt.args.f)
for i := 0; i < len(*tt.rm)-1; i++ {
if (*tt.rm)[i].Int("id") < (*tt.rm)[i+1].Int("id") {
t.Fatal("rows map order wrong:", tt.rm)
}
}
}
}
func TestRowsMap_MultiWarpByField(t *testing.T) {
type args struct {
fields []string
}
tests := []struct {
name string
rm RowsMap
args args
want []MultiWarp
}{
// TODO: Add test cases.
{"1", RowsMap{
RowMap{"bid": "1", "bname": "电", "sid": "1", "sname": "灯不亮", "gid": "1", "gname": "待整理"},
RowMap{"bid": "1", "bname": "电", "sid": "2", "sname": "灯松脱"},
RowMap{"bid": "2", "bname": "水", "sid": "3", "sname": "没水"},
RowMap{"bid": "2", "bname": "水", "sid": "4", "sname": "漏水"},
}, args{fields: []string{"bid", "bname", "sid", "sname", "gid", "gname"}}, []MultiWarp{
MultiWarp{
ID: "1",
Name: "电",
Vals: []MultiWarp{
MultiWarp{ID: "1", Name: "灯不亮", Vals: []MultiWarp{
MultiWarp{
ID: "1",
Name: "待整理",
Vals: []MultiWarp{},
},
}},
MultiWarp{ID: "2", Name: "灯松脱", Vals: []MultiWarp{}},
},
},
MultiWarp{
ID: "2",
Name: "水",
Vals: []MultiWarp{
MultiWarp{ID: "3", Name: "没水", Vals: []MultiWarp{}},
MultiWarp{ID: "4", Name: "漏水", Vals: []MultiWarp{}},
},
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.rm.MultiWarpByField(tt.args.fields...); stringify(got) != stringify(tt.want) {
t.Errorf("RowsMap.MultiWarpByField() = %v, want %v", stringify(got), stringify(tt.want))
}
})
}
}