def testVariance_ShortList_UsesPopulationVariance(self):
     self.assertAlmostEqual(6.25, sum([12.25, 0.25, 0.25, 12.25]) / 4.0)
     self.assertAlmostEqual(6.25, math_utils.Variance([-3, 0, 1, 4]))
 def testVariance_EmptyList_ReturnsNan(self):
     self.assertTrue(math.isnan(math_utils.Variance([])))
 def testVariance_OneValue_ReturnsZero(self):
     self.assertEqual(0.0, math_utils.Variance([0]))
     self.assertEqual(0.0, math_utils.Variance([4.3]))
Beispiel #4
0
def _MakeSampleStats(sample):
    """Calculates relevant stats for a sample and makes a SampleStats object."""
    return SampleStats(math_utils.Mean(sample), math_utils.Variance(sample),
                       len(sample))