protocol/aprs: refactored
This commit is contained in:
130
protocol/aprs/mice_test.go
Normal file
130
protocol/aprs/mice_test.go
Normal file
@@ -0,0 +1,130 @@
|
||||
package aprs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPositionMicE(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string
|
||||
Frame string
|
||||
Want *MicE
|
||||
}{
|
||||
{
|
||||
"position",
|
||||
"N0CALL>S32U6T:`(_f \"Oj/",
|
||||
&MicE{
|
||||
Latitude: 33.427333,
|
||||
Longitude: 13.129000,
|
||||
Symbol: "/j",
|
||||
Velocity: &Velocity{Course: 251, Speed: 20.57777776},
|
||||
},
|
||||
},
|
||||
{
|
||||
"position with altitude",
|
||||
"N0CALL>S32U6T:`(_f \"Oj/\"4T}",
|
||||
&MicE{
|
||||
Latitude: 33.427333,
|
||||
Longitude: 13.129000,
|
||||
Altitude: feetToMeters(61),
|
||||
Symbol: "/j",
|
||||
Velocity: &Velocity{Course: 251, Speed: 20.57777776},
|
||||
},
|
||||
},
|
||||
{
|
||||
"position with telemetry",
|
||||
"N0CALL>S32U6T:`(_f \"Oj/>|\\'s%0\\'c|",
|
||||
&MicE{
|
||||
Latitude: 33.427333,
|
||||
Longitude: 13.129000,
|
||||
Symbol: "/j",
|
||||
Velocity: &Velocity{Course: 251, Speed: 20.57777776},
|
||||
Telemetry: &Telemetry{ID: 5375, Analog: []int{7466, 1424, 612}},
|
||||
},
|
||||
},
|
||||
/*
|
||||
{
|
||||
"gridsquare position with comment",
|
||||
"NOCALL>S32U6T:IO91SX/G Hello world",
|
||||
&Position{
|
||||
Latitude: 33.427333,
|
||||
Longitude: -12.129,
|
||||
Symbol: "/G",
|
||||
Comment: "Hello world",
|
||||
},
|
||||
},
|
||||
*/
|
||||
}
|
||||
|
||||
var decoder micEDecoder
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
frame, err := Parse(test.Frame)
|
||||
if err != nil {
|
||||
t.Fatalf("can't parse %q: %v", test.Frame, err)
|
||||
}
|
||||
if !decoder.CanDecode(frame) {
|
||||
t.Fatalf("%T can't decode %q", decoder, test.Frame)
|
||||
}
|
||||
|
||||
v, err := decoder.Decode(frame)
|
||||
if err != nil {
|
||||
t.Fatalf("can't decode %q: %v", test.Frame, err)
|
||||
}
|
||||
|
||||
testCompareMicE(t, test.Want, v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testCompareMicE(t *testing.T, want *MicE, value any) {
|
||||
t.Helper()
|
||||
|
||||
p, ok := value.(*MicE)
|
||||
if !ok {
|
||||
t.Fatalf("expected data to be a %T, got %T", want, value)
|
||||
return
|
||||
}
|
||||
|
||||
if p.HasMessaging != want.HasMessaging {
|
||||
t.Errorf("expected to have messaging: %t, got %t", want.HasMessaging, p.HasMessaging)
|
||||
}
|
||||
|
||||
if !testAlmostEqual(p.Latitude, want.Latitude) {
|
||||
t.Errorf("expected latitude %f, got %f", want.Latitude, p.Latitude)
|
||||
}
|
||||
if !testAlmostEqual(p.Longitude, want.Longitude) {
|
||||
t.Errorf("expected longitude %f, got %f", want.Longitude, p.Longitude)
|
||||
}
|
||||
if !testAlmostEqual(p.Altitude, want.Altitude) {
|
||||
t.Errorf("expected altitude %f, got %f", want.Altitude, p.Altitude)
|
||||
}
|
||||
|
||||
if p.Symbol != want.Symbol {
|
||||
t.Errorf("expected symbol %q, got %q", want.Symbol, p.Symbol)
|
||||
}
|
||||
if p.Comment != want.Comment {
|
||||
t.Errorf("expected comment %q, got %q", want.Comment, p.Comment)
|
||||
}
|
||||
|
||||
if want.Velocity != nil {
|
||||
if p.Velocity == nil {
|
||||
t.Errorf("expected velocity, got none")
|
||||
} else if !reflect.DeepEqual(p.Velocity, want.Velocity) {
|
||||
t.Errorf("expected velocity %#+v, got %#+v", want.Velocity, p.Velocity)
|
||||
}
|
||||
} else if p.Velocity != nil {
|
||||
t.Errorf("expected no velocity, got %#+v", p.Velocity)
|
||||
}
|
||||
|
||||
if want.Telemetry != nil {
|
||||
if p.Telemetry == nil {
|
||||
t.Errorf("expected telemetry, got none")
|
||||
} else if !reflect.DeepEqual(p.Telemetry, want.Telemetry) {
|
||||
t.Errorf("expected telemetry %#+v, got %#+v", want.Telemetry, p.Telemetry)
|
||||
}
|
||||
} else if p.Telemetry != nil {
|
||||
t.Errorf("expected no telemetry, got %#+v", p.Telemetry)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user