Ejemplo n.º 1
0
        public void Cancellation_after_two_items___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().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(expected, actual);
        }
Ejemplo n.º 2
0
        public async Task Cancellation___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            var data     = RawDataAsync(RawDataForTrend());
            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);
        }
Ejemplo n.º 3
0
        public async Task Empty_IAsyncEnumerable___empty_result()
        {
            var sut      = new SwingingDoorCompression(1);
            var data     = EmptyAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();

            Assert.IsFalse(await iterator.MoveNextAsync());
        }
Ejemplo n.º 4
0
        public async Task Empty_IAsyncEnumerable___empty_result()
        {
            var sut  = new SwingingDoorCompression(1d);
            var data = EmptyAsync();

            var actual = sut.ProcessAsync(data);

            Assert.AreEqual(0, (await actual.ToListAsync()).Count);
        }
Ejemplo n.º 5
0
        public async Task Data_given_as_IAsyncEnumerable___OK(double compressionDeviation, IAsyncEnumerable <DataPoint> rawData, IEnumerable <DataPoint> expectedData)
        {
            var sut      = new SwingingDoorCompression(compressionDeviation);
            var data     = rawData;
            var expected = expectedData.ToList();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public async Task Data_given_as_IAsyncEnumerable___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new SwingingDoorCompression(1d, 6d);
            var data     = RawDataAsync(RawDataForMaxDelta());
            var expected = ExpectedForMaxDelta().ToList();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public async Task Data_IAsyncEnumerable_with_minDeltaX_ToArray___OK()
        {
            int currentRawMinDeltaXCount = RawMinDeltaXCounter;

            var sut      = new SwingingDoorCompression(1d, minDeltaX: 1d);
            var data     = RawMinDeltaXAsync();
            var expected = ExpectedMinDeltaX().ToList();

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

            CollectionAssert.AreEqual(expected, actual);
            Assert.AreEqual(currentRawMinDeltaXCount + 1, RawMinDeltaXCounter);
        }
Ejemplo n.º 9
0
        public async Task Empty_IAsyncEnumerable_foreach___empty_result()
        {
            var sut  = new SwingingDoorCompression(1);
            var data = EmptyAsync();

            int count = 0;

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

            Assert.AreEqual(0, count);
        }
Ejemplo n.º 10
0
        public async Task CompressionDeviation_0___input_echoed()
        {
            var sut      = new SwingingDoorCompression(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);
        }
Ejemplo n.º 11
0
        public async Task Known_sequence_foreach___correct_result()
        {
            var sut      = new SwingingDoorCompression(1);
            var data     = KnownSequenceAsync();
            var result   = sut.ProcessAsync(data);
            var expected = KnownSequenceExpected().ToArray();
            var actual   = new List <DataPoint>();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public async Task Data_given_as_IAsyncEnumerable___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

            var actual = new List <DataPoint>();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public async Task Data_IAsyncEnumerable_with_minDeltaX___OK()
        {
            var sut      = new SwingingDoorCompression(1d, minDeltaX: 1d);
            var data     = RawMinDeltaXAsync();
            var expected = ExpectedMinDeltaX().ToList();

            var actual = new List <DataPoint>();

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

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public async Task IEnumerable_iterated_and_ToList___OK(double compressionDeviation, IAsyncEnumerable <DataPoint> rawData, IEnumerable <DataPoint> expectedData)
        {
            var sut      = new SwingingDoorCompression(compressionDeviation);
            var data     = rawData;
            var expected = expectedData.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);
        }
Ejemplo n.º 15
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new SwingingDoorCompression(1d, 6d);
            var data     = RawDataAsync(RawDataForMaxDelta());
            var expected = ExpectedForMaxDelta().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);
        }
Ejemplo n.º 16
0
        public async Task IEnumerable_iterated_and_ToList___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            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);
        }
Ejemplo n.º 17
0
        public async Task Data_given_as_IAsyncEnumerable___OK(double compressionDeviation, IAsyncEnumerable <DataPoint> rawData, IEnumerable <DataPoint> expectedData)
        {
            var sut      = new SwingingDoorCompression(compressionDeviation);
            var data     = rawData;
            var expected = expectedData.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);
        }
Ejemplo n.º 18
0
        public void Known_sequence___correct_result()
        {
            var sut      = new SwingingDoorCompression(1);
            var data     = KnownSequenceAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();
            var expected = KnownSequenceExpected().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);
            });
        }
Ejemplo n.º 19
0
        public async Task Known_sequence___correct_result()
        {
            var sut      = new SwingingDoorCompression(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);
            });
        }