forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gngga_test.go
69 lines (65 loc) · 1.55 KB
/
gngga_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
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var gnggatests = []struct {
name string
raw string
err string
msg GNGGA
}{
{
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: GNGGA{
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",
},
}
func TestGNGGA(t *testing.T) {
for _, tt := range gnggatests {
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)
gngga := m.(GNGGA)
gngga.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, gngga)
}
})
}
}