Take a QTC header that is only a series number as ten lines
An operator copying a header off the air often types the series number and nothing else. That read as a header the program could not parse, so the box went yellow and Close refused to log the series. N1MM fills the count in: "If he only types the batch number without the forward slash and count, the program will assume the count is 10." Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0157i7PiZyqBkquxS9A6FTdQ
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user