public void TestExecuteRelationalOperationWithStaticValue() { var array1 = new[] { 1.0, 3.1, 2.4, 2.0 }; var result = WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.LessOrEqualsThan, array1, 2); Assert.IsTrue(TestUtils.SequenceEquals(result, new[] { 1.0, 0.0, 0.0, 1.0 })); }
/// <summary> /// Executes the block /// </summary> public override void Execute() { SetOperationDescription(); var inputNode1 = InputNodes[0].ConnectingNode as BlockOutputNode; var inputNode2 = InputNodes[1].ConnectingNode as BlockOutputNode; if (inputNode1 == null || inputNode1.Object.Count == 0) { return; } OutputNodes[0].Object.Clear(); for (var i = 0; i < inputNode1.Object.Count; i++) { var signal1 = inputNode1.Object[i]; if (Operand == OperandEnum.StaticValue) { OutputNodes[0].Object.Add(WaveMath.ExecuteRelationalOperation(Operation, signal1, ScalarValue)); } else if (Operand == OperandEnum.Signal) { if (inputNode2 == null) { return; } Signal signal2; if (i < inputNode2.Object.Count) { signal2 = inputNode2.Object[i]; } else if (inputNode2.Object.Count > 0) { signal2 = inputNode2.Object[0]; } else { OutputNodes[0].Object.Add(WaveMath.ExecuteRelationalOperation(Operation, signal1, 0)); continue; } OutputNodes[0].Object.Add(WaveMath.ExecuteRelationalOperation(Operation, signal1, signal2)); } else if (Operand == OperandEnum.NextSample) { OutputNodes[0].Object.Add(WaveMath.ExecuteRelationalOperationWithNextSample(Operation, signal1)); } else if (Operand == OperandEnum.PreviousSample) { OutputNodes[0].Object.Add(WaveMath.ExecuteRelationalOperationWithPreviousSample(Operation, signal1)); } } if (Cascade && OutputNodes[0].ConnectingNode != null) { OutputNodes[0].ConnectingNode.Root.Execute(); } }
public void TestExecuteRelationalOperationWithSignals() { var signal1 = new Signal(new[] { 0.0, 0.0, 45.1, 10.2 }); var signal2 = new Signal(new[] { 0.0, 20.0, 0.1, 15.1 }); var signal3 = new Signal(new double[] { }); var signal4 = new Signal(null); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 1.0, 1.0, 0.0, 1.0 }, WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.LessOrEqualsThan, signal1, signal2).Samples)); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 1.0, 1.0, 0.0, 1.0 }, WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.LessOrEqualsThan, signal1, signal2, signal3, signal4).Samples)); Assert.IsNull(WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.GreaterThan, null, signal3, signal4)); }
public void TestExecuteRelationalOperationWithTwoArrays() { var array1 = new[] { 1.0, -3.1, 4.4, 8.5 }; var array2 = new[] { 1.0, 2.1, 3.4, 4.5 }; var result = WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.GreaterThan, array1, array2); Assert.IsTrue(TestUtils.SequenceEquals(result, new[] { 0.0, 0.0, 1.0, 1.0 })); array1 = new[] { 1.0, -3.1, 4.4 }; array2 = new[] { 1.0, 2.1, 3.4, 4.5 }; result = WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.GreaterThan, array1, array2); Assert.IsTrue(TestUtils.SequenceEquals(result, new[] { 0.0, 0.0, 1.0, 0.0 })); array1 = new[] { 1.0, -3.1, 4.4, 8.5 }; array2 = new[] { 1.0, 2.1, 3.4 }; result = WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.GreaterThan, array1, array2); Assert.IsTrue(TestUtils.SequenceEquals(result, new[] { 0.0, 0.0, 1.0, 0.0 })); }
public void TestExecuteRelationalOperationWithSignalAndStaticValue() { var signal1 = new Signal(new[] { 0.0, 20.0, 10.0, 10.2 }); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 1.0, 0.0, 1.0, 0.0 }, WaveMath.ExecuteRelationalOperation(WaveMath.RelationalOperatorEnum.LessOrEqualsThan, signal1, 10).Samples)); }