Exemple #1
0
    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))
Exemple #2
0
    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)
Exemple #3
0
    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))
Exemple #4
0
    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))
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
 def test_one_update_variance_nan(self):
     online = OnlineVariance()
     online.update(1)
     self.assertTrue(isnan(online.variance))