Exemple #1
0
        public async Task Cancellation___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().Take(2).ToList();

            DataPointIterator dataPointIterator = sut.ProcessAsync(data);
            var cts        = new CancellationTokenSource();
            var enumerator = dataPointIterator.GetAsyncEnumerator(cts.Token);

            var actual = new List <DataPoint>();
            await enumerator.MoveNextAsync();

            actual.Add(enumerator.Current);
            await enumerator.MoveNextAsync();

            actual.Add(enumerator.Current);
            cts.Cancel();

            List <DataPoint> res = null;

            Assert.ThrowsAsync <OperationCanceledException>(async() => res = await dataPointIterator.ToListAsync(cts.Token));

            CollectionAssert.AreEqual(expected, actual);
            Assert.IsNull(res);
        }
Exemple #2
0
        public void Cancellation_after_two_items___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = KnownSequenceAsync();
            var expected = KnownSequence().Take(2).ToList();
            var cts      = new CancellationTokenSource();

            var actual = new List <DataPoint>();
            int idx    = 0;

            Assert.ThrowsAsync <OperationCanceledException>(async() =>
            {
                await foreach (DataPoint dp in sut.ProcessAsync(data).WithCancellation(cts.Token))
                {
                    actual.Add(dp);
                    idx++;

                    if (idx == 2)
                    {
                        cts.Cancel();
                    }
                }
            });

            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #3
0
        public async Task Empty_IAsyncEnumerable___empty_result()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = EmptyAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();

            Assert.IsFalse(await iterator.MoveNextAsync());
        }
Exemple #4
0
        public async Task Empty_IAsyncEnumerable___empty_result()
        {
            var sut  = new DeadBandCompression(0.1);
            var data = EmptyAsync();

            var actual = sut.ProcessAsync(data);

            Assert.AreEqual(0, (await actual.ToListAsync()).Count);
        }
Exemple #5
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new DeadBandCompression(0.1, 4d);
            var data     = RawDataForMaxDeltaAsync();
            var expected = ExpectedForMaxDelta().ToList();

            var actual = await sut.ProcessAsync(data).ToListAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #6
0
        public async Task Data_given_as_IAsyncEnumerable___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

            var actual = await sut.ProcessAsync(data).ToListAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #7
0
        public async Task Empty_IAsyncEnumerable_foreach___empty_result()
        {
            var sut  = new DeadBandCompression(0.1);
            var data = EmptyAsync();

            int count = 0;

            await foreach (DataPoint db in sut.ProcessAsync(data))
            {
                count++;
            }

            Assert.AreEqual(0, count);
        }
Exemple #8
0
        public async Task InstrumentPrecision_0___input_echoed()
        {
            var sut      = new DeadBandCompression(0);
            var data     = KnownSequenceAsync();
            var result   = sut.ProcessAsync(data);
            var expected = KnownSequence().ToArray();
            var actual   = new List <DataPoint>();

            await foreach (DataPoint dp in result)
            {
                actual.Add(dp);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #9
0
        public async Task Known_sequence_foreach___correct_result()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = KnownSequenceAsync();
            var result   = sut.ProcessAsync(data);
            var expected = KnownSequenceExpected(swingingDoor: false).ToArray();
            var actual   = new List <DataPoint>();

            await foreach (DataPoint dp in result)
            {
                actual.Add(dp);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #10
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new DeadBandCompression(0.1, 4d);
            var data     = RawDataForMaxDeltaAsync();
            var expected = ExpectedForMaxDelta().ToList();

            var actual = new List <DataPoint>();

            await foreach (DataPoint dp in sut.ProcessAsync(data))
            {
                actual.Add(dp);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #11
0
        public async Task IEnumerable_iterated_and_ToList___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

            DataPointIterator dataPointIterator = sut.ProcessAsync(data);
            var enumerator = dataPointIterator.GetAsyncEnumerator();

            await enumerator.MoveNextAsync();

            await enumerator.MoveNextAsync();

            var actual = await dataPointIterator.ToListAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #12
0
        public async Task Data_given_as_IAsyncEnumerable___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

            var actual = new List <DataPoint>();

            await foreach (DataPoint dp in sut.ProcessAsync(data))
            {
                actual.Add(dp);
            }

            Print(expected, "expected");
            Print(actual, "actual");
            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #13
0
        public void Known_sequence___correct_result()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = KnownSequenceAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();
            var expected = KnownSequenceExpected(swingingDoor: false).ToArray();

            Assert.Multiple(async() =>
            {
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[0], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[1], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[2], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[3], iterator.Current);
            });
        }
        public async Task Known_sequence___correct_result()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = KnownSequenceAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();
            var expected = new List <DataPoint>();

            await foreach (DataPoint dp in KnownSequenceAsync())
            {
                expected.Add(dp);
            }

            Assert.Multiple(async() =>
            {
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[0], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[1], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[2], iterator.Current);
            });
        }