Add the core, contest, storage and format layers

Frequencies, bands, modes, callsigns, grid squares and the country file live in
Nonemm.Core. Nonemm.Contests holds the scoring engine and CQ WW and CQ WPX.
Nonemm.Storage writes N1MM's DXLOG schema, and Nonemm.Formats writes Cabrillo
3.0 and reads and writes ADIF.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik
2026-08-27 10:27:51 +00:00
commit 0f84bc8972
68 changed files with 3823 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
using Nonemm.Contests.Rules;
using Nonemm.Core;
namespace Nonemm.Contests.Tests;
public class CqWorldWideTests
{
private static ContestLog LogFor(StationInfo me) =>
new(new CqWorldWide(ModeCategory.Cw), me, TestLog.CountryFile);
[Fact]
public void ContactWithOwnCountryScoresNothing()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(0, log.Judge(TestLog.Contact("DL9XYZ", zone: 14)).Points);
}
[Fact]
public void SameContinentDifferentCountryScoresOne()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(1, log.Judge(TestLog.Contact("IK2XYZ", zone: 15)).Points);
}
[Fact]
public void DifferentContinentScoresThree()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(3, log.Judge(TestLog.Contact("JA1XYZ", zone: 25)).Points);
}
[Fact]
public void NorthAmericansScoreTwoWithinNorthAmerica()
{
ContestLog log = LogFor(TestLog.UnitedStates);
Assert.Equal(2, log.Judge(TestLog.Contact("VE3XYZ", zone: 5)).Points);
}
[Fact]
public void OwnCountryStillCountsAsAMultiplier()
{
ContestLog log = LogFor(TestLog.Germany);
Verdict verdict = log.Judge(TestLog.Contact("DL9XYZ", zone: 14));
Assert.Equal(2, verdict.NewMultipliers.Count);
Assert.Equal(0, verdict.Points);
}
[Fact]
public void ZoneAndCountryCountOncePerBand()
{
ContestLog log = LogFor(TestLog.Germany);
log.Add(TestLog.Contact("JA1XYZ", zone: 25));
Assert.Empty(log.Judge(TestLog.Contact("JA2XYZ", zone: 25)).NewMultipliers);
Assert.Equal(2, log.Judge(TestLog.Contact("JA2XYZ", 21_025, zone: 25)).NewMultipliers.Count);
}
[Fact]
public void SameStationOnAnotherBandIsNotADupe()
{
ContestLog log = LogFor(TestLog.Germany);
log.Add(TestLog.Contact("JA1XYZ", zone: 25));
Assert.True(log.Judge(TestLog.Contact("JA1XYZ", zone: 25)).IsDupe);
Assert.False(log.Judge(TestLog.Contact("JA1XYZ", 21_025, zone: 25)).IsDupe);
}
[Fact]
public void ScoreIsPointsTimesMultipliers()
{
ContestLog log = LogFor(TestLog.Germany);
log.Add(TestLog.Contact("JA1XYZ", zone: 25));
log.Add(TestLog.Contact("PY2XYZ", zone: 11));
Assert.Equal(6, log.Tally.Points);
Assert.Equal(4, log.Tally.TotalMultipliers);
Assert.Equal(24, log.TotalScore);
}
[Fact]
public void RemovingAContactHandsItsMultiplierToTheNextOne()
{
ContestLog log = LogFor(TestLog.Germany);
Qso first = log.Add(TestLog.Contact("JA1XYZ", zone: 25, at: new DateTime(2026, 5, 30, 12, 0, 0, DateTimeKind.Utc)));
log.Add(TestLog.Contact("JA2XYZ", zone: 25, at: new DateTime(2026, 5, 30, 12, 1, 0, DateTimeKind.Utc)));
log.Remove(first.Id);
Assert.True(log.Qsos.Single().IsMultiplier1);
Assert.Equal(2, log.Tally.TotalMultipliers);
}
}

View File

