Files
ham/protocol/aprs/mice_test.go
maze 63040a44b3
Some checks failed
Run tests / test (1.25) (push) Failing after 1m37s
Run tests / test (stable) (push) Failing after 1m37s
protocol/aprs: refactored
2026-03-02 22:28:17 +01:00

131 lines
3.1 KiB
Go

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)
}
}