forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pskpdpt_test.go
81 lines (77 loc) · 1.82 KB
/
pskpdpt_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
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPSKPDPT(t *testing.T) {
var testcases = []struct {
name string
raw string
err string
msg PSKPDPT
}{
{
name: "good sentence, empty location",
raw: "$PSKPDPT,0002.5,+00.0,0010,10,03,*77",
msg: PSKPDPT{
Depth: 2.5,
Offset: 0,
RangeScale: 10,
BottomEchoStrength: 10,
ChannelNumber: 03,
TransducerLocation: "",
},
},
{
name: "good sentence",
raw: "$PSKPDPT,0002.5,-01.1,0010,10,03,AFT*22",
msg: PSKPDPT{
Depth: 2.5,
Offset: -1.1,
RangeScale: 10,
BottomEchoStrength: 10,
ChannelNumber: 03,
TransducerLocation: "AFT",
},
},
{
name: "invalid nmea: Depth",
raw: "$PSKPDPT,x0002.5,+00.0,0010,10,03,*0f",
err: "nmea: PSKPDPT invalid depth: x0002.5",
},
{
name: "invalid nmea: Offset",
raw: "$PSKPDPT,0002.5,+x00.0,0010,10,03,*0f",
err: "nmea: PSKPDPT invalid offset: +x00.0",
},
{
name: "invalid nmea: RangeScale",
raw: "$PSKPDPT,0002.5,+00.0,x0010,10,03,*0f",
err: "nmea: PSKPDPT invalid range scale: x0010",
},
{
name: "invalid nmea: BottomEchoStrength",
raw: "$PSKPDPT,0002.5,+00.0,0010,10x,03,*0f",
err: "nmea: PSKPDPT invalid bottom echo strength: 10x",
},
{
name: "invalid nmea: ChannelNumber",
raw: "$PSKPDPT,0002.5,+00.0,0010,10,0x3,*0f",
err: "nmea: PSKPDPT invalid channel number: 0x3",
},
}
for _, tt := range testcases {
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)
sentence := m.(PSKPDPT)
sentence.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, sentence)
}
})
}
}