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
|
package nmea
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestVWR(t *testing.T) {
var tests = []struct {
name string
raw string
err string
msg VWR
}{
{ // these examples are from SignalK
name: "good sentence",
raw: "$IIVWR,75,R,1.0,N,0.51,M,1.85,K*6C",
msg: VWR{
MeasuredAngle: 75,
MeasuredDirectionBow: Right,
SpeedKnots: 1,
SpeedKnotsUnit: SpeedKnots,
SpeedMPS: 0.51,
SpeedMPSUnit: SpeedMeterPerSecond,
SpeedKPH: 1.85,
SpeedKPHUnit: SpeedKilometerPerHour,
},
},
{
name: "good sentence, shorter but still valid",
raw: "$IIVWR,024,L,018,N,,,,*5e",
msg: VWR{
MeasuredAngle: 24,
MeasuredDirectionBow: Left,
SpeedKnots: 18,
SpeedKnotsUnit: SpeedKnots,
SpeedMPS: 0,
SpeedMPSUnit: "",
SpeedKPH: 0,
SpeedKPHUnit: "",
},
},
{
name: "good sentence, handle empty values",
raw: "$IIVWR,,,,,,,,*53",
msg: VWR{
MeasuredAngle: 0,
MeasuredDirectionBow: "",
SpeedKnots: 0,
SpeedKnotsUnit: "",
SpeedMPS: 0,
SpeedMPSUnit: "",
SpeedKPH: 0,
SpeedKPHUnit: "",
},
},
{
name: "invalid nmea: DirectionBow",
raw: "$IIVWR,75,x,1.0,N,0.51,M,1.85,K*46",
err: "nmea: IIVWR invalid measured wind direction to bow: x",
},
{
name: "invalid nmea: SpeedKnotsUnit",
raw: "$IIVWR,75,R,1.0,x,0.51,M,1.85,K*5a",
err: "nmea: IIVWR invalid wind speed in knots unit: x",
},
{
name: "invalid nmea: SpeedMPSUnit",
raw: "$IIVWR,75,R,1.0,N,0.51,x,1.85,K*59",
err: "nmea: IIVWR invalid wind speed in meters per second unit: x",
},
{
name: "invalid nmea: SpeedKPHUnit",
raw: "$IIVWR,75,R,1.0,N,0.51,M,1.85,x*5f",
err: "nmea: IIVWR invalid wind speed in kilometers per hour unit: x",
},
}
for _, tt := range tests {
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)
vwr := m.(VWR)
vwr.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, vwr)
}
})
}
}
|