def test_100_integers_update_variance(self): test_set = list(range(0, 100)) online = OnlineVariance() for number in test_set: online.update(number) self.assertEqual(online.variance, variance(test_set))
def test_100_floats_update_variance(self): test_set = [i / 3 for i in range(0, 100)] online = OnlineVariance() for number in test_set: online.update(number) #note: this test will fail on the final the test_set if `places` > 12 self.assertAlmostEqual(online.variance, variance(test_set), places=12)
def test_two_update_variance(self): test_sets = [[0, 2], [1, 1], [1, 2], [-1, 1], [10.5, 20]] for test_set in test_sets: online = OnlineVariance() for number in test_set: online.update(number) self.assertEqual(online.variance, variance(test_set))
def test_two_update_variance(self): batches = [[0, 2], [1, 1], [1, 2], [-1, 1], [10.5, 20]] for batch in batches: online = OnlineVariance() for number in batch: online.update(number) self.assertEqual(online.variance, variance(batch))
def test_three_update_variance(self): test_sets = [ [0, 2, 4], [1, 1, 1], [1,2,3], [-1,1,-1], [10.5,20,29.5] ] for test_set in test_sets: online = OnlineVariance() for number in test_set: online.update(number) #note: this test will fail on the final the test_set if `places` > 15 self.assertAlmostEqual(online.variance, variance(test_set), places = 15)
def test_three_update_variance(self): batches = [[0, 2, 4], [1, 1, 1], [1, 2, 3], [-1, 1, -1], [10.5, 20, 29.5]] for batch in batches: online = OnlineVariance() for number in batch: online.update(number) #note: this test will fail on the final the batch if `places` > 15 self.assertAlmostEqual(online.variance, variance(batch), places=15)
def test_one_update_variance_nan(self): online = OnlineVariance() online.update(1) self.assertTrue(isnan(online.variance))