public void TestExecuteLogicOperationWithSignals() { 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[] { 0.0, 1.0, 1.0, 1.0 }, WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, signal1, signal2).Samples)); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 0.0, 1.0, 1.0, 1.0 }, WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, signal1, signal2, signal3, signal4).Samples)); Assert.IsNull(WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, null, signal3, signal4)); }
public void TestExecuteLogicOperation() { var x1 = new[] { 0.0, 0.0, 45.1, 10.2 }; var x2 = new[] { 0.0, 20.0, 0.1, 15.1 }; Assert.IsTrue(TestUtils.SequenceEquals(new[] { 0.0, 1.0, 1.0, 1.0 }, WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, x1, x2))); x1 = new[] { 0.0, 0.0, 45.1, 10.2, 1.0 }; x2 = new[] { 0.0, 20.0, 0.1, 15.1 }; Assert.IsTrue(TestUtils.SequenceEquals(new[] { 0.0, 1.0, 1.0, 1.0, 0.0 }, WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, x1, x2))); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 0.0, 1.0, 1.0, 1.0, 0.0 }, WaveMath.ExecuteLogicOperation(WaveMath.LogicalOperationEnum.Or, x2, x1))); }
/// <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 || inputNode2 == null) { return; } if (inputNode2.Object.Count > inputNode1.Object.Count) { inputNode1 = InputNodes[1].ConnectingNode as BlockOutputNode; inputNode2 = InputNodes[0].ConnectingNode as BlockOutputNode; } OutputNodes[0].Object.Clear(); for (var i = 0; i < inputNode1.Object.Count; i++) { var signal1 = inputNode1.Object[i]; 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(signal1.Clone()); continue; } OutputNodes[0].Object.Add(WaveMath.ExecuteLogicOperation(Operation, signal1, signal2)); } if (Cascade && OutputNodes[0].ConnectingNode != null) { OutputNodes[0].ConnectingNode.Root.Execute(); } }