-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathparse_bias_test.go
More file actions
66 lines (62 loc) · 1.12 KB
/
parse_bias_test.go
File metadata and controls
66 lines (62 loc) · 1.12 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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseBias(t *testing.T) {
examples := []struct {
name string
input string
output []float64
err string
}{
{
"happy case",
"0=1,1=2.5",
[]float64{1, 2.5},
"",
},
{
"bad format",
"bad",
nil,
"not a valid bias declaration: bad",
},
{
"bad pair",
"0=1, bad",
nil,
"not a valid bias declaration: bad",
},
{
"bad index",
"bad=0.5",
nil,
"failed to parse bias index: strconv.Atoi: parsing \"bad\": invalid syntax",
},
{
"bad time",
"0=bad",
nil,
"failed to parse bias time: strconv.ParseFloat: parsing \"bad\": invalid syntax",
},
{
"index out of range",
"3=0.5",
nil,
"bias index is not within the split number: 3",
},
}
for _, example := range examples {
t.Run(example.name, func(t *testing.T) {
output, err := parseBias(example.input, 2)
if example.err != "" {
require.EqualError(t, err, example.err)
} else {
require.NoError(t, err)
assert.Equal(t, example.output, output)
}
})
}
}