using Nonemm.Contests.Rules; using Nonemm.Core; namespace Nonemm.Contests.Tests; public class ScoreBreakdownTests { private static readonly Contest Contest = new CqWorldWide(ModeCategory.Cw); private static Qso Scored(string call, double kilohertz, Mode mode, int points, bool zone = false, bool country = false) => TestLog.Contact(call, kilohertz, mode) with { Points = points, IsMultiplier1 = zone, IsMultiplier2 = country, }; [Fact] public void Rows_are_ordered_by_the_band_as_text_then_by_mode_and_the_total_is_last() { List log = [ Scored("DL1AAA", 3_525, Modes.Cw, 1), Scored("DL1BBB", 10_120, Modes.Cw, 1), Scored("DL1CCC", 14_025, Modes.Cw, 1), Scored("DL1DDD", 14_200, Modes.Usb, 1), Scored("DL1EEE", 1_830, Modes.Cw, 1), ]; IReadOnlyList rows = ScoreBreakdown.For(log, Contest); Assert.Equal( [(1.8, "CW"), (10.0, "CW"), (14.0, "CW"), (14.0, "USB"), (3.5, "CW"), (ScoreBreakdown.TotalBand, "Both")], rows.Select(r => (r.Band, r.Mode))); } [Fact] public void A_row_adds_up_contacts_points_and_multiplier_flags() { List log = [ Scored("DL1AAA", 14_025, Modes.Cw, 3, zone: true, country: true), Scored("DL1BBB", 14_030, Modes.Cw, 3, country: true), Scored("DL1CCC", 7_010, Modes.Cw, 3, zone: true), ]; ScoreBreakdownRow twenty = ScoreBreakdown.For(log, Contest).Single(r => r.Band == 14.0); ScoreBreakdownRow total = ScoreBreakdown.For(log, Contest).Last(); Assert.Equal((2, 6, 1, 2, 0), (twenty.Qsos, twenty.Points, twenty.Multipliers[0], twenty.Multipliers[1], twenty.Multipliers[2])); Assert.Equal((3, 9, 2, 2), (total.Qsos, total.Points, total.Multipliers[0], total.Multipliers[1])); } [Fact] public void A_dupe_and_an_unclaimed_contact_are_not_counted() { List log = [ Scored("DL1AAA", 14_025, Modes.Cw, 3), Scored("DL1AAA", 14_026, Modes.Cw, 0) with { ContactType = "D" }, Scored("DL1BBB", 14_027, Modes.Cw, 3) with { IsClaimed = false }, ]; Assert.Equal(1, ScoreBreakdown.For(log, Contest).Last().Qsos); } [Fact] public void An_empty_log_has_no_rows_not_even_a_total() { Assert.Empty(ScoreBreakdown.For([], Contest)); } }