Files
Nonemm/tests/Nonemm.Core.Tests/BandsTests.cs
ericek111 e6d0b58305 Keep the band when the frequency is past the edge
Contest operating goes outside the band edges. Someone answers a CQ at 14352, or
a radio reports a frequency a few hundred hertz off, and Bands.ForFrequency
returned null: the contact scored nothing, missed the per-band dupe check and
exported with no band.

N1MM buckets a frequency by its whole megahertz — its BandFor divides the
kilohertz by 1000 and switches on the result, with 1 and 2 both 160M, 3 and 4
both 80M, 28 and 29 both 10M — and never looks at a band edge. Same rule here,
except that the real edges are checked first: 2190M and 630M are both under
1 MHz and share the bucket, so nothing else can tell them apart. A frequency
under 1 MHz that misses both edge ranges still has no band, as it does in N1MM.

The bandmap clamped its slice to the band edges, so a radio past the edge left
the receiver bar off the top of the scale. The slice now stretches to wherever
the radio is.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-27 23:01:39 +00:00

59 lines
2.0 KiB
C#

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)));
/// N1MM buckets by whole megahertz, so a contact made past the edge keeps
/// its band instead of losing it.
[Theory]
[InlineData(14400, "20M")]
[InlineData(7305, "40M")]
[InlineData(1999.9, "160M")]
[InlineData(4100, "80M")]
[InlineData(29800, "10M")]
[InlineData(21500, "15M")]
public void FrequencyPastTheBandEdgeStillCountsAsThatBand(double kilohertz, string expected) =>
Assert.Equal(expected, Bands.ForFrequency(Frequency.FromKilohertz(kilohertz))?.Name);
/// Below 1 MHz every band shares the same megahertz, so only the real edges
/// decide.
[Theory]
[InlineData(137, "2190M")]
[InlineData(475, "630M")]
public void TheLowFrequencyBandsGoByTheirEdges(double kilohertz, string expected) =>
Assert.Equal(expected, Bands.ForFrequency(Frequency.FromKilohertz(kilohertz))?.Name);
[Fact]
public void BroadcastFrequenciesBelowOneMegahertzHaveNoBand() =>
Assert.Null(Bands.ForFrequency(Frequency.FromKilohertz(900)));
[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);
}