forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gga_test.go
100 lines (96 loc) · 2.5 KB
/
gga_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
93
94
95
96
97
98
99
100
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var ggatests = []struct {
name string
raw string
err string
msg GGA
}{
{
name: "good sentence",
raw: "$GNGGA,203415.000,6325.6138,N,01021.4290,E,1,8,2.42,72.5,M,41.5,M,,*7C",
msg: GGA{
Time: Time{
Valid: true,
Hour: 20,
Minute: 34,
Second: 15,
Millisecond: 0,
},
Latitude: MustParseLatLong("6325.6138 N"),
Longitude: MustParseLatLong("01021.4290 E"),
FixQuality: "1",
NumSatellites: 8,
HDOP: 2.42,
Altitude: 72.5,
Separation: 41.5,
DGPSAge: "",
DGPSId: "",
},
},
{
name: "bad latitude",
raw: "$GNGGA,034225.077,A,S,15124.5567,E,1,03,9.7,-25.0,M,21.0,M,,0000*24",
err: "nmea: GNGGA invalid latitude: cannot parse [A S], unknown format",
},
{
name: "bad longitude",
raw: "$GNGGA,034225.077,3356.4650,S,A,E,1,03,9.7,-25.0,M,21.0,M,,0000*12",
err: "nmea: GNGGA invalid longitude: cannot parse [A E], unknown format",
},
{
name: "bad fix quality",
raw: "$GNGGA,034225.077,3356.4650,S,15124.5567,E,12,03,9.7,-25.0,M,21.0,M,,0000*7D",
err: "nmea: GNGGA invalid fix quality: 12",
},
{
name: "good sentence",
raw: "$GPGGA,034225.077,3356.4650,S,15124.5567,E,1,03,9.7,-25.0,M,21.0,M,,0000*51",
msg: GGA{
Time: Time{true, 3, 42, 25, 77},
Latitude: MustParseLatLong("3356.4650 S"),
Longitude: MustParseLatLong("15124.5567 E"),
FixQuality: GPS,
NumSatellites: 03,
HDOP: 9.7,
Altitude: -25.0,
Separation: 21.0,
DGPSAge: "",
DGPSId: "0000",
},
},
{
name: "bad latitude",
raw: "$GPGGA,034225.077,A,S,15124.5567,E,1,03,9.7,-25.0,M,21.0,M,,0000*3A",
err: "nmea: GPGGA invalid latitude: cannot parse [A S], unknown format",
},
{
name: "bad longitude",
raw: "$GPGGA,034225.077,3356.4650,S,A,E,1,03,9.7,-25.0,M,21.0,M,,0000*0C",
err: "nmea: GPGGA invalid longitude: cannot parse [A E], unknown format",
},
{
name: "bad fix quality",
raw: "$GPGGA,034225.077,3356.4650,S,15124.5567,E,12,03,9.7,-25.0,M,21.0,M,,0000*63",
err: "nmea: GPGGA invalid fix quality: 12",
},
}
func TestGGA(t *testing.T) {
for _, tt := range ggatests {
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)
gga := m.(GGA)
gga.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, gga)
}
})
}
}