Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public async ValueTask <List <DataPoint> > ToList()
        {
            IAsyncEnumerable <DataPoint> source   = this.SourceAsync();
            DataPointIterator            filtered = source.DeadBandCompressionAsync(0.1);

            return(await filtered.ToListAsync());
        }
Exemplo n.º 3
0
        public async Task MoveNextAsync___false()
        {
            DataPointIterator sut = DataPointIterator.Empty;

            Assert.AreSame(Array.Empty <DataPoint>(), await sut.ToArrayAsync());
            Assert.AreEqual(0, (await sut.ToListAsync()).Count);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }