70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package aprs
|
|
|
|
import "testing"
|
|
|
|
func TestParseQuery(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
Raw Raw
|
|
Want *Query
|
|
}{
|
|
{
|
|
"general query",
|
|
"?APRS?",
|
|
&Query{
|
|
Type: "APRS",
|
|
},
|
|
},
|
|
{
|
|
"general query for stations within a target footprint of radius 200 miles",
|
|
"?APRS? 34.02,-117.15,0200",
|
|
&Query{
|
|
Type: "APRS",
|
|
Latitude: 34.02,
|
|
Longitude: -117.15,
|
|
Radius: milesToMeters(200),
|
|
},
|
|
},
|
|
}
|
|
|
|
var decoder queryDecoder
|
|
for _, test := range tests {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
frame := &Frame{Raw: test.Raw}
|
|
if !decoder.CanDecode(frame) {
|
|
t.Fatalf("%T can't decode %q", decoder, test.Raw)
|
|
}
|
|
|
|
v, err := decoder.Decode(frame)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
testCompareQuery(t, test.Want, v)
|
|
})
|
|
}
|
|
}
|
|
|
|
func testCompareQuery(t *testing.T, want *Query, value any) {
|
|
t.Helper()
|
|
|
|
test, ok := value.(*Query)
|
|
if !ok {
|
|
t.Fatalf("expected data to be a %T, got %T", want, value)
|
|
return
|
|
}
|
|
|
|
if test.Type != want.Type {
|
|
t.Errorf("expected type %q, got %q", want.Type, test.Type)
|
|
}
|
|
if !testAlmostEqual(test.Latitude, want.Latitude) {
|
|
t.Errorf("expected latitude %f, got %f", want.Latitude, test.Latitude)
|
|
}
|
|
if !testAlmostEqual(test.Longitude, want.Longitude) {
|
|
t.Errorf("expected longitude %f, got %f", want.Longitude, test.Longitude)
|
|
}
|
|
if !testAlmostEqual(test.Radius, want.Radius) {
|
|
t.Errorf("expected radius %f, got %f", want.Radius, test.Radius)
|
|
}
|
|
}
|