using Nonemm.Session; namespace Nonemm.Session.Tests; /// The decoded text as the modem sends it, one character at a time. public class DigitalReceiverTests { private static List CallsIn(string text) { DigitalReceiver receiver = new(); List heard = []; receiver.CallHeard += (_, call) => heard.Add(call); foreach (char c in text) { receiver.Receive(c.ToString()); } return heard; } [Fact] public void ACallsignIsReportedWhenTheWordEnds() { Assert.Equal(["OM5M"], CallsIn("CQ DE OM5M ")); } [Fact] public void AWordThatIsStillBeingSentIsNotReportedYet() { Assert.Empty(CallsIn("CQ DE OM5")); } [Fact] public void ALineBreakEndsAWordTheSameWayASpaceDoes() { Assert.Equal(["OM5M"], CallsIn("DE OM5M\r\n")); } [Fact] public void NoiseThatIsNotShapedLikeACallIsPassedOver() { Assert.Empty(CallsIn("RYRY ????? +.+. \r\n")); } [Fact] public void TheTextIsKeptAsItArrived() { DigitalReceiver receiver = new(); receiver.Receive("CQ TEST "); receiver.Receive("OM5M"); Assert.Equal("CQ TEST OM5M", receiver.Text); } /// A callsign has at most three characters after its number, so that is /// where a word that ran into the next one is cut. [Fact] public void AWordRunTogetherWithTheNextIsCutBackToTheCall() { Assert.Equal("OM5MTE", DigitalReceiver.TrimToCall("OM5MTESTTEST")); Assert.Equal("OM5M", DigitalReceiver.TrimToCall("OM5M")); } [Fact] public void APortableCallIsLeftAlone() { Assert.Equal("OM5M/P", DigitalReceiver.TrimToCall("OM5M/P")); } [Fact] public void TheWordUnderThePointerIsTheOneAroundIt() { Assert.Equal("OM5M", DigitalReceiver.WordAt("CQ DE OM5M K", 7)); Assert.Equal("", DigitalReceiver.WordAt("CQ DE OM5M K", 5)); } }