static void Main(string[] args) { Random rnd = new Random(); //Creating an array with values, corresponding to linear function with added white noise const int n = 360; double[] array = new double[n]; for (int i = 0; i < n; i++) { double noise = 0; noise = (double)rnd.Next(Int32.MinValue, Int32.MaxValue) / (Int32.MaxValue / rnd.Next(1, 30)); //if (i % 10 == 0) noise = 100; //Noise for tukey filter testing array[i] = (double)i + noise; } BSDataObject source = new BSDataObject(array, "SourceData"); IVisualizer visualizer = new SimpleVisualizationHandler(); visualizer.AddToGraph(source); visualizer.AddToGraph(new MedianPreprocessor().Process(source)); using (var ms = new MemoryStream(n * (sizeof(double) + sizeof(char)))) { StreamWriter sw = new StreamWriter(ms); for (int i = 0; i < n; i++) { array[i] = 80 * Math.Sin((double)i * Math.PI / 180.0); sw.WriteLine(array[i]); } sw.Flush(); ms.Position = 0; BSDataObject target = DataObjectSupplier.GetDataObjectForStream(ms, "Sine from memory stream"); visualizer.AddToGraph(target); } (visualizer as SimpleVisualizationHandler)._TestShow(); }
/// <summary> /// Creates a new DataObject using data in file at <paramref name="iFilePath"/> path. /// </summary> /// <param name="iFilePath">A path to the file with data - relative or absolute.</param> /// <exception cref="System.ArgumentNullException"/> /// <exception cref="System.UnauthorizedAccessException"/> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.IO.FileNotFoundException"/> /// <exception cref="System.IO.PathTooLongException"/> /// <exception cref="System.FormatException"/> /// <returns>New Dataobject.</returns> public static BSDataObject DataObjectFromFile(string iFilePath) { BSDataObject result = null; using (FileStream sr = new FileStream(iFilePath, FileMode.Open)) { result = DataObjectSupplier.GetDataObjectForStream(sr); } return(result); }
public void GetBSDataObjectForStreamTest() { const int numberOfPoints = 360; double[] expectedArray = new double[numberOfPoints]; string fileName = Path.GetTempFileName(); Random rnd = new Random(); //Create a file with random values in it using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate)) { var streamWriter = new StreamWriter(fileStream); for (int i = 0; i < numberOfPoints; i++) { expectedArray[i] = rnd.Next(); streamWriter.WriteLine(expectedArray[i]); } streamWriter.Flush(); } //Get BSDataObject from this file using (var fileStream = new FileStream(fileName, FileMode.Open)) { BSDataObject target = DataObjectSupplier.GetDataObjectForStream(fileStream); CollectionAssert.AreEqual(expectedArray, target.DataArray); } File.Delete(fileName); //The same for memory stream using (var memoryStream = new MemoryStream(numberOfPoints * (sizeof(double) + sizeof(char)))) { StreamWriter streamWriter = new StreamWriter(memoryStream); for (int i = 0; i < numberOfPoints; i++) { expectedArray[i] = Math.Sin((double)i * Math.PI / 180.0); streamWriter.WriteLine(expectedArray[i]); } streamWriter.Flush(); memoryStream.Position = 0; BSDataObject target = DataObjectSupplier.GetDataObjectForStream(memoryStream); CheckTwoOrderedArrays(expectedArray, target.DataArray); } }