public void TestFFTBlockExecute() { //Test with periodic signal var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 7, SamplingRate = 1, Offset = 1.1 }; var fftBlock = new FFTBlock(); fftBlock.Execute(); signalBlock.OutputNodes[0].ConnectTo(fftBlock.InputNodes[0]); Assert.IsNotNull(fftBlock.Name); Assert.IsNotNull(fftBlock.Description); Assert.IsNotNull(fftBlock.ProcessingType); signalBlock.Execute(); Assert.AreEqual("3.2 0.0 0.0 0.0", fftBlock.OutputNodes[0].Object.ToString(1)); //Test cascade var scalarBlock = new ScalarOperationBlock { Value = 1, Operation = WaveMath.OperationEnum.Sum }; fftBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual("4.2 1.0 1.0 1.0", scalarBlock.OutputNodes[0].Object.ToString(1)); //Test when cascade is false fftBlock.Cascade = false; var fftBlock2 = (FFTBlock)fftBlock.Clone(); fftBlock.OutputNodes[0].ConnectTo(fftBlock2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, fftBlock2.OutputNodes[0].Object.Count); }
public void TestConnection() { var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; var sumBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; var multBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Multiply, Value = 2 }; var signalOutputNode = signalBlock.OutputNodes[0]; var sumInputNode = sumBlock.InputNodes[0]; var sumOutputNode = sumBlock.OutputNodes[0]; var multInputNode = multBlock.InputNodes[0]; var multOutputNode = multBlock.OutputNodes[0]; signalOutputNode.ConnectTo(ref sumInputNode); sumOutputNode.ConnectTo(ref multInputNode); signalBlock.Execute(); var outputText = multOutputNode.Object.ToString(0); Assert.AreEqual("3 5 3 5 3", outputText); }
public void TestScalarOperationBlockExecute() { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; var scalarBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; scalarBlock.Execute(); signalBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); Assert.IsNotNull(scalarBlock.Name); Assert.IsNotNull(scalarBlock.Description); Assert.IsNotNull(scalarBlock.ProcessingType); signalBlock.Execute(); Assert.AreEqual("1.5 2.5 1.5 2.5 1.5", scalarBlock.OutputNodes[0].Object.ToString(1)); scalarBlock.Operation = WaveMath.OperationEnum.Multiply; signalBlock.Execute(); Assert.AreEqual("0.0 1.5 0.0 1.5 0.0", scalarBlock.OutputNodes[0].Object.ToString(1)); Assert.AreEqual("ScalarMultiply", scalarBlock.GetAssemblyClassName()); scalarBlock.Operation = WaveMath.OperationEnum.Subtract; signalBlock.Execute(); Assert.AreEqual("-1.5 -0.5 -1.5 -0.5 -1.5", scalarBlock.OutputNodes[0].Object.ToString(1)); scalarBlock.Operation = WaveMath.OperationEnum.Divide; signalBlock.Execute(); Assert.AreEqual("0.00 0.67 0.00 0.67 0.00", scalarBlock.OutputNodes[0].Object.ToString(2)); var scalarBlock2 = (ScalarOperationBlock)scalarBlock.Clone(); scalarBlock2.Operation = WaveMath.OperationEnum.Sum; scalarBlock2.Value = 3.1; scalarBlock.OutputNodes[0].ConnectTo(scalarBlock2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual("3.10 3.77 3.10 3.77 3.10", scalarBlock2.OutputNodes[0].Object.ToString(2)); scalarBlock.Cascade = false; scalarBlock2 = (ScalarOperationBlock)scalarBlock.Clone(); scalarBlock.OutputNodes[0].ConnectTo(scalarBlock2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, scalarBlock2.OutputNodes[0].Object.Count); }
public void TestSignalFromCSVBlockExecute() { var csvBlock = new ImportFromCSVBlock { IgnoreFirstRow = true, SignalNameInFirstColumn = true }; csvBlock.Execute(); Assert.IsNotNull(csvBlock.Name); Assert.IsNotNull(csvBlock.Description); Assert.IsNotNull(csvBlock.ProcessingType); Assert.AreEqual(3, csvBlock.OutputNodes[0].Object.Count); Assert.AreEqual("Signal1", csvBlock.OutputNodes[0].Object[0].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 1.1, 9.12355, 0.123456, 0 }, csvBlock.OutputNodes[0].Object[0].Samples)); Assert.AreEqual("Signal2", csvBlock.OutputNodes[0].Object[1].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { -1.1, 0.123456, 0 }, csvBlock.OutputNodes[0].Object[1].Samples)); Assert.AreEqual("Signal3", csvBlock.OutputNodes[0].Object[2].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { -1.1, 9.12355, 0.123456, 0 }, csvBlock.OutputNodes[0].Object[2].Samples)); csvBlock.Cascade = false; var scalarBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; csvBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); csvBlock.Execute(); Assert.AreEqual(0, scalarBlock.OutputNodes[0].Object.Count); var csvBlock2 = (ImportFromCSVBlock)csvBlock.Clone(); csvBlock2.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); csvBlock2.Cascade = true; csvBlock2.Execute(); Assert.AreEqual(3, csvBlock2.OutputNodes[0].Object.Count); csvBlock2.FilePath = "nonononono.csv"; csvBlock2.Cascade = true; csvBlock2.Execute(); Assert.AreEqual(0, csvBlock2.OutputNodes[0].Object.Count); csvBlock2.FilePath = "waveletstudio.tests.dll"; csvBlock2.Cascade = true; csvBlock2.Execute(); Assert.AreEqual(0, csvBlock2.OutputNodes[0].Object.Count); }
public void TestGenerateSignalBlockExecute() { var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; signalBlock.Execute(); var newSignal = (GenerateSignalBlock)signalBlock.Clone(); newSignal.Finish = 6; newSignal.Execute(); Assert.IsNotNull(signalBlock.Name); Assert.AreEqual("Binary", signalBlock.GetAssemblyClassName()); Assert.AreEqual("A=1, F=60, φ=0, D=0; x=0...5, fs=1", signalBlock.Description); Assert.IsNotNull(signalBlock.ProcessingType); Assert.AreNotSame(signalBlock.OutputNodes[0], newSignal.OutputNodes[0]); Assert.AreNotSame(signalBlock.OutputNodes[0].Object, newSignal.OutputNodes[0].Object); Assert.AreEqual("0.0 1.0 0.0 1.0 0.0 1.0", newSignal.OutputNodes[0].Object.ToString(1)); Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", signalBlock.OutputNodes[0].Object.ToString(1)); signalBlock.Cascade = false; var scalarBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; signalBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, scalarBlock.OutputNodes[0].Object.Count); try { //force exception signalBlock.TemplateName = "Nonono"; Assert.Fail("Exception not thrown!"); } catch (Exception) { Assert.IsTrue(true, "Exception thrown! Yeay!"); } }
public void TestRampBlockExecute() { var signalBlock = new RampFunctionBlock { Start = 0, Finish = 5, RampStart = 1, RampFinish = 3, SamplingInterval = 1, SamplingRate = 1, Amplitude = 2, Offset = 1, ReturnToZero = true }; signalBlock.Execute(); var newSignal = (RampFunctionBlock)signalBlock.Clone(); newSignal.Finish = 6; newSignal.ReturnToZero = false; newSignal.Execute(); Assert.IsNotNull(signalBlock.Name); Assert.IsNotNull(signalBlock.Description); Assert.IsNotNull(signalBlock.ProcessingType); Assert.AreNotSame(signalBlock.OutputNodes[0], newSignal.OutputNodes[0]); Assert.AreNotSame(signalBlock.OutputNodes[0].Object, newSignal.OutputNodes[0].Object); Assert.AreEqual("1 1 3 5 5 5 5", newSignal.OutputNodes[0].Object.ToString(0)); Assert.AreEqual("1 1 3 5 1 1", signalBlock.OutputNodes[0].Object.ToString(0)); signalBlock.Cascade = false; var scalarBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; signalBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, scalarBlock.OutputNodes[0].Object.Count); signalBlock.Cascade = true; signalBlock.Execute(); Assert.IsNotNull(scalarBlock.OutputNodes[0].Object[0]); Assert.AreEqual("2.5 2.5 4.5 6.5 2.5 2.5", scalarBlock.OutputNodes[0].Object.ToString(1)); signalBlock.IgnoreLastSample = true; signalBlock.SamplingRate = 0; signalBlock.Execute(); Assert.AreEqual("1 1 3 5 1", signalBlock.OutputNodes[0].Object.ToString(0)); }
public void TestImportFromTextBlockExecute() { var textBlock = new ImportFromTextBlock { Text = "name,s1,s2,s3,s4\r\nSignal1, 1.1, 9.12355, 0.123456, 0\r\nSignal2, -1.1, asdf, 0.123456, 0\r\nSignal3, -1.1, 9.12355, 0.123456, 0\r\nSignal4\r\n\r\n", SignalNameInFirstColumn = true }; textBlock.Execute(); Assert.IsNotNull(textBlock.Name); Assert.IsNotNull(textBlock.Description); Assert.IsNotNull(textBlock.ProcessingType); Assert.AreEqual(3, textBlock.OutputNodes[0].Object.Count); Assert.AreEqual("Signal1", textBlock.OutputNodes[0].Object[0].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { 1.1, 9.12355, 0.123456, 0 }, textBlock.OutputNodes[0].Object[0].Samples)); Assert.AreEqual("Signal2", textBlock.OutputNodes[0].Object[1].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { -1.1, 0.123456, 0 }, textBlock.OutputNodes[0].Object[1].Samples)); Assert.AreEqual("Signal3", textBlock.OutputNodes[0].Object[2].Name); Assert.IsTrue(TestUtils.SequenceEquals(new[] { -1.1, 9.12355, 0.123456, 0 }, textBlock.OutputNodes[0].Object[2].Samples)); textBlock.Cascade = false; var scalarBlock = new ScalarOperationBlock { Operation = WaveMath.OperationEnum.Sum, Value = 1.5 }; textBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); textBlock.Execute(); Assert.AreEqual(0, scalarBlock.OutputNodes[0].Object.Count); var textBlock2 = (ImportFromTextBlock)textBlock.Clone(); textBlock2.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); textBlock2.Cascade = true; textBlock2.Execute(); Assert.AreEqual(3, textBlock2.OutputNodes[0].Object.Count); textBlock.Text = null; textBlock.Execute(); Assert.AreEqual(0, textBlock.OutputNodes[0].Object.Count); }
public void TestIFFTBlockExecute() { var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 31, SamplingRate = 1, Offset = 1.1 }; var fftBlock = new FFTBlock(); var ifftBlock = new IFFTBlock(); ifftBlock.Execute(); signalBlock.OutputNodes[0].ConnectTo(fftBlock.InputNodes[0]); fftBlock.OutputNodes[1].ConnectTo(ifftBlock.InputNodes[0]); Assert.IsNotNull(ifftBlock.Name); Assert.IsNotNull(ifftBlock.Description); Assert.IsNotNull(ifftBlock.ProcessingType); signalBlock.Execute(); Assert.AreEqual("1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1", ifftBlock.OutputNodes[0].Object.ToString(1)); //Test cascade var scalarBlock = new ScalarOperationBlock { Value = 1, Operation = WaveMath.OperationEnum.Sum }; ifftBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual("2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1", scalarBlock.OutputNodes[0].Object.ToString(1)); //Test when cascade is false fftBlock.Cascade = false; var ifftBlock2 = (IFFTBlock)ifftBlock.Clone(); ifftBlock.OutputNodes[0].ConnectTo(ifftBlock2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, ifftBlock2.OutputNodes[0].Object.Count); ifftBlock2.Cascade = false; ifftBlock2.Execute(); Assert.IsNotNull(ifftBlock2.OutputNodes[0].Object[0]); }
public void TestGlobalizedObject() { var block = new DWTBlock(); Assert.AreEqual(typeof(DWTBlock).FullName, block.GetClassName()); Assert.IsTrue(block.GetAttributes().Count > 0); Assert.IsNull(block.GetComponentName()); Assert.IsNotNull(block.GetConverter()); Assert.IsNull(block.GetDefaultEvent()); Assert.IsNull(block.GetDefaultProperty()); Assert.IsNull(block.GetEditor(typeof(DWTBlock))); Assert.AreEqual(0, block.GetEvents().Count); Assert.IsTrue(block.GetProperties().Count > 0); Assert.IsFalse(block.CausesRefresh); Assert.AreEqual(block, block.GetPropertyOwner(new PropertyDescriptorMock("WaveletName", new Attribute[] { }))); block = new DWTBlock(); Assert.AreEqual(0, block.GetEvents(new Attribute[] {}).Count); Assert.IsTrue(block.GetProperties(new Attribute[] { }).Count > 0); var block2 = new ScalarOperationBlock(); Assert.IsTrue(block2.CausesRefresh); }