public void testWeightedAndStdDev() { WeightedRunningAverageAndStdDev runningAverage = new WeightedRunningAverageAndStdDev(); Assert.AreEqual(0, runningAverage.GetCount()); Assert.True(Double.IsNaN(runningAverage.GetAverage())); Assert.True(Double.IsNaN(runningAverage.GetStandardDeviation())); runningAverage.AddDatum(1.0); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.True(Double.IsNaN(runningAverage.GetStandardDeviation())); runningAverage.AddDatum(1.0, 2.0); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(0.0, runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(8.0, 0.5); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(10.5), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(-4.0); Assert.AreEqual(2.0/3.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(15.75), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.RemoveDatum(-4.0); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(10.5), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.RemoveDatum(2.0, 2.0); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(31.5), runningAverage.GetStandardDeviation(), EPSILON); }
public void testWeightedAndStdDev() { WeightedRunningAverageAndStdDev runningAverage = new WeightedRunningAverageAndStdDev(); Assert.AreEqual(0, runningAverage.GetCount()); Assert.True(Double.IsNaN(runningAverage.GetAverage())); Assert.True(Double.IsNaN(runningAverage.GetStandardDeviation())); runningAverage.AddDatum(1.0); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.True(Double.IsNaN(runningAverage.GetStandardDeviation())); runningAverage.AddDatum(1.0, 2.0); Assert.AreEqual(1.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(0.0, runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(8.0, 0.5); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(10.5), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.AddDatum(-4.0); Assert.AreEqual(2.0 / 3.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(15.75), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.RemoveDatum(-4.0); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(10.5), runningAverage.GetStandardDeviation(), EPSILON); runningAverage.RemoveDatum(2.0, 2.0); Assert.AreEqual(2.0, runningAverage.GetAverage(), EPSILON); Assert.AreEqual(Math.Sqrt(31.5), runningAverage.GetStandardDeviation(), EPSILON); }