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:
61
tests/Nonemm.Formats.Tests/AdifTests.cs
Normal file
61
tests/Nonemm.Formats.Tests/AdifTests.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Formats.Adif;
|
||||
|
||||
namespace Nonemm.Formats.Tests;
|
||||
|
||||
public class AdifTests
|
||||
{
|
||||
private static readonly StationInfo Me = new() { Callsign = "DL1ABC" };
|
||||
|
||||
private static Qso Contact() => new()
|
||||
{
|
||||
Id = Qso.NewId(),
|
||||
TimestampUtc = new DateTime(2026, 5, 30, 12, 34, 56, DateTimeKind.Utc),
|
||||
Call = Callsign.Parse("JA1XYZ"),
|
||||
Frequency = Frequency.FromKilohertz(14_025),
|
||||
Mode = Modes.Cw,
|
||||
ContestName = "CQWW",
|
||||
SentReport = "599",
|
||||
ReceivedReport = "579",
|
||||
Zone = 25,
|
||||
ReceivedNumber = 34,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ContactSurvivesAWriteAndRead()
|
||||
{
|
||||
string text = new AdifWriter(Me).Write([Contact()]);
|
||||
Qso read = AdifReader.Read(text).Single();
|
||||
|
||||
Assert.Equal("JA1XYZ", read.Call.Text);
|
||||
Assert.Equal(new DateTime(2026, 5, 30, 12, 34, 56, DateTimeKind.Utc), read.TimestampUtc);
|
||||
Assert.Equal(14_025_000, read.Frequency.Hertz);
|
||||
Assert.Equal(Modes.Cw, read.Mode);
|
||||
Assert.Equal("579", read.ReceivedReport);
|
||||
Assert.Equal(25, read.Zone);
|
||||
Assert.Equal(34, read.ReceivedNumber);
|
||||
Assert.Equal("CQWW", read.ContestName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HeaderIsSkipped()
|
||||
{
|
||||
const string text = "Exported by something\r\n<ADIF_VER:5>3.1.4 <EOH>\r\n" +
|
||||
"<CALL:6>JA1XYZ <QSO_DATE:8>20260530 <TIME_ON:6>123456 <MODE:2>CW <EOR>";
|
||||
Assert.Equal("JA1XYZ", AdifReader.Read(text).Single().Call.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordWithNoCallIsDropped()
|
||||
{
|
||||
const string text = "<EOH>\r\n<QSO_DATE:8>20260530 <EOR>\r\n<CALL:6>JA1XYZ <EOR>";
|
||||
Assert.Single(AdifReader.Read(text));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BandStandsInWhenThereIsNoFrequency()
|
||||
{
|
||||
const string text = "<EOH>\r\n<CALL:6>JA1XYZ <BAND:3>20m <EOR>";
|
||||
Assert.Equal(Bands.Band20M, AdifReader.Read(text).Single().Band);
|
||||
}
|
||||
}
|
||||
83
tests/Nonemm.Formats.Tests/CabrilloWriterTests.cs
Normal file
83
tests/Nonemm.Formats.Tests/CabrilloWriterTests.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Nonemm.Contests.Rules;
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Formats.Cabrillo;
|
||||
|
||||
namespace Nonemm.Formats.Tests;
|
||||
|
||||
public class CabrilloWriterTests
|
||||
{
|
||||
private static readonly StationInfo Me = new()
|
||||
{
|
||||
Callsign = "DL1ABC",
|
||||
CqZone = 14,
|
||||
Continent = "EU",
|
||||
CountryPrefix = "DL",
|
||||
};
|
||||
|
||||
private static Qso Contact(double kilohertz = 14_025, Mode? mode = null) => new()
|
||||
{
|
||||
Id = Qso.NewId(),
|
||||
TimestampUtc = new DateTime(2026, 5, 30, 12, 34, 56, DateTimeKind.Utc),
|
||||
Call = Callsign.Parse("JA1XYZ"),
|
||||
Frequency = Frequency.FromKilohertz(kilohertz),
|
||||
Mode = mode ?? Modes.Cw,
|
||||
ContestName = "CQWW",
|
||||
SentReport = "599",
|
||||
ReceivedReport = "599",
|
||||
Zone = 25,
|
||||
SentNumber = 12,
|
||||
ReceivedNumber = 34,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void QsoLineCarriesBothExchanges()
|
||||
{
|
||||
CabrilloWriter writer = new(new CqWorldWide(ModeCategory.Cw), Me);
|
||||
string line = writer.QsoLine(Contact());
|
||||
Assert.StartsWith("QSO: 14025 CW 2026-05-30 1234 DL1ABC", line);
|
||||
Assert.Contains("JA1XYZ", line);
|
||||
Assert.EndsWith("0", line);
|
||||
Assert.Contains(" 14 ", line);
|
||||
Assert.Contains(" 25 ", line);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WpxNumbersArePaddedToFour()
|
||||
{
|
||||
CabrilloWriter writer = new(new CqWpx(ModeCategory.Cw), Me);
|
||||
string line = writer.QsoLine(Contact());
|
||||
Assert.Contains("0012", line);
|
||||
Assert.Contains("0034", line);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VhfContactsUseTheBandDesignator()
|
||||
{
|
||||
CabrilloWriter writer = new(new CqWorldWide(ModeCategory.Cw), Me);
|
||||
Assert.Contains(" 144 ", writer.QsoLine(Contact(144_200)));
|
||||
Assert.Contains(" 1.2G ", writer.QsoLine(Contact(1_296_100)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HeaderAndFooterWrapTheContacts()
|
||||
{
|
||||
CabrilloWriter writer = new(new CqWorldWide(ModeCategory.Cw), Me);
|
||||
string log = writer.Write(
|
||||
new CabrilloHeader { Contest = "CQ-WW-CW", Callsign = "DL1ABC", ClaimedScore = 1234 },
|
||||
[Contact()]);
|
||||
Assert.StartsWith("START-OF-LOG: 3.0\r\n", log);
|
||||
Assert.Contains("CONTEST: CQ-WW-CW\r\n", log);
|
||||
Assert.Contains("CLAIMED-SCORE: 1234\r\n", log);
|
||||
Assert.EndsWith("END-OF-LOG:\r\n", log);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContactsLeftOutOfTheClaimedScoreAreNotSent()
|
||||
{
|
||||
CabrilloWriter writer = new(new CqWorldWide(ModeCategory.Cw), Me);
|
||||
string log = writer.Write(
|
||||
new CabrilloHeader { Contest = "CQ-WW-CW", Callsign = "DL1ABC" },
|
||||
[Contact() with { IsClaimed = false }]);
|
||||
Assert.DoesNotContain("QSO:", log);
|
||||
}
|
||||
}
|
||||
27
tests/Nonemm.Formats.Tests/Nonemm.Formats.Tests.csproj
Normal file
27
tests/Nonemm.Formats.Tests/Nonemm.Formats.Tests.csproj
Normal file
@@ -0,0 +1,27 @@
|
||||
<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.Formats\Nonemm.Formats.csproj" />
|
||||
<ProjectReference Include="..\..\src\Nonemm.Core\Nonemm.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\Nonemm.Contests\Nonemm.Contests.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user