-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtable_test.go
62 lines (54 loc) · 842 Bytes
/
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
61
62
package simpletable
import "testing"
func TestNew(t *testing.T) {
tbl := New()
if tbl == nil {
t.Error("Table must not be empty")
}
}
func TestTable_Carve(t *testing.T) {
type Test struct {
Value int
Parts int
Result []int
}
s := []*Test{
{
Value: 5,
Parts: 3,
Result: []int{2, 2, 1},
},
{
Value: 7,
Parts: 2,
Result: []int{4, 3},
},
{
Value: 6,
Parts: 3,
Result: []int{2, 2, 2},
},
{
Value: 1,
Parts: 3,
Result: []int{1, 0, 0},
},
}
tbl := New()
for _, x := range s {
if !tableTestSlicesEqual(tbl.carve(x.Value, x.Parts), x.Result) {
t.Error("Wrong column sizes calculation")
}
}
}
func tableTestSlicesEqual(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}