public void TestExportToCSVBlockExecute() { var signalBlock = new GenerateSignalBlock { Offset = 1.2, TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; var exportBlock = new ExportToCSVBlock { ColumnSeparator = "|", DecimalPlaces = 1, IncludeSignalNameInFirstColumn = true }; exportBlock.Execute(); Assert.IsNotNull(exportBlock.Name); Assert.IsNotNull(exportBlock.FilePath); Assert.IsNotNull(exportBlock.Description); Assert.IsNotNull(exportBlock.ProcessingType); signalBlock.ConnectTo(exportBlock); signalBlock.Execute(); var lines = File.ReadAllLines(Path.Combine(Utils.AssemblyDirectory, "output.csv")); Assert.AreEqual(1, lines.Length); Assert.AreEqual("|1.2|2.2|1.2|2.2|1.2", lines[0]); var exportBlock2 = (ExportToCSVBlock)exportBlock.Clone(); signalBlock.Cascade = false; signalBlock.ConnectTo(exportBlock2); signalBlock.Execute(); Assert.AreEqual(0, exportBlock2.OutputNodes.Count); signalBlock.Cascade = true; signalBlock.OutputNodes[0].Object = null; exportBlock2.Execute(); Assert.AreEqual(0, exportBlock2.OutputNodes.Count); }
public void TestBlockList() { var signalBlock1 = new GenerateSignalBlock { Cascade = false, Offset = 1, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1 }; var signalBlock2 = new GenerateSignalBlock { Cascade = false, Offset = 2, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1 }; var signalBlock3 = new GenerateSignalBlock { Offset = 3, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1 }; var convolutionBlock1 = new ConvolutionBlock(); var convolutionBlock2 = new ConvolutionBlock(); var blockList = new BlockList { signalBlock1, signalBlock2, signalBlock3, convolutionBlock1, convolutionBlock2 }; signalBlock1.ConnectTo(convolutionBlock1); signalBlock2.ConnectTo(convolutionBlock1); convolutionBlock1.ConnectTo(convolutionBlock2); signalBlock2.ConnectTo(convolutionBlock2); blockList.ExecuteAll(); Assert.AreEqual("4 20 45 78 111 114 103 74 33 18", convolutionBlock2.OutputNodes[0].Object.ToString(0)); convolutionBlock1 = new ConvolutionBlock(); convolutionBlock1.InputNodes.Clear(); signalBlock1.ConnectTo(convolutionBlock1); signalBlock1.Execute(); Assert.AreEqual(0, convolutionBlock1.OutputNodes[0].Object.Count); convolutionBlock1 = new ConvolutionBlock(); signalBlock1 = new GenerateSignalBlock(); signalBlock2.OutputNodes.Clear(); signalBlock2.ConnectTo(convolutionBlock1); signalBlock1.ConnectTo(convolutionBlock1); signalBlock1.Execute(); Assert.AreEqual(0, convolutionBlock1.OutputNodes[0].Object.Count); }
public void TestRelationalOperatorBlockTest() { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); var signalBlock1 = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; var signalBlock2 = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, Phase = 0.5, SamplingRate = 1, IgnoreLastSample = true }; var block = new RelationalOperatorBlock { Operation = WaveMath.RelationalOperatorEnum.GreaterThan }; block.Execute(); signalBlock1.Execute(); signalBlock2.Execute(); signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]); signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]); Assert.IsNotNull(block.Name); Assert.IsNotNull(block.Description); Assert.IsNotNull(block.ProcessingType); Assert.AreEqual("GreaterThan", block.GetAssemblyClassName()); block.Operand = RelationalOperatorBlock.OperandEnum.Signal; block.Execute(); Assert.AreEqual("0 1 0 1 0", block.OutputNodes[0].Object.ToString(0)); block.Operand = RelationalOperatorBlock.OperandEnum.PreviousSample; block.Operation = WaveMath.RelationalOperatorEnum.LessThan; block.Execute(); Assert.AreEqual("0 0 1 0 1", block.OutputNodes[0].Object.ToString(0)); block.Operand = RelationalOperatorBlock.OperandEnum.NextSample; block.Operation = WaveMath.RelationalOperatorEnum.LessThan; block.Execute(); Assert.AreEqual("1 0 1 0 0", block.OutputNodes[0].Object.ToString(0)); block.Operand = RelationalOperatorBlock.OperandEnum.StaticValue; block.Operation = WaveMath.RelationalOperatorEnum.GreaterOrEqualsThan; block.ScalarValue = 1; block.Execute(); Assert.AreEqual("0 1 0 1 0", block.OutputNodes[0].Object.ToString(0)); var block2 = (RelationalOperatorBlock)block.Clone(); block2.Operation = WaveMath.RelationalOperatorEnum.GreaterOrEqualsThan; block.OutputNodes[0].ConnectTo(block2.InputNodes[0]); signalBlock2.OutputNodes[0].ConnectTo(block2.InputNodes[1]); signalBlock1.Execute(); signalBlock2.Execute(); Assert.AreEqual("0 1 0 1 0", block2.OutputNodes[0].Object[0].ToString(0)); block.Cascade = false; block2 = (RelationalOperatorBlock)block.Clone(); block.OutputNodes[0].ConnectTo(block2.InputNodes[0]); block.Operand = RelationalOperatorBlock.OperandEnum.Signal; signalBlock1.Execute(); Assert.AreEqual(0, block2.OutputNodes[0].Object.Count); Assert.AreEqual("", block2.OutputNodes[0].Object.ToString(0)); signalBlock1 = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1, IgnoreLastSample = true }; signalBlock2 = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true }; signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]); signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]); signalBlock1.Execute(); signalBlock2.Execute(); signalBlock2.OutputNodes[0].Object.Add(new Signal(new double[] { 1, 2, 3, 4 })); block.Execute(); Assert.AreEqual("1 1 1 0 0", block.OutputNodes[0].Object[0].ToString(0)); signalBlock2.OutputNodes[0].Object.Clear(); block.Execute(); Assert.AreEqual(1, block.OutputNodes[0].Object.Count); Assert.AreEqual("1 1 1", block.OutputNodes[0].Object[0].ToString(0)); block2.InputNodes[1].ConnectingNode = null; block2.Operand = RelationalOperatorBlock.OperandEnum.Signal; block2.Execute(); Assert.AreEqual(0, block2.OutputNodes[0].Object.Count); block2 = (RelationalOperatorBlock)block.Clone(); block2.Operand = RelationalOperatorBlock.OperandEnum.Signal; block.ConnectTo(block2); signalBlock1.ConnectTo(block2); block2.Operand = RelationalOperatorBlock.OperandEnum.Signal; block2.Execute(); Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[0].ToString(0)); ((BlockOutputNode)block2.InputNodes[0].ConnectingNode).Object.Add(signalBlock1.OutputNodes[0].Object[0].Clone()); block2.Execute(); Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[0].ToString(0)); Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[1].ToString(0)); }
public void TestWaveletBlockExecute() { var signalBlock = new GenerateSignalBlock { TemplateName = "Binary", Start = 0, Finish = 10, SamplingRate = 1, IgnoreLastSample = true }; var waveletBlock = new DWTBlock { WaveletName = "db4|Daubechies 4", Level = 2, ExtensionMode = SignalExtension.ExtensionMode.SymmetricHalfPoint }; waveletBlock.Execute(); Assert.IsTrue(waveletBlock.WaveletNameList.Count > 0); Assert.AreEqual("db4|Daubechies 4", waveletBlock.WaveletName); signalBlock.OutputNodes[0].ConnectTo(waveletBlock.InputNodes[0]); Assert.IsNotNull(waveletBlock.Name); Assert.IsNotNull(waveletBlock.Description); Assert.IsNotNull(waveletBlock.ProcessingType); signalBlock.Execute(); Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", waveletBlock.OutputNodes[0].Object[0].ToString(1)); Assert.AreEqual("1.0 0.8 1.1 0.8 1.0 0.8 1.6", waveletBlock.OutputNodes[0].Object[1].ToString(1)); Assert.AreEqual("-0.2 -0.8 -0.7 -0.7 -0.7 0.2 0.8 0.7", waveletBlock.OutputNodes[1].Object[0].ToString(1)); Assert.AreEqual("-0.1 -0.4 0.0 -0.3 0.1 0.2 0.1", waveletBlock.OutputNodes[1].Object[1].ToString(1)); Assert.AreEqual(signalBlock.OutputNodes[0].Object.ToString(1), waveletBlock.OutputNodes[2].Object[0].ToString(1)); Assert.AreEqual(5, waveletBlock.OutputNodes[3].Object.Count); Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", waveletBlock.OutputNodes[3].Object[0].ToString(1)); Assert.AreEqual("-0.2 -0.8 -0.7 -0.7 -0.7 0.2 0.8 0.7", waveletBlock.OutputNodes[3].Object[1].ToString(1)); Assert.AreEqual("1.0 0.8 1.1 0.8 1.0 0.8 1.6", waveletBlock.OutputNodes[3].Object[2].ToString(1)); Assert.AreEqual("-0.1 -0.4 0.0 -0.3 0.1 0.2 0.1", waveletBlock.OutputNodes[3].Object[3].ToString(1)); Assert.AreEqual(signalBlock.OutputNodes[0].Object.ToString(1), waveletBlock.OutputNodes[3].Object[4].ToString(1)); var block2 = (DWTBlock)waveletBlock.Clone(); block2.WaveletName = "db4"; signalBlock.OutputNodes[0].ConnectTo(block2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", block2.OutputNodes[0].Object[0].ToString(1)); waveletBlock.Cascade = false; block2 = (DWTBlock)waveletBlock.Clone(); waveletBlock.OutputNodes[0].ConnectTo(block2.InputNodes[0]); signalBlock.Execute(); Assert.AreEqual(0, block2.OutputNodes[0].Object.Count); waveletBlock.Cascade = true; signalBlock.ConnectTo(waveletBlock); waveletBlock.ConnectTo(block2); waveletBlock.Execute(); Assert.AreEqual(4, block2.OutputNodes[0].Object.Count); try { waveletBlock.WaveletName = "nonono"; Assert.Fail("Exception not thrown!"); } catch (Exception) { Assert.IsTrue(true, "Exception thrown! Yeay!"); } }