diff --git a/src/Nonemm.Session/QtcTraffic.cs b/src/Nonemm.Session/QtcTraffic.cs index 2897be8..793a947 100644 --- a/src/Nonemm.Session/QtcTraffic.cs +++ b/src/Nonemm.Session/QtcTraffic.cs @@ -214,16 +214,23 @@ public sealed class QtcTraffic /// The header a station sends in front of a series: a series number, a /// separator and how many lines follow. Anything between the two numbers - /// counts as the separator, because it is copied off the air. + /// counts as the separator, because it is copied off the air. A series + /// number on its own means ten lines, which is what N1MM assumes: "If he + /// only types the batch number without the forward slash and count, the + /// program will assume the count is 10." public static (int Series, int Count)? ReadHeader(string text) { string[] parts = text.Trim().ToUpperInvariant().Replace("QTC", "").Trim() .Split(['/', '-', ' ', '\\'], StringSplitOptions.RemoveEmptyEntries); - return parts.Length >= 2 - && int.TryParse(parts[0], out int series) - && int.TryParse(parts[1], out int count) - && series > 0 - && count is > 0 and <= WaeQtc.MostPerSeries + if (parts.Length == 0 || !int.TryParse(parts[0], out int series) || series <= 0) + { + return null; + } + if (parts.Length == 1) + { + return (series, WaeQtc.MostPerSeries); + } + return int.TryParse(parts[1], out int count) && count is > 0 and <= WaeQtc.MostPerSeries ? (series, count) : null; } diff --git a/tests/Nonemm.Session.Tests/QtcTrafficTests.cs b/tests/Nonemm.Session.Tests/QtcTrafficTests.cs index 8abcdbf..4976e9b 100644 --- a/tests/Nonemm.Session.Tests/QtcTrafficTests.cs +++ b/tests/Nonemm.Session.Tests/QtcTrafficTests.cs @@ -314,9 +314,21 @@ public class QtcTrafficTests Assert.Equal(10, count); } + /// N1MM fills in the count when the operator types the series number + /// alone, because ten is the usual series. + [Theory] + [InlineData("87")] + [InlineData("QTC 87")] + public void ASeriesNumberOnItsOwnMeansTenLines(string text) + { + (int series, int count) = Assert.IsType<(int, int)>(QtcTraffic.ReadHeader(text)); + + Assert.Equal(87, series); + Assert.Equal(10, count); + } + [Theory] [InlineData("")] - [InlineData("87")] [InlineData("87/11")] [InlineData("abc/10")] public void AHeaderThatIsNotOneReadsAsNothing(string text) =>