package cluster import "testing" func TestParseSpot(t *testing.T) { cases := []struct { line string wantCall string wantKHz float64 wantBand string wantLoc string }{ { `DX de DK0SWL: 14195.5 W1AW CQ Field Day 1745Z`, "W1AW", 14195.5, "20m", "", }, { `DX de F4XYZ-#: 7074.0 3DA0RU FT8 -10 0823Z JN18`, "3DA0RU", 7074.0, "40m", "JN18", }, { `DX de N1MM: 14010.0 K1JT 599 NJ 1234Z FN20`, "K1JT", 14010.0, "20m", "FN20", }, { `DX de YO3JW 3573.0 EA1ABC CQ 2010Z IN73`, "EA1ABC", 3573.0, "80m", "IN73", }, } for _, c := range cases { s, ok := parseSpot(c.line) if !ok { t.Errorf("%q: parse failed", c.line) continue } if s.DXCall != c.wantCall { t.Errorf("%q: call=%q want %q", c.line, s.DXCall, c.wantCall) } if s.FreqKHz != c.wantKHz { t.Errorf("%q: kHz=%v want %v", c.line, s.FreqKHz, c.wantKHz) } if s.Band != c.wantBand { t.Errorf("%q: band=%q want %q", c.line, s.Band, c.wantBand) } if s.Locator != c.wantLoc { t.Errorf("%q: loc=%q want %q", c.line, s.Locator, c.wantLoc) } } } func TestParseSpotRejectsNoise(t *testing.T) { noise := []string{ "Welcome to DXCluster", "login:", "WX bulletin from G4ABC: heavy rain", "To ALL de F1XYZ: anyone using XYZ contest log?", "", "sh/dx 10", } for _, line := range noise { if _, ok := parseSpot(line); ok { t.Errorf("noise line parsed as spot: %q", line) } } }