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:
@@ -0,0 +1,34 @@
|
||||
using Nonemm.Core;
|
||||
|
||||
namespace Nonemm.Core.Tests;
|
||||
|
||||
public class BandsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1830, "160M")]
|
||||
[InlineData(3510.5, "80M")]
|
||||
[InlineData(14025, "20M")]
|
||||
[InlineData(28499, "10M")]
|
||||
[InlineData(50110, "6M")]
|
||||
[InlineData(144200, "2M")]
|
||||
public void FrequencyLandsOnItsBand(double kilohertz, string expected) =>
|
||||
Assert.Equal(expected, Bands.ForFrequency(Frequency.FromKilohertz(kilohertz))?.Name);
|
||||
|
||||
[Fact]
|
||||
public void FrequencyOutsideEveryAllocationHasNoBand() =>
|
||||
Assert.Null(Bands.ForFrequency(Frequency.FromKilohertz(12000)));
|
||||
|
||||
[Fact]
|
||||
public void BandEdgesAreIncluded()
|
||||
{
|
||||
Assert.Equal("20M", Bands.ForFrequency(Frequency.FromKilohertz(14000))?.Name);
|
||||
Assert.Equal("20M", Bands.ForFrequency(Frequency.FromKilohertz(14350))?.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1.8, "160M")]
|
||||
[InlineData(5, "60M")]
|
||||
[InlineData(76000, "4MM")]
|
||||
public void N1mmBandLabelFindsTheBand(double label, string expected) =>
|
||||
Assert.Equal(expected, Bands.ByLabel(label)?.Name);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Nonemm.Core;
|
||||
|
||||
namespace Nonemm.Core.Tests;
|
||||
|
||||
public class CallsignTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("N8BJQ", "N8")]
|
||||
[InlineData("9A1AA", "9A1")]
|
||||
[InlineData("K1ABC", "K1")]
|
||||
[InlineData("VP2EXX", "VP2")]
|
||||
[InlineData("LZ1400PS", "LZ1400")]
|
||||
public void WpxPrefixEndsAtTheLastDigit(string call, string expected) =>
|
||||
Assert.Equal(expected, Callsign.Parse(call).WpxPrefix());
|
||||
|
||||
[Fact]
|
||||
public void CallWithNoDigitTakesAZeroAfterTwoLetters() =>
|
||||
Assert.Equal("RA0", Callsign.Parse("RAEM").WpxPrefix());
|
||||
|
||||
[Theory]
|
||||
[InlineData("KH9/N8BJQ")]
|
||||
[InlineData("N8BJQ/KH9")]
|
||||
public void PortablePrefixBecomesTheWpxPrefix(string call) =>
|
||||
Assert.Equal("KH9", Callsign.Parse(call).WpxPrefix());
|
||||
|
||||
[Fact]
|
||||
public void PortablePrefixWithNoDigitGainsAZero() =>
|
||||
Assert.Equal("PA0", Callsign.Parse("PA/N8BJQ").WpxPrefix());
|
||||
|
||||
[Fact]
|
||||
public void SingleDigitModifierReplacesTheDigit() =>
|
||||
Assert.Equal("N9", Callsign.Parse("N8BJQ/9").WpxPrefix());
|
||||
|
||||
[Fact]
|
||||
public void PortableModifierChangesNothing()
|
||||
{
|
||||
Callsign call = Callsign.Parse("DL1ABC/P");
|
||||
Assert.Equal("DL1", call.WpxPrefix());
|
||||
Assert.Null(call.PortablePrefix);
|
||||
Assert.Equal("DL1ABC", call.Station);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MaritimeMobileCountsForNothing()
|
||||
{
|
||||
Callsign call = Callsign.Parse("DL1ABC/MM");
|
||||
Assert.True(call.IsMaritimeMobile);
|
||||
Assert.False(call.CountsForEntity);
|
||||
Assert.Null(call.WpxPrefix());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortablePrefixIsWhatTheCountryFileGetsAsked() =>
|
||||
Assert.Equal("KH9", Callsign.Parse("KH9/N8BJQ").EntityLookupText());
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Core.Country;
|
||||
|
||||
namespace Nonemm.Core.Tests.Country;
|
||||
|
||||
public class CountryFileTests
|
||||
{
|
||||
private const string Sample = """
|
||||
Sicily: 15: 28: EU: 37.50: -14.00: -1.0: *IT9:
|
||||
IT9,IW9,ID9;
|
||||
Italy: 15: 28: EU: 42.83: -12.83: -1.0: I:
|
||||
I,IK,IZ,=IG9ABC;
|
||||
United States: 05: 08: NA: 37.60: 91.87: 5.0: K:
|
||||
K,W,N,K6(3)[6],=W1AW;
|
||||
Fiji: 32: 56: OC: -17.78: -177.92: -12.0: 3D2:
|
||||
3D2;
|
||||
""";
|
||||
|
||||
private static readonly CountryFile File = CountryFile.Parse(Sample);
|
||||
|
||||
[Fact]
|
||||
public void LongestPrefixWins() =>
|
||||
Assert.Equal("IT9", File.Find("IT9ABC")?.Entity.PrimaryPrefix);
|
||||
|
||||
[Fact]
|
||||
public void ShorterPrefixStillMatches() =>
|
||||
Assert.Equal("I", File.Find("IK2XYZ")?.Entity.PrimaryPrefix);
|
||||
|
||||
[Fact]
|
||||
public void WaeOnlyEntitiesAreMarked() =>
|
||||
Assert.True(File.Find("IT9ABC")?.Entity.IsWaeOnly);
|
||||
|
||||
[Fact]
|
||||
public void WholeCallEntryBeatsThePrefix() =>
|
||||
Assert.Equal("I", File.Find("IG9ABC")?.Entity.PrimaryPrefix);
|
||||
|
||||
[Fact]
|
||||
public void PrefixOverrideChangesTheZone()
|
||||
{
|
||||
CountryLookup? found = File.Find("K6XYZ");
|
||||
Assert.Equal(3, found?.CqZone);
|
||||
Assert.Equal(6, found?.ItuZone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PrefixWithoutOverrideKeepsTheEntityZone() =>
|
||||
Assert.Equal(5, File.Find("W1XYZ")?.CqZone);
|
||||
|
||||
[Fact]
|
||||
public void PortableStationIsLookedUpByItsPortablePrefix() =>
|
||||
Assert.Equal("3D2", File.Find("3D2/K1ABC")?.Entity.PrimaryPrefix);
|
||||
|
||||
[Fact]
|
||||
public void MaritimeMobileBelongsToNoEntity() =>
|
||||
Assert.Null(File.Find("K1ABC/MM"));
|
||||
|
||||
[Fact]
|
||||
public void LongitudeComesBackEastPositive() =>
|
||||
Assert.Equal(-91.87, File.Find("W1XYZ")!.Longitude, 2);
|
||||
|
||||
[Fact]
|
||||
public void UnknownCallHasNoEntity() =>
|
||||
Assert.Null(File.Find("XX9ZZZ"));
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("<html>404 not found</html>")]
|
||||
public void TextThatIsNotACountryFileIsRejected(string text) =>
|
||||
Assert.Throws<FormatException>(() => CountryFile.Parse(text));
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Nonemm.Core;
|
||||
|
||||
namespace Nonemm.Core.Tests;
|
||||
|
||||
public class GridSquareTests
|
||||
{
|
||||
[Fact]
|
||||
public void FourCharacterSquareCentresOnTheSquare()
|
||||
{
|
||||
Assert.True(GridSquare.TryParse("JN88", out GridSquare grid));
|
||||
Assert.Equal(48.5, grid.Latitude, 3);
|
||||
Assert.Equal(17.0, grid.Longitude, 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SixCharacterSquareIsMorePrecise()
|
||||
{
|
||||
Assert.True(GridSquare.TryParse("FN31pr", out GridSquare grid));
|
||||
Assert.Equal(41.7, grid.Latitude, 1);
|
||||
Assert.Equal(-72.7, grid.Longitude, 1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("JN8")]
|
||||
[InlineData("SN89")]
|
||||
[InlineData("JNXY")]
|
||||
public void MalformedLocatorIsRejected(string text) =>
|
||||
Assert.False(GridSquare.TryParse(text, out _));
|
||||
|
||||
[Fact]
|
||||
public void DistanceIsTheGreatCircleBetweenSquareCentres()
|
||||
{
|
||||
Assert.True(GridSquare.TryParse("JO99", out GridSquare jo99));
|
||||
Assert.True(GridSquare.TryParse("IO91", out GridSquare io91));
|
||||
Assert.InRange(jo99.DistanceTo(io91), 1525, 1540);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BearingIsZeroDueNorth()
|
||||
{
|
||||
Assert.True(GridSquare.TryParse("JO99", out GridSquare south));
|
||||
Assert.True(GridSquare.TryParse("JP90", out GridSquare north));
|
||||
Assert.Equal(0, south.BearingTo(north), 6);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<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.Core\Nonemm.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user