Files
Nonemm/tests/Nonemm.Contests.Tests/UserDefinedContestTests.cs
T
erikbrockoandClaude Opus 5 bae40bb04e Show the boxes N1MM shows for each contest
The entry window had a fixed set of boxes with a Name and Comment box beside
the exchange. N1MM lays out one row of boxes per contest and nothing else, so
this does the same: general logging keeps Name and Comment, and a contest gets
the boxes it exchanges.

Two new members on `Contest` carry the cases where the boxes and the log
columns are not the same list:

- `FromExchange1` spreads what was typed in one box across the log columns.
  Where the other station sends a serial or a district code depending on where
  it is, N1MM gives it one box and sorts the value into the number, section or
  zone column from there, so the score and the Cabrillo file read it from the
  same column N1MM does.
- `LogFieldsFor` gives the log window its own column list. Sweepstakes takes
  the whole exchange in one box and logs it in four columns; `SweepstakesExchange`
  parses `72 A 74 SCV` in any order, reading from the last word back as N1MM
  does.

The sent serial is now marked as not required and space steps over it along
with the two report boxes, because nobody types the number going out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015NZkFxHde1iifAQemFTHxf
2026-09-09 20:12:37 +00:00

115 lines
3.8 KiB
C#

using Nonemm.Contests.Udc;
using Nonemm.Core;
namespace Nonemm.Contests.Tests;
public class UserDefinedContestTests
{
private const string Sample = """
[Author]
AuthorName=Someone
[Contest]
Name=SAMPLETEST
DisplayName=Sample Test
CabrilloName=SAMPLE-TEST
Mode=CW
DupeType=2
Multiplier1Name=Countries
MultSqlString=CountryPrefix
IsMultPer=1
PointsPerContact=MyCountry, 1, SameContinent, 2, OtherContinent, 5
EntryWindowInfo=RCVText, 500, Exchange1Text, 500
FrameText=RcvRST Exch
DefaultContestExchange=599
""";
private static UserDefinedContest Contest() => new(UdcFile.Parse(Sample));
private static ContestLog LogFor(StationInfo me) =>
new(Contest(), me, TestLog.CountryFile);
[Fact]
public void NameAndCabrilloNameComeFromTheFile()
{
UserDefinedContest contest = Contest();
Assert.Equal("SAMPLETEST", contest.Name);
Assert.Equal("Sample Test", contest.DisplayName);
Assert.Equal("SAMPLE-TEST", contest.CabrilloName);
}
[Fact]
public void ExchangeBoxesComeFromTheEntryWindowSetting()
{
IReadOnlyList<ExchangeField> fields = Contest().ExchangeFieldsFor(TestLog.Germany);
Assert.Equal(2, fields.Count);
Assert.Equal("RcvRST", fields[0].Label);
Assert.Equal(ExchangeSlot.Exchange1, fields[1].Slot);
}
[Theory]
[InlineData("DL9XYZ", 1)]
[InlineData("IK2XYZ", 2)]
[InlineData("JA1XYZ", 5)]
public void PointsFollowTheConditionList(string call, int expected) =>
Assert.Equal(expected, LogFor(TestLog.Germany).Judge(TestLog.Contact(call)).Points);
[Fact]
public void CountriesCountOncePerBand()
{
ContestLog log = LogFor(TestLog.Germany);
log.Add(TestLog.Contact("JA1XYZ"));
Assert.Empty(log.Judge(TestLog.Contact("JA2XYZ")).NewMultipliers);
Assert.Single(log.Judge(TestLog.Contact("JA2XYZ", 7_025)).NewMultipliers);
}
[Fact]
public void FileWithNoContestNameIsRejected() =>
Assert.Throws<FormatException>(() => UdcFile.Parse("[Author]\r\nAuthorName=Someone\r\n"));
[Fact]
public void DupeTypeFourNeverFlagsADupe()
{
UserDefinedContest contest = new(UdcFile.Parse(Sample.Replace("DupeType=2", "DupeType=4")));
ContestLog log = new(contest, TestLog.Germany, TestLog.CountryFile);
log.Add(TestLog.Contact("JA1XYZ"));
Assert.False(log.Judge(TestLog.Contact("JA1XYZ")).IsDupe);
}
/// The box names in a published file are N1MM's `LogItemNameType` members.
[Fact]
public void TheZoneStateAndPowerBoxesAreRead()
{
UserDefinedContest contest = new(UdcFile.Parse("""
[Contest]
Name=BOXTEST
EntryWindowInfo=RCVText, 400, CQZoneText, 300, SectionText, 300, PowerText, 300
FrameText=RST Zone Sect Pwr
"""));
Assert.Equal(
[ExchangeSlot.ReceivedReport, ExchangeSlot.Zone, ExchangeSlot.Section, ExchangeSlot.Power],
contest.ExchangeFieldsFor(TestLog.Germany).Select(f => f.Slot).ToList());
}
/// The sent-side boxes are in the same setting and are not exchange boxes.
[Fact]
public void TheSentBoxesAreBoxesOfTheirOwn()
{
UserDefinedContest contest = new(UdcFile.Parse("""
[Contest]
Name=SENTTEST
EntryWindowInfo=SNTText, 400, SntNrText, 300, RCVText, 400, RcvNrText, 300
FrameText=Snt SntNr RST Nr
"""));
Assert.Equal(
[
ExchangeSlot.SentReport,
ExchangeSlot.SentNumber,
ExchangeSlot.ReceivedReport,
ExchangeSlot.SerialNumber,
],
contest.ExchangeFieldsFor(TestLog.Germany).Select(f => f.Slot).ToList());
}
}