-
Notifications
You must be signed in to change notification settings - Fork 80
/
hdg_test.go
66 lines (64 loc) · 1.37 KB
/
hdg_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
package nmea
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestHDG(t *testing.T) {
var tests = []struct {
name string
raw string
err string
msg HDG
}{
{
name: "good sentence",
raw: "$HCHDG,98.3,0.1,E,12.6,W*56",
msg: HDG{
Heading: 98.3,
Deviation: 0.1,
DeviationDirection: East,
Variation: 12.6,
VariationDirection: West,
},
},
{
name: "invalid Heading",
raw: "$HCHDG,X,0.1,E,12.6,W*12",
err: "nmea: HCHDG invalid heading: X",
},
{
name: "invalid Deviation",
raw: "$HCHDG,98.3,x.1,E,12.6,W*1E",
err: "nmea: HCHDG invalid deviation: x.1",
},
{
name: "invalid DeviationDirection",
raw: "$HCHDG,98.3,0.1,X,12.6,W*4B",
err: "nmea: HCHDG invalid deviation direction: X",
},
{
name: "invalid Variation",
raw: "$HCHDG,98.3,0.1,E,x.1,W*2A",
err: "nmea: HCHDG invalid variation: x.1",
},
{
name: "invalid VariationDirection",
raw: "$HCHDG,98.3,0.1,E,12.6,X*59",
err: "nmea: HCHDG invalid variation direction: X",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m, err := Parse(tt.raw)
if tt.err != "" {
assert.Error(t, err)
assert.EqualError(t, err, tt.err)
} else {
assert.NoError(t, err)
hdg := m.(HDG)
hdg.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, hdg)
}
})
}
}