Files
Nonemm/tests/Nonemm.Formats.Tests/CabrilloWriterTests.cs
Erik 0f84bc8972 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>
2026-08-27 10:27:51 +00:00

84 lines
2.6 KiB
C#

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);
}
}