public void Cloning_iterates_over_fresh_set() { var sut = new DeadBandCompression(0.1); var data = KnownSequence().ToArray().Select(dp => dp); var expected = KnownSequence().ToArray(); var filter = sut.Process(data); var iterator = filter.GetEnumerator(); iterator.MoveNext(); iterator = filter.Clone().GetEnumerator(); Assert.Multiple(() => { int step = 0; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsFalse(iterator.MoveNext(), $"MoveNext step: {step++}"); }); }
public void Known_sequence___correct_result() { var sut = new DeadBandCompression(0.1); var data = KnownSequence(); var iterator = sut.Process(data).GetEnumerator(); var expected = KnownSequenceExpected(swingingDoor: false).ToArray(); Assert.Multiple(() => { int step = 0; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsTrue(iterator.MoveNext(), $"MoveNext step: {step}"); Assert.AreEqual(expected[step], iterator.Current, $"Equal step: {step}"); step++; Assert.IsFalse(iterator.MoveNext(), $"MoveNext step: {step++}"); }); }
public void Empty_IEnumerable___empty_result() { var sut = new DeadBandCompression(0.1); var data = Empty(); var iterator = sut.Process(data).GetEnumerator(); Assert.IsFalse(iterator.MoveNext()); }
public void Empty_Array___empty_result() { var sut = new DeadBandCompression(0.1); var data = Array.Empty <DataPoint>(); var iterator = sut.Process(data).GetEnumerator(); Assert.IsFalse(iterator.MoveNext()); }
public void Indexed_MoveNext_without_GetEnumerator___throws_InvalidOperation() { var sut = new DeadBandCompression(1); var data = RawDataForTrend().ToArray(); var iterator = sut.Process(data); Assert.Throws <InvalidOperationException>(() => iterator.MoveNext()); }
public void Empty_Array___empty_result() { var sut = new DeadBandCompression(0.1); var data = new DataPoint[0]; var actual = sut.Process(data); Assert.AreSame(Array.Empty <DataPoint>(), actual.ToArray()); Assert.AreEqual(0, actual.ToList().Count); }
public void Data_IList_with_maxDeltaX___OK() { var sut = new DeadBandCompression(0.1, 4d); var data = RawDataForMaxDelta().ToList().AsReadOnly(); var expected = ExpectedForMaxDelta().ToList(); var actual = sut.Process(data).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void One_DataPoint_List___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForMaxDelta().Take(1).ToList(); var expected = RawDataForMaxDelta().Take(1).ToList(); var actual = sut.Process(data).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void Data_given_as_IEnumerable___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend(); var expected = ExpectedForTrend().ToList(); var actual = sut.Process(data).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void Data_given_as_ArrayWrapper___OK() { var sut = new DeadBandCompression(0.1); var data = new ArrayWrapper <DataPoint>(RawDataForTrend().ToArray()); var expected = ExpectedForTrend().ToArray(); var actual = sut.Process(data).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void KnownData_given_as_IEnumerable___OK() { var sut = new DeadBandCompression(0.1); var data = KnownSequence(); var expected = KnownSequence().ToList(); var actual = sut.Process(data).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Two_DataPoint_IEnumerable___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForMaxDelta().Take(2); var expected = RawDataForMaxDelta().Take(2).ToList(); var actual = sut.Process(data).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Known_sequence_with_constant_part_ToArray____correct_result() { var sut = new DeadBandCompression(0.1); var data = KnownSequenceWithConstantPart(); var result = sut.Process(data); var expected = KnownSequenceWithConstantPartExpected(swingingDoor: false).ToArray(); var actual = result.ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void InstrumentPrecision_0_as_array___input_echoed() { var sut = new DeadBandCompression(0); var data = KnownSequence().ToArray(); var result = sut.Process(data); var expected = KnownSequence().ToArray(); var actual = result.ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Tow_Iterators_IEnumerable___different_Instances() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend(); var dummy = new List <DataPoint>(); DataPointIterator actual0 = sut.Process(data.Skip(1)); DataPointIterator actual1 = sut.Process(data.Take(1)); foreach (DataPoint dp in actual0) { dummy.Add(dp); } foreach (DataPoint dp in actual1) { dummy.Add(dp); } Assert.AreNotSame(actual0, actual1); }
public void Iterator_Caching_List___same_Instance() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend(); var dummy = new List <DataPoint>(); DataPointIterator actual0 = sut.Process(data.Skip(1).ToList()); foreach (DataPoint dp in actual0) { dummy.Add(dp); } DataPointIterator actual1 = sut.Process(data.Take(1).ToList()); foreach (DataPoint dp in actual1) { dummy.Add(dp); } Assert.AreSame(actual0, actual1); }
public void Empty_IEnumerable_foreach___empty_result() { var sut = new DeadBandCompression(0.1); var data = Empty(); int count = 0; foreach (DataPoint dp in sut.Process(data)) { count++; } Assert.AreEqual(0, count); }
public void Data_given_as_IEnumerable___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend(); var expected = ExpectedForTrend().ToList(); var actual0 = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual0.Add(dp); } var actual1 = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual1.Add(dp); } CollectionAssert.AreEqual(expected, actual0); CollectionAssert.AreEqual(expected, actual1); }
public void Two_DataPoints_IList___OK(IEnumerable <DataPoint> rawData, List <DataPoint> expectedData) { var sut = new DeadBandCompression(0.1); var data = rawData.ToList().AsReadOnly(); var expected = expectedData; var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Two_DataPoint_List___OK() { var sut = new DeadBandCompression(0.1); var data = KnownSequence().Take(2).ToList(); var expected = KnownSequence().Take(2).ToList(); var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Known_sequence_with_constant_part_foreach____correct_result() { var sut = new DeadBandCompression(0.1); var data = KnownSequenceWithConstantPart(); var result = sut.Process(data); var expected = KnownSequenceWithConstantPartExpected(swingingDoor: false).ToArray(); var actual = new List <DataPoint>(); foreach (DataPoint dp in result) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void InstrumentPrecision_0_as_array_foreach___input_echoed() { var sut = new DeadBandCompression(0); var data = KnownSequence().ToArray(); var result = sut.Process(data); var expected = KnownSequence().ToArray(); var actual = new List <DataPoint>(); foreach (DataPoint dp in result) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Two_DataPoint_IList___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForMaxDelta().Take(2).ToList().AsReadOnly(); var expected = RawDataForMaxDelta().Take(2).ToList(); var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Data_List_with_maxDeltaX___OK() { var sut = new DeadBandCompression(0.1, 4d); var data = RawDataForMaxDelta().ToList(); var expected = ExpectedForMaxDelta().ToList(); var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Data_given_as_IList___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend().ToList().AsReadOnly(); var expected = ExpectedForTrend().ToList(); var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
public void Known_sequence_as_array_foreach___correct_result() { var sut = new DeadBandCompression(0.1); var data = KnownSequence().ToArray(); var result = sut.Process(data); var expected = KnownSequence().ToArray(); var actual = new List <DataPoint>(); foreach (DataPoint dp in result) { actual.Add(dp); } CollectionAssert.AreEqual(expected, actual); }
//--------------------------------------------------------------------- static async Task Main() { using CancellationTokenSource cts = new CancellationTokenSource(); int counter = 0; Task t = Task.Run(() => { // A single instance can be re-used over and over again DeadBandCompression deadBand = new DeadBandCompression(0.1); SwingingDoorCompression swingingDoor = new SwingingDoorCompression(0.1); while (!cts.IsCancellationRequested) { s_compressed.Clear(); counter++; // Allocates a new instance of compression each iteration //DataPointIterator compressed = s_dataPoints//.Select(d => d) // //.DeadBandCompression(0.05) // .SwingingDoorCompression(0.1); //DataPointIterator compressed = compression.Process(s_dataPoints.Select(d => d)); DataPointIterator deadBandCompressed = deadBand.Process(s_dataPoints); DataPointIterator swingingDoorCompressed = swingingDoor.Process(deadBandCompressed); foreach (DataPoint item in swingingDoorCompressed) { s_compressed.Add(item); } Console.Write("."); } }, cts.Token); Console.WriteLine("any key to stop..."); Console.ReadKey(); cts.Cancel(); try { await t; } catch (OperationCanceledException) { } Console.WriteLine($"\n\nend -- counter: {counter}"); }
public void List_iterated_and_ToArray___OK() { var sut = new DeadBandCompression(0.1); var data = RawDataForTrend().ToList(); var expected = ExpectedForTrend().ToList(); DataPointIterator dataPointIterator = sut.Process(data); DataPointIterator enumerator = dataPointIterator.GetEnumerator(); enumerator.MoveNext(); enumerator.MoveNext(); var actual = dataPointIterator.ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Two_DataPoint_IEnumerable___OK(IEnumerable <DataPoint> rawData, List <DataPoint> expectedData) { var sut = new DeadBandCompression(0.1); var data = rawData; var expected = expectedData; var actual = new List <DataPoint>(); foreach (DataPoint dp in sut.Process(data)) { actual.Add(dp); } Print(expected, "expected"); Print(actual, "actual"); CollectionAssert.AreEqual(expected, actual); }