Ejemplo 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();

            DataPoint[] res = null;
            Assert.ThrowsAsync <OperationCanceledException>(async() => res = await dataPointIterator.ToArrayAsync(cts.Token));

            CollectionAssert.AreEqual(expected, actual);
            Assert.IsNull(res);
        }
Ejemplo n.º 2
0
        public async ValueTask <DataPoint[]> ToArray()
        {
            IAsyncEnumerable <DataPoint> source   = this.SourceAsync();
            DataPointIterator            filtered = source.DeadBandCompressionAsync(0.1);

            return(await filtered.ToArrayAsync());
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public async Task IEnumerable_iterated_and_ToArray___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.ToArrayAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public async Task IEnumerable_iterated_and_ToArray___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.ToArrayAsync();

            CollectionAssert.AreEqual(expected, actual);
        }