package pskrme import ( "testing" "time" ) // One station uploading every five minutes must be ONE pair of ears on the map, // showing its freshest report — not four arcs to the same square, and not the // oldest of them deciding whether the path still looks open. func TestReportsKeepsTheFreshestPerStation(t *testing.T) { w := New(Config{MyCall: "F4BPO"}) now := time.Now() w.reports = []Report{ {Call: "OH5CX", Grid: "KP30", SNR: -18, At: now.Add(-9 * time.Minute)}, {Call: "W1AW", Grid: "FN31", SNR: -5, At: now.Add(-2 * time.Minute)}, {Call: "OH5CX", Grid: "KP30", SNR: -11, At: now.Add(-1 * time.Minute)}, } got := w.Reports() if len(got) != 2 { t.Fatalf("got %d stations, want 2: %+v", len(got), got) } for _, r := range got { if r.Call == "OH5CX" && r.SNR != -11 { t.Errorf("OH5CX kept the %d dB report, want the freshest (-11)", r.SNR) } } } // A report older than the window is gone, and gone from the slice too: the map // must not show a path that stopped existing a quarter of an hour ago, and the // window is what keeps this from growing all evening. func TestReportsDropsWhatIsPastTheWindow(t *testing.T) { w := New(Config{MyCall: "F4BPO"}) now := time.Now() w.reports = []Report{ {Call: "OLD", Grid: "JN36", At: now.Add(-Window - time.Minute)}, {Call: "NEW", Grid: "JN36", At: now.Add(-time.Minute)}, } got := w.Reports() if len(got) != 1 || got[0].Call != "NEW" { t.Fatalf("got %+v, want only NEW", got) } if len(w.reports) != 1 { t.Errorf("the stale report is still held: %d kept", len(w.reports)) } } // Turning the feed off clears what it collected. Left in place, switching it // back on would redraw a map of who heard us before it was on. func TestStopForgetsTheReports(t *testing.T) { w := New(Config{MyCall: "F4BPO"}) w.reports = []Report{{Call: "OH5CX", Grid: "KP30", At: time.Now()}} w.Stop() if got := w.Reports(); len(got) != 0 { t.Errorf("got %+v after Stop, want nothing", got) } } // No callsign, no subscription: the transmit level would be a wildcard, which // is the entire feed — the one thing this package exists not to ask for. func TestStartRefusesWithoutACallsign(t *testing.T) { if err := New(Config{}).Start(); err == nil { t.Fatal("started with no callsign") } }