-
Notifications
You must be signed in to change notification settings - Fork 79
/
apb_test.go
92 lines (90 loc) · 2.62 KB
/
apb_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
83
84
85
86
87
88
89
90
91
92
package nmea
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestAPB(t *testing.T) {
var tests = []struct {
name string
raw string
err string
msg APB
}{
{
name: "good sentence",
raw: "$GPAPB,A,A,0.10,R,N,V,V,011,M,DEST,011,M,011,M*3C",
msg: APB{
StatusGeneralWarning: "A",
StatusLockWarning: "A",
CrossTrackErrorMagnitude: 0.1,
DirectionToSteer: "R",
CrossTrackUnits: "N",
StatusArrivalCircleEntered: "V",
StatusPerpendicularPassed: "V",
BearingOriginToDest: 11,
BearingOriginToDestType: "M",
DestinationWaypointID: "DEST",
BearingPresentToDest: 11,
BearingPresentToDestType: "M",
Heading: 11,
HeadingType: "M",
FFAMode: "",
},
},
{
name: "good sentence b with FAA mode",
raw: "$ECAPB,A,A,0.0,L,M,V,V,175.2,T,Antechamber_Bay,175.2,T,175.2,T,V*32",
msg: APB{
StatusGeneralWarning: "A",
StatusLockWarning: "A",
CrossTrackErrorMagnitude: 0,
DirectionToSteer: "L",
CrossTrackUnits: "M",
StatusArrivalCircleEntered: "V",
StatusPerpendicularPassed: "V",
BearingOriginToDest: 175.2,
BearingOriginToDestType: "T",
DestinationWaypointID: "Antechamber_Bay",
BearingPresentToDest: 175.2,
BearingPresentToDestType: "T",
Heading: 175.2,
HeadingType: "T",
FFAMode: "V",
},
},
{
name: "invalid nmea: CrossTrackErrorMagnitude",
raw: "$ECAPB,A,A,x.0,L,M,V,V,175.2,T,Antechamber_Bay,175.2,T,175.2,T,V*7A",
err: "nmea: ECAPB invalid cross track error magnitude: x.0",
},
{
name: "invalid nmea: BearingOriginToDest",
raw: "$ECAPB,A,A,0.0,L,M,V,V,175.x,T,Antechamber_Bay,175.2,T,175.2,T,V*78",
err: "nmea: ECAPB invalid origin bearing to destination: 175.x",
},
{
name: "invalid nmea: BearingPresentToDest",
raw: "$ECAPB,A,A,0.0,L,M,V,V,175.2,T,Antechamber_Bay,175.x,T,175.2,T,V*78",
err: "nmea: ECAPB invalid present bearing to destination: 175.x",
},
{
name: "invalid nmea: Heading",
raw: "$ECAPB,A,A,0.0,L,M,V,V,175.2,T,Antechamber_Bay,175.2,T,175.x,T,V*78",
err: "nmea: ECAPB invalid heading: 175.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)
apb := m.(APB)
apb.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, apb)
}
})
}
}