public void testStddev() { IRunningAverageAndStdDev runningAverage = new FullRunningAverageAndStdDev(); Assert.AreEqual(0, runningAverage.GetCount()); Assert.True(Double.IsNaN(runningAverage.GetAverage())); runningAverage.AddDatum(1.0); Assert.AreEqual(1, runningAverage.GetCount()); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.True(Double.IsNaN(runningAverage.GetStandardDeviation())); runningAverage.AddDatum(1.0); Assert.AreEqual(2, runningAverage.GetCount()); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(0.0, runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(7.0); Assert.AreEqual(3, runningAverage.GetCount()); Assert.AreEqual(3.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(3.464101552963257, runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(5.0); Assert.AreEqual(4, runningAverage.GetCount()); Assert.AreEqual(3.5, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(3.0, runningAverage.GetStandardDeviation(), EPSILON); }
public void testFull() { IRunningAverageAndStdDev average = new FullRunningAverageAndStdDev(); Assert.AreEqual(0, average.GetCount()); Assert.True(Double.IsNaN(average.GetAverage())); Assert.True(Double.IsNaN(average.GetStandardDeviation())); average.AddDatum(6.0); Assert.AreEqual(1, average.GetCount()); Assert.AreEqual(6.0, average.GetAverage(), EPSILON); Assert.True(Double.IsNaN(average.GetStandardDeviation())); average.AddDatum(6.0); Assert.AreEqual(2, average.GetCount()); Assert.AreEqual(6.0, average.GetAverage(), EPSILON); Assert.AreEqual(0.0, average.GetStandardDeviation(), EPSILON); average.RemoveDatum(6.0); Assert.AreEqual(1, average.GetCount()); Assert.AreEqual(6.0, average.GetAverage(), EPSILON); Assert.True(Double.IsNaN(average.GetStandardDeviation())); average.AddDatum(-4.0); Assert.AreEqual(2, average.GetCount()); Assert.AreEqual(1.0, average.GetAverage(), EPSILON); Assert.AreEqual(5.0 * 1.4142135623730951, average.GetStandardDeviation(), EPSILON); average.RemoveDatum(4.0); Assert.AreEqual(1, average.GetCount()); Assert.AreEqual(-2.0, average.GetAverage(), EPSILON); Assert.True(Double.IsNaN(average.GetStandardDeviation())); }