namespace Nonemm.Session.Tests; /// The cases are the rows of N1MM's ESM table, both columns. public class EsmTests { private static EsmSituation Running(EsmSituation now) => now with { IsRunning = true }; [Fact] public void AnEmptyWindowCallsCqOrSendsMyCall() { Assert.Equal([0], Esm.Decide(Running(new EsmSituation())).Keys); Assert.Equal([3], Esm.Decide(new EsmSituation()).Keys); } [Fact] public void ANewCallGetsHisCallAndTheExchangeWhileRunning() { EsmAction action = Esm.Decide(Running(new EsmSituation { HasCall = true })); Assert.Equal([4, 1], action.Keys); Assert.False(action.Logs); } [Fact] public void CallingAgainWhileRunningAsksForARepeat() { EsmSituation now = Running(new EsmSituation { HasCall = true, CallSent = true }); Assert.Equal([7], Esm.Decide(now).Keys); } [Fact] public void SearchingSendsMyCallAgainUnlessTheBigGunSwitchIsOn() { EsmSituation now = new() { HasCall = true, CallSent = true }; Assert.Equal([3], Esm.Decide(now).Keys); Assert.Equal([7], Esm.Decide(now with { SendsCallOnce = true }).Keys); } [Fact] public void AnExchangeInTheBoxesEndsTheContact() { EsmSituation now = new() { HasCall = true, HasExchange = true, ExchangeSent = false }; EsmAction running = Esm.Decide(Running(now)); Assert.Equal([4, 1], running.Keys); Assert.False(running.Logs); EsmAction searching = Esm.Decide(now); Assert.Equal([1], searching.Keys); Assert.True(searching.Logs); } [Fact] public void OnceTheExchangeHasGoneOutEnterLogsTheContact() { EsmSituation now = new() { HasCall = true, HasExchange = true, ExchangeSent = true }; EsmAction running = Esm.Decide(Running(now)); Assert.Equal([2], running.Keys); Assert.True(running.Logs); EsmAction searching = Esm.Decide(now); Assert.Empty(searching.Keys); Assert.True(searching.Logs); } [Fact] public void ADupeIsToldItIsInTheLogUnlessDupesAreWorked() { EsmSituation now = Running(new EsmSituation { HasCall = true, IsDupe = true }); Assert.Equal([5], Esm.Decide(now).Keys); Assert.Equal([4, 1], Esm.Decide(now with { WorksDupes = true }).Keys); } [Fact] public void ADupeWhileSearchingIsLeftAlone() { EsmAction action = Esm.Decide(new EsmSituation { HasCall = true, IsDupe = true }); Assert.True(action.IsNothing); } [Fact] public void ADupeWithAnExchangeIsWorkedLikeAnyOtherStation() { EsmSituation now = new() { HasCall = true, IsDupe = true, HasExchange = true }; Assert.Equal([4, 1], Esm.Decide(Running(now)).Keys); Assert.Equal([1], Esm.Decide(now).Keys); Assert.True(Esm.Decide(now).Logs); } }