Esempio n. 1
0
 public void Sum()
 {
     var testInterval = new TestInterval();
     long max = long.MinValue;
     testInterval.Interval.Aggregate((sum, @event) => new Event<long>(0, sum.Data + @event.Data)).Subscribe(i => max = i.Data);
     testInterval.Start();
     max.Should().Be(1770);
 }
Esempio n. 2
0
 public void Max()
 {
     var testInterval = new TestInterval();
     long max = long.MinValue;
     testInterval.Interval.Max(e => e.Data).Subscribe(i => max = i);
     testInterval.Start();
     max.Should().Be(testInterval.ExpectedCount - 1);
 }
Esempio n. 3
0
 public void Ding()
 {
     var testInterval = new TestInterval();
     long ding = long.MinValue;
     testInterval.Interval.SkipWhile(@event => @event.Data < 30).Take(1).Subscribe(@e => ding = @e.Data);
     testInterval.Start();
     ding.Should().Be(30);
 }
Esempio n. 4
0
        public void Count()
        {
            var testInterval = new TestInterval();

            int count = 0;
            testInterval.Interval.Where(e => e.Type == 0).Count().Subscribe(i => count = i);
            testInterval.Start();
            count.Should().Be(testInterval.ExpectedCount / testInterval.NumberOfTypes);
        }
Esempio n. 5
0
        public void CompoundWhere()
        {
            var filter = new Filter<Event<long>>("@event => @event.Type == 1L && @event.Data > 30 && @event != null && @event.Data != 203123123");

            var testInterval = new TestInterval();

            int count = 0;
            testInterval.Interval.Link(filter).Count().Subscribe(i => count = i);
            testInterval.Start();
            count.Should().Be((testInterval.ExpectedCount - 30) / testInterval.NumberOfTypes);
        }
Esempio n. 6
0
        public void GroupBy_Count()
        {
            var testInterval = new TestInterval();
            testInterval.Interval.GroupBy(@event => @event.Type).Subscribe(x =>
            {
                int count = 0;
                x.Subscribe(_ => Console.WriteLine("-> {0} : {1}", x.Key.ToString().PadLeft(3), (++count).ToString().PadLeft(3)));
            });

            testInterval.Start();
        }
Esempio n. 7
0
        public void MostBasic_Count_100x()
        {
            // Where type = 1

            var testInterval = new TestInterval();

            var query = new QueryState<EventBase>();

            var session = ConfigureSession(query);
            session.Execute("Filters.Add(@event => @event.Type == 1);");

            int count = 0;
            testInterval.Interval.WhereEach(query.Filters).Count().Subscribe(i => count = i);
            testInterval.Start();
            count.Should().Be(testInterval.ExpectedCount / testInterval.NumberOfTypes);
        }
Esempio n. 8
0
        public void RunningSum()
        {
            // NOTE: fully qualifying the type name matters.  If this were a real thing, you could put in default namespaces.
            var summer = new Scan<Event<long>>("(sum, @event) => new RoslynRx.Tests.Event<long>(0, sum.Data + @event.Data)");
            var testInterval = new TestInterval();
            long sum = long.MinValue;

            testInterval.Interval.Link(summer).Subscribe(i => { sum = i.Data; Console.WriteLine(i.Data); });
            var oldSum = 0L;
            for (int i = 0; i < testInterval.ExpectedCount; i++)
            {
                Console.WriteLine("Advancing. {0} {1}", i, oldSum);
                testInterval.Scheduler.AdvanceBy(TimeSpan.TicksPerSecond);
                oldSum = oldSum + i;
                sum.Should().Be(oldSum);
            }

            sum.Should().Be(1770);
        }
Esempio n. 9
0
        public void Demux()
        {
            var knownTypes = new[] { 1, 2 };
            var dm = new Demuxer<int, Event<long>>(knownTypes, "@event => @event.Type");
            foreach (var stream in dm.Streams)
                stream.Should().NotBeNull();
            var testInterval = new TestInterval(100, 5);
            testInterval.Interval.Subscribe(dm);

            var expected = new[] {20L, 20L};
            var results = new long[2];

            for (int index = 0; index < knownTypes.Length; index++)
            {
                var x = index;
                dm.Streams[knownTypes[index]].Count().Subscribe(i => results[x] = i);
            }

            testInterval.Start();
            results.ShouldAllBeEquivalentTo(expected);
        }
Esempio n. 10
0
        public void SimpleTest_WithExtension()
        {
            var filter = new Filter<Event<long>>("@event => @event.Type == 1L");

            var testInterval = new TestInterval();

            int count = 0;

            testInterval.Interval.Link(filter).Count().Subscribe(i => count = i);
            testInterval.Start();
            count.Should().Be(testInterval.ExpectedCount / testInterval.NumberOfTypes);
        }
Esempio n. 11
0
        public void Sum()
        {
            // NOTE: fully qualifying the type name matters.  If this were a real thing, you could put in default namespaces.
            var summer = new Aggregate<Event<long>>("(sum, @event) => new RoslynRx.Tests.Event<long>(0, sum.Data + @event.Data)");
            var testInterval = new TestInterval();
            long sum = long.MinValue;

            testInterval.Interval.Link(summer).Subscribe(i => sum = i.Data);
            testInterval.Start();
            sum.Should().Be(1770);
        }