Esempio n. 1
0
        private static void JoinIntervalsTest(bool fixedInterval = false)
        {
            const long duration = 10;
            var        input1   = new StreamEvent <string>[]
            {
                StreamEvent.CreateInterval(100, 100 + duration, "A1"),
                StreamEvent.CreateInterval(101, 101 + duration, "B1"),
                StreamEvent.CreateInterval(102, 102 + duration, "C1"),

                StreamEvent.CreateInterval(120, 120 + duration, "A3"),
                StreamEvent.CreateInterval(121, 121 + duration, "B3"),
                StreamEvent.CreateInterval(122, 122 + duration, "C3"),
                StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime)
            };

            var input2 = new[]
            {
                StreamEvent.CreateInterval(105, 105 + duration, "A2"),
                StreamEvent.CreateInterval(106, 106 + duration, "B2"),
                StreamEvent.CreateInterval(107, 107 + duration, "D2"),

                StreamEvent.CreateInterval(125, 125 + duration, "A4"),
                StreamEvent.CreateInterval(126, 126 + duration, "B4"),
                StreamEvent.CreateInterval(127, 127 + duration, "C4"),
                StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime)
            };

            var inputStream1 = input1.ToStreamable();
            var inputStream2 = input2.ToStreamable();

            if (fixedInterval)
            {
                inputStream1 = inputStream1.AlterEventDuration(duration);
                inputStream2 = inputStream2.AlterEventDuration(duration);
            }

            var outputStream = inputStream1.Join(
                inputStream2,
                l => (l != null ? l[0].ToString() : null),
                r => (r != null ? r[0].ToString() : null),
                (l, r) => $"{l},{r}");

            var correct = new[]
            {
                StreamEvent.CreateInterval(105, 110, "A1,A2"),
                StreamEvent.CreateInterval(106, 111, "B1,B2"),

                StreamEvent.CreateInterval(125, 130, "A3,A4"),
                StreamEvent.CreateInterval(126, 131, "B3,B4"),
                StreamEvent.CreateInterval(127, 132, "C3,C4"),
                StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime)
            };

            Assert.IsTrue(outputStream.IsEquivalentTo(correct));
        }