public void TestExecuteRelationalOperationWithPreviousSample() { var array1 = new[] { 1.0, 3.1, 2.4, 2.1 }; var result = WaveMath.ExecuteRelationalOperationWithPreviousSample(WaveMath.RelationalOperatorEnum.LessThan, array1); Assert.IsTrue(TestUtils.SequenceEquals(result, new[] { 0.0, 0.0, 1.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 TestExecuteRelationalOperationPreviousSampleWithSignal() { var signal1 = new Signal(new[] { 1.0, 3.1, 2.4, 2.5 }); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 0.0, 0.0, 1.0, 0.0 }, WaveMath.ExecuteRelationalOperationWithPreviousSample(WaveMath.RelationalOperatorEnum.LessOrEqualsThan, signal1).Samples)); }