-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbowdiff_test.go
More file actions
94 lines (81 loc) · 2.57 KB
/
bowdiff_test.go
File metadata and controls
94 lines (81 loc) · 2.57 KB
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
package bow
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDiff(t *testing.T) {
t.Run("all columns all supported types with nils and metadata", func(t *testing.T) {
b, err := NewBowWithMetadata(NewMetadata([]string{"k"}, []string{"v"}),
NewSeries("a", Int64,
[]int64{1, 2, 3, 4, 0, 5},
[]bool{true, true, true, true, false, true}),
NewSeries("b", Float64,
[]float64{1., 2., 3., 4., 0., 5.},
[]bool{true, true, true, true, false, true}),
NewSeries("c", Boolean,
[]bool{false, false, true, true, false, false},
[]bool{true, true, true, true, false, true}),
)
require.NoError(t, err)
expected, err := NewBowWithMetadata(NewMetadata([]string{"k"}, []string{"v"}),
NewSeries("a", Int64,
[]int64{0, 1, 1, 1, 0, 0},
[]bool{false, true, true, true, false, false}),
NewSeries("b", Float64,
[]float64{0., 1., 1., 1., 0., 0.},
[]bool{false, true, true, true, false, false}),
NewSeries("c", Boolean,
[]bool{false, false, true, false, false, false},
[]bool{false, true, true, true, false, false}),
)
require.NoError(t, err)
calc, err := b.Diff()
assert.NoError(t, err)
assert.EqualValues(t, expected.String(), calc.String())
})
t.Run("one column all supported types", func(t *testing.T) {
b, err := NewBowFromRowBasedInterfaces(
[]string{"a", "b", "c"},
[]Type{Int64, Float64, Boolean},
[][]interface{}{
{1, 1., false},
{2, 2., false},
{3, 3., true},
})
require.NoError(t, err)
expected, err := NewBowFromRowBasedInterfaces(
[]string{"a", "b", "c"},
[]Type{Int64, Float64, Boolean},
[][]interface{}{
{1, nil, false},
{2, 1., false},
{3, 1., true},
})
require.NoError(t, err)
calc, err := b.Diff(1)
assert.NoError(t, err)
assert.EqualValues(t, expected.String(), calc.String())
})
t.Run("unsupported type string", func(t *testing.T) {
b, err := NewBowFromRowBasedInterfaces([]string{"a"}, []Type{String}, [][]interface{}{})
require.NoError(t, err)
calc, err := b.Diff()
assert.Error(t, err)
assert.Nil(t, calc)
})
t.Run("empty", func(t *testing.T) {
b, err := NewBowFromRowBasedInterfaces([]string{"a"}, []Type{Int64}, [][]interface{}{})
require.NoError(t, err)
calc, err := b.Diff()
assert.NoError(t, err)
assert.EqualValues(t, b.String(), calc.String())
})
t.Run("missing column", func(t *testing.T) {
b, err := NewBowFromRowBasedInterfaces([]string{"a"}, []Type{Int64}, [][]interface{}{})
require.NoError(t, err)
calc, err := b.Diff(1)
assert.Error(t, err)
assert.Nil(t, calc)
})
}