up
This commit is contained in:
@@ -96,6 +96,38 @@ func TestComputeMultiRef(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// WAJA-style award: MatchBy="description", non-exact, scanning the QTH for a
|
||||
// reference's NAME (the prefecture). Also guards against the nil-slice crash:
|
||||
// an award with nothing worked must return empty (non-nil) Refs/Bands.
|
||||
func TestComputeMatchByDescription(t *testing.T) {
|
||||
def := Def{Code: "WAJA", Type: TypeQSOFields, Field: "qth", MatchBy: "description",
|
||||
DXCCFilter: []int{339}, Confirm: []string{"lotw", "qsl"}, Valid: true}
|
||||
qsos := []qso.QSO{
|
||||
{Callsign: "JA1ABC", Band: "20m", DXCC: ip(339), QTH: "Tokyo city", LOTWRcvd: "Y"},
|
||||
{Callsign: "JA3DEF", Band: "40m", DXCC: ip(339), QTH: "Osaka"},
|
||||
{Callsign: "JA9XYZ", Band: "20m", DXCC: ip(339), QTH: "nowhere special"}, // no prefecture name
|
||||
}
|
||||
refMetas := map[string][]RefMeta{"WAJA": {
|
||||
{Code: "100", Name: "Tokyo", Valid: true},
|
||||
{Code: "270", Name: "Osaka", Valid: true},
|
||||
{Code: "010", Name: "Hokkaido", Valid: true},
|
||||
}}
|
||||
r := Compute([]Def{def}, qsos, refMetas, nil)[0]
|
||||
if r.Worked != 2 { // Tokyo + Osaka found by name inside QTH
|
||||
t.Errorf("WAJA worked = %d, want 2 (%v)", r.Worked, refCodes(r))
|
||||
}
|
||||
if r.Total != 3 { // predefined denominator = list size
|
||||
t.Errorf("WAJA total = %d, want 3", r.Total)
|
||||
}
|
||||
|
||||
// Nil-slice guard: an award with zero worked refs must still return
|
||||
// non-nil (empty) Refs/Bands so the JSON isn't null (UI white-screen).
|
||||
empty := Compute([]Def{{Code: "WWFF", Type: TypeReference, Field: "wwff", Dynamic: true, Valid: true}}, nil, nil, nil)[0]
|
||||
if empty.Refs == nil || empty.Bands == nil {
|
||||
t.Errorf("empty award must have non-nil Refs/Bands, got Refs=%v Bands=%v", empty.Refs, empty.Bands)
|
||||
}
|
||||
}
|
||||
|
||||
func refCodes(r Result) []string {
|
||||
out := make([]string, 0, len(r.Refs))
|
||||
for _, rf := range r.Refs {
|
||||
|
||||
Reference in New Issue
Block a user