/// <summary> /// Get the average of a dataset and format it to be human readable. /// </summary> /// <param name="ds">The dataset to calculate</param> /// <param name="builder">The StringBuilder to output to</param> public static void OutputCalculation(MovingAverageDS ds, StringBuilder builder) { double[] output = MovingAverage.GetMovingAverage(ds.windowSize, ds.data); builder.Append("Name: "); builder.AppendLine(ds.name); builder.Append("Window Size: "); builder.AppendLine(ds.windowSize.ToString()); builder.Append("Data: "); ArrayToString(ds.data, builder); builder.AppendLine(); builder.Append("Averages: "); ArrayToString(output, builder); builder.AppendLine(); }
public void Should_retun_the_moving_average_for_the_given_array_in_a_k_window(int k, double[] arr, double[] expected) { var actual = MovingAverage.GetMovingAverage(arr, k); var i = 0; foreach (var d in actual) { Assert.Equal(expected[i], d, 1); i++; } }
/// <summary> /// A quick test of the averaging algorithms. Use the project /// "Moving Averages" instead. /// </summary> /// <param name="args"></param> static void Main(string[] args) { double[] data = { 0, 1, -2, 3, -4, 5, -6, 7, -8, 9 }; int windowSize = 5; double[] output = MovingAverage.GetMovingAverage(windowSize, data); Console.WriteLine("{0,-10} {1,4} {2,10}", "Position", "Data", "Output"); // Display output for (int i = 0; i < data.Length; i++) { Console.WriteLine("{0,-10} {1,4} {2,10:0.##}", i, data[i], output[i]); } Console.In.Read(); }