forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gprmc_test.go
65 lines (61 loc) · 1.39 KB
/
gprmc_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
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var gprmctests = []struct {
name string
raw string
err string
msg GPRMC
}{
{
name: "good sentence A",
raw: "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70",
msg: GPRMC{
Time: Time{true, 22, 5, 16, 0},
Validity: "A",
Speed: 173.8,
Course: 231.8,
Date: Date{true, 13, 6, 94},
Variation: -4.2,
Latitude: MustParseGPS("5133.82 N"),
Longitude: MustParseGPS("00042.24 W"),
},
},
{
name: "good sentence B",
raw: "$GPRMC,142754.0,A,4302.539570,N,07920.379823,W,0.0,,070617,0.0,E,A*3F",
msg: GPRMC{
Time: Time{true, 14, 27, 54, 0},
Validity: "A",
Speed: 0,
Course: 0,
Date: Date{true, 7, 6, 17},
Variation: 0,
Latitude: MustParseGPS("4302.539570 N"),
Longitude: MustParseGPS("07920.379823 W"),
},
},
{
name: "bad validity",
raw: "$GPRMC,220516,D,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*75",
err: "nmea: GPRMC invalid validity: D",
},
}
func TestGPRMC(t *testing.T) {
for _, tt := range gprmctests {
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)
gprmc := m.(GPRMC)
gprmc.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, gprmc)
}
})
}
}