forked from HVelosoETI/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ths_test.go
82 lines (78 loc) · 1.37 KB
/
ths_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
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var thstests = []struct {
name string
raw string
err string
msg THS
}{
{
name: "good sentence AutonomousTHS",
raw: "$INTHS,123.456,A*20",
msg: THS{
Heading: 123.456,
Status: AutonomousTHS,
},
},
{
name: "good sentence EstimatedTHS",
raw: "$INTHS,123.456,E*24",
msg: THS{
Heading: 123.456,
Status: EstimatedTHS,
},
},
{
name: "good sentence ManualTHS",
raw: "$INTHS,123.456,M*2C",
msg: THS{
Heading: 123.456,
Status: ManualTHS,
},
},
{
name: "good sentence SimulatorTHS",
raw: "$INTHS,123.456,S*32",
msg: THS{
Heading: 123.456,
Status: SimulatorTHS,
},
},
{
name: "good sentence InvalidTHS",
raw: "$INTHS,,V*1E",
msg: THS{
Heading: 0.0,
Status: InvalidTHS,
},
},
{
name: "invalid Status",
raw: "$INTHS,123.456,B*23",
err: "nmea: INTHS invalid status: B",
},
{
name: "invalid Heading",
raw: "$INTHS,XXX,A*51",
err: "nmea: INTHS invalid heading: XXX",
},
}
func TestTHS(t *testing.T) {
for _, tt := range thstests {
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)
ths := m.(THS)
ths.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, ths)
}
})
}
}