From f35aac9e89d4d8f2b27a9289710a1357d989b609 Mon Sep 17 00:00:00 2001 From: Peter Freiling Date: Fri, 30 Oct 2020 14:13:57 -0700 Subject: [PATCH] clean up --- .../SimpleTesting/Streamables/AfaTests.cs | 183 +++++++++++------- 1 file changed, 117 insertions(+), 66 deletions(-) diff --git a/Sources/Test/SimpleTesting/Streamables/AfaTests.cs b/Sources/Test/SimpleTesting/Streamables/AfaTests.cs index 30139db..68aa360 100644 --- a/Sources/Test/SimpleTesting/Streamables/AfaTests.cs +++ b/Sources/Test/SimpleTesting/Streamables/AfaTests.cs @@ -616,6 +616,54 @@ namespace SimpleTesting Assert.IsTrue(result.SequenceEqual(expected)); } + [TestMethod, TestCategory("Gated")] + public void AfaZeroOrOneGroup() + { + var source = new StreamEvent[] + { + StreamEvent.CreateStart(0, "O"), + StreamEvent.CreateStart(1, "A"), + StreamEvent.CreateStart(2, "A"), + StreamEvent.CreateStart(3, "F"), + StreamEvent.CreateStart(4, "O"), + }.ToObservable() + .ToStreamable() + .AlterEventDuration(10); + + // O(A*F)? + var afa = ARegex.Concat( + ARegex.SingleElement( + (time, @event, state) => @event == "O", + (time, @event, state) => state + @event), + ARegex.ZeroOrOne( + ARegex.Concat( + ARegex.KleeneStar( + ARegex.SingleElement( + (time, @event, state) => @event == "A", + (time, @event, state) => state + @event)), + ARegex.SingleElement( + (time, @event, state) => @event == "F", + (time, @event, state) => state + @event)))); + + var result = source + .Detect( + afa, + allowOverlappingInstances: false, + isDeterministic: false) + .ToStreamEventObservable() + .Where(evt => evt.IsData) + .ToEnumerable() + .ToArray(); + var expected = new StreamEvent[] + { + StreamEvent.CreateInterval(0, 10, "O"), + StreamEvent.CreateInterval(3, 10, "OAAF"), + StreamEvent.CreateInterval(4, 14, "O"), + }; + + Assert.IsTrue(result.SequenceEqual(expected)); + } + [TestMethod, TestCategory("Gated")] public void AfaPunctuationAtBatchBoundary() { @@ -683,54 +731,6 @@ namespace SimpleTesting longPool.Free(); } } - - [TestMethod, TestCategory("Gated")] - public void AfaZeroOrOneGroup() - { - var source = new StreamEvent[] - { - StreamEvent.CreateStart(0, "O"), - StreamEvent.CreateStart(1, "A"), - StreamEvent.CreateStart(2, "A"), - StreamEvent.CreateStart(3, "F"), - StreamEvent.CreateStart(4, "O"), - }.ToObservable() - .ToStreamable() - .AlterEventDuration(10); - - // O(A*F)? - var afa = ARegex.Concat( - ARegex.SingleElement( - (time, @event, state) => @event == "O", - (time, @event, state) => state + @event), - ARegex.ZeroOrOne( - ARegex.Concat( - ARegex.KleeneStar( - ARegex.SingleElement( - (time, @event, state) => @event == "A", - (time, @event, state) => state + @event)), - ARegex.SingleElement( - (time, @event, state) => @event == "F", - (time, @event, state) => state + @event)))); - - var result = source - .Detect( - afa, - allowOverlappingInstances: false, - isDeterministic: false) - .ToStreamEventObservable() - .Where(evt => evt.IsData) - .ToEnumerable() - .ToArray(); - var expected = new StreamEvent[] - { - StreamEvent.CreateInterval(0, 10, "O"), - StreamEvent.CreateInterval(3, 10, "OAAF"), - StreamEvent.CreateInterval(4, 14, "O"), - }; - - Assert.IsTrue(result.SequenceEqual(expected)); - } } /// @@ -771,8 +771,7 @@ namespace SimpleTesting (time, @event, state) => state + @event)); var afa_compiled = source - .Detect( - afa); + .Detect(afa); afa_compiled.Properties.IsSyncTimeSimultaneityFree = true; var result = afa_compiled @@ -819,8 +818,7 @@ namespace SimpleTesting (time, @event, state) => state + @event))); var afa_compiled = source - .Detect( - afa); + .Detect(afa); afa_compiled.Properties.IsSyncTimeSimultaneityFree = true; var result = afa_compiled @@ -927,11 +925,11 @@ namespace SimpleTesting var afa_compiled = source.GroupApply( (input) => input.Item2, group => - { - var afaGroup = group.Detect(afa, maxDuration: 10); - afaGroup.Properties.IsSyncTimeSimultaneityFree = true; - return afaGroup; - }, + { + var afaGroup = group.Detect(afa, maxDuration: 10); + afaGroup.Properties.IsSyncTimeSimultaneityFree = true; + return afaGroup; + }, (group, bind) => bind); var result = afa_compiled @@ -1049,9 +1047,7 @@ namespace SimpleTesting (time, @event, state) => state + @event)); var afa_compiled = source - .Detect( - afa, - maxDuration: 7); + .Detect(afa, maxDuration: 7); afa_compiled.Properties.IsSyncTimeSimultaneityFree = true; @@ -1097,9 +1093,7 @@ namespace SimpleTesting (time, @event, state) => state + @event))); var result = source - .Detect( - afa, - maxDuration: 4) + .Detect(afa, maxDuration: 4) .ToStreamEventObservable() .Where(evt => evt.IsData) .ToEnumerable() @@ -1143,9 +1137,7 @@ namespace SimpleTesting (time, @event, state) => state + @event))); var result = source - .Detect( - afa, - maxDuration: 7) + .Detect(afa, maxDuration: 7) .ToStreamEventObservable() .Where(evt => evt.IsData) .ToEnumerable() @@ -1162,6 +1154,65 @@ namespace SimpleTesting Assert.IsTrue(result.SequenceEqual(expected)); } + internal class State + { + // This cannot be an enum because we want represent a concatinated state in terms of digits in int value + public const int A = 1; + public const int B = 2; + public const int C = 3; + } + + [TestMethod, TestCategory("Gated")] + public void AfaZeroOrOneWithStartEvent() + { + var source = new StreamEvent[] + { + StreamEvent.CreateStart(0, State.A), + StreamEvent.CreateStart(1, State.C), + StreamEvent.CreateStart(2, State.B), + StreamEvent.CreateStart(3, State.B), + StreamEvent.CreateStart(4, State.C), + StreamEvent.CreateStart(5, State.A), + StreamEvent.CreateStart(6, State.B), + StreamEvent.CreateStart(7, State.B), + StreamEvent.CreateStart(8, State.B), + StreamEvent.CreateStart(9, State.A), + }.ToObservable() + .ToStreamable() + .SetProperty().IsConstantDuration(true, StreamEvent.InfinitySyncTime); + + // Assert we are actually testing columnar + Assert.IsTrue(source.Properties.IsColumnar); + + var afa = ARegex.Concat( + ARegex.SingleElement( + (time, @event, state) => @event == State.A, + (time, @event, state) => @event), + ARegex.ZeroOrOne( + ARegex.SingleElement( + (time, @event, state) => @event == State.B, + (time, @event, state) => state * 10 + @event))); + + var result = source + .Detect( + afa, + allowOverlappingInstances: false, + isDeterministic: false) + .ToStreamEventObservable() + .Where(evt => evt.IsData) + .ToEnumerable() + .ToArray(); + + var expected = new StreamEvent[] + { + StreamEvent.CreateStart(0, State.A), + StreamEvent.CreateStart(5, State.A), + StreamEvent.CreateStart(6, State.A * 10 + State.B), + StreamEvent.CreateStart(9, State.A), + }; + Assert.IsTrue(result.SequenceEqual(expected)); + } + [TestMethod, TestCategory("Gated")] public void PartitionedAfaPunctuationAtBatchBoundary() => PartitionedAfaBatchBoundary(isLowWatermark: false);