@@ -0,0 +1,69 @@
using Nonemm.Contests.Rules;
using Nonemm.Core;
namespace Nonemm.Contests.Tests;
public class CqWpxTests
{
private static ContestLog LogFor(StationInfo me, ModeCategory mode = ModeCategory.Cw) =>
new(new CqWpx(mode), me, TestLog.CountryFile);
[Theory]
[InlineData(14_025, 3)]
[InlineData(21_025, 3)]
[InlineData(7_025, 6)]
[InlineData(3_525, 6)]
public void DifferentContinentDoublesBelowFourteenMegahertz(double kilohertz, int expected)
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(expected, log.Judge(TestLog.Contact("JA1XYZ", kilohertz)).Points);
}
[Fact]
public void SameContinentScoresOneOnTheHighBands()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(1, log.Judge(TestLog.Contact("IK2XYZ")).Points);
Assert.Equal(2, log.Judge(TestLog.Contact("IK2XYZ", 7_025)).Points);
}
[Fact]
public void NorthAmericansScoreDoubleWithinNorthAmerica()
{
ContestLog log = LogFor(TestLog.UnitedStates);
Assert.Equal(2, log.Judge(TestLog.Contact("VE3XYZ")).Points);
Assert.Equal(4, log.Judge(TestLog.Contact("VE3XYZ", 7_025)).Points);
}
[Fact]
public void OwnCountryScoresOneOnEveryBand()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Equal(1, log.Judge(TestLog.Contact("DL9XYZ")).Points);
Assert.Equal(1, log.Judge(TestLog.Contact("DL9XYZ", 3_525)).Points);
}
[Fact]
public void RttyScoresOwnCountryTwiceOnTheLowBands()
{
ContestLog log = LogFor(TestLog.Germany, ModeCategory.Digital);
Assert.Equal(1, log.Judge(TestLog.Contact("DL9XYZ", mode: Modes.Rtty)).Points);
Assert.Equal(2, log.Judge(TestLog.Contact("DL9XYZ", 3_525, Modes.Rtty)).Points);
}
[Fact]
public void PrefixCountsOnceForTheWholeContest()
{
ContestLog log = LogFor(TestLog.Germany);
log.Add(TestLog.Contact("JA1XYZ"));
Assert.Empty(log.Judge(TestLog.Contact("JA1ZZZ", 7_025)).NewMultipliers);
Assert.Single(log.Judge(TestLog.Contact("JA2ZZZ", 7_025)).NewMultipliers);
}
[Fact]
public void MaritimeMobileBringsNoPrefix()
{
ContestLog log = LogFor(TestLog.Germany);
Assert.Empty(log.Judge(TestLog.Contact("DL1ABC/MM")).NewMultipliers);
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Nonemm.Contests\Nonemm.Contests.csproj" />
<ProjectReference Include="..\..\src\Nonemm.Core\Nonemm.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,69 @@
using Nonemm.Core;
using Nonemm.Core.Country;
namespace Nonemm.Contests.Tests;
/// A country file and QSO builder small enough to read, so a scoring test says
/// what it is testing rather than how to build a contact.
public static class TestLog
{
public const string Countries = """
Germany: 14: 28: EU: 51.00: -10.00: -1.0: DL:
DA,DB,DC,DD,DE,DF,DG,DH,DJ,DK,DL,DM,DO,DP,DQ,DR;
Italy: 15: 28: EU: 42.83: -12.83: -1.0: I:
I,IK,IZ;
United States: 05: 08: NA: 37.60: 91.87: 5.0: K:
K,W,N,AA,K6(3)[6];
Canada: 05: 09: NA: 44.35: 78.75: 5.0: VE:
VE,VA;
Japan: 25: 45: AS: 36.40: -138.38: -9.0: JA:
JA,JH,JR,7K;
Brazil: 11: 15: SA: -10.00: 55.00: 3.0: PY:
PY,PP;
""";
public static readonly CountryFile CountryFile = CountryFile.Parse(Countries);
public static readonly StationInfo Germany = new()
{
Callsign = "DL1ABC",
CqZone = 14,
ItuZone = 28,
Continent = "EU",
CountryPrefix = "DL",
};
public static readonly StationInfo UnitedStates = new()
{
Callsign = "K1ABC",
CqZone = 5,
ItuZone = 8,
Continent = "NA",
CountryPrefix = "K",
State = "CT",
ArrlSection = "CT",
};
public static Qso Contact(
string call,
double kilohertz = 14_025,
Mode? mode = null,
int zone = 0,
int number = 0,
string exchange = "",
string section = "",
DateTime? at = null) =>
new()
{
Id = Qso.NewId(),
TimestampUtc = at ?? new DateTime(2026, 5, 30, 12, 0, 0, DateTimeKind.Utc),
Call = Callsign.Parse(call),
Frequency = Frequency.FromKilohertz(kilohertz),
Mode = mode ?? Modes.Cw,
ContestName = "TEST",
Zone = zone,
ReceivedNumber = number,
Exchange1 = exchange,
Section = section,
};
}