forked from HVelosoETI/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmc_test.go
112 lines (108 loc) · 2.6 KB
/
rmc_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
101
102
103
104
105
106
107
108
109
110
111
112
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var rmctests = []struct {
name string
raw string
err string
msg RMC
}{
{
name: "good sentence A",
raw: "$GNRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*6E",
msg: RMC{
Time: Time{true, 22, 05, 16, 0},
Validity: "A",
Speed: 173.8,
Course: 231.8,
Date: Date{true, 13, 06, 94},
Variation: -4.2,
Latitude: MustParseGPS("5133.82 N"),
Longitude: MustParseGPS("00042.24 W"),
},
},
{
name: "good sentence B",
raw: "$GNRMC,142754.0,A,4302.539570,N,07920.379823,W,0.0,,070617,0.0,E,A*21",
msg: RMC{
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: "good sentence C",
raw: "$GNRMC,100538.00,A,5546.27711,N,03736.91144,E,0.061,,260318,,,A*60",
msg: RMC{
Time: Time{true, 10, 5, 38, 0},
Validity: "A",
Speed: 0.061,
Course: 0,
Date: Date{true, 26, 3, 18},
Variation: 0,
Latitude: MustParseGPS("5546.27711 N"),
Longitude: MustParseGPS("03736.91144 E"),
},
},
{
name: "bad sentence",
raw: "$GNRMC,220516,D,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*6B",
err: "nmea: GNRMC invalid validity: D",
},
{
name: "good sentence A",
raw: "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70",
msg: RMC{
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: RMC{
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 TestRMC(t *testing.T) {
for _, tt := range rmctests {
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)
rmc := m.(RMC)
rmc.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, rmc)
}
})
}
}