Exemplo n.º 1
0
    def test_negation_of_estimate(self) -> None:
        a = StatisticalEstimate(1, 2)

        actual = -a
        expected = StatisticalEstimate(-1, 2)

        self.assertEqual(actual, expected)
Exemplo n.º 2
0
    def test_division_by_scalar(self) -> None:
        a = StatisticalEstimate(1, 2)

        r_actual = a / 2
        expected = StatisticalEstimate(1 / 2, 1)

        self.failUnlessRaises(Exception, lambda: 2 / a)
        self.assertEqual(r_actual, expected)
Exemplo n.º 3
0
    def test_subtraction_of_estimate(self) -> None:
        a = StatisticalEstimate(1, 2)
        b = StatisticalEstimate(1, 3)

        actual = a - b
        expected = StatisticalEstimate(0, sqrt(4 + 9))

        self.assertEqual(actual, expected)
Exemplo n.º 4
0
    def test_addition_of_estimate(self) -> None:
        a = StatisticalEstimate(1, 2)
        b = StatisticalEstimate(1, 3)

        actual = a + b
        expected = StatisticalEstimate(2, sqrt(4 + 9))

        self.assertEqual(actual, expected)
Exemplo n.º 5
0
    def test_addition_of_estimate_nan(self) -> None:
        a = StatisticalEstimate(1, 2)
        b = StatisticalEstimate(1, float('nan'))

        actual = a + b
        expected = StatisticalEstimate(2, float('nan'))

        self.assertEqual(actual, expected)
Exemplo n.º 6
0
    def test_multiplication_by_scalar(self) -> None:
        a = StatisticalEstimate(1, 2)

        l_actual = 2 * a
        r_actual = a * 2
        expected = StatisticalEstimate(2, 4)

        self.assertEqual(l_actual, expected)
        self.assertEqual(r_actual, expected)
Exemplo n.º 7
0
    def test_addition_of_scalar(self) -> None:
        a = StatisticalEstimate(1, 2)

        l_actual = 2.2 + a
        r_actual = a + 2.2
        expected = StatisticalEstimate(3.2, 2)

        self.assertEqual(l_actual, expected)
        self.assertEqual(r_actual, expected)
Exemplo n.º 8
0
    def test_subtraction_of_scalar(self) -> None:
        a = StatisticalEstimate(1, 2)

        l_actual = 2.2 - a
        r_actual = a - 2.2
        l_expected = StatisticalEstimate(+1.2, 2)
        r_expected = StatisticalEstimate(-1.2, 2)

        self.assertEqual(l_actual, l_expected)
        self.assertEqual(r_actual, r_expected)
Exemplo n.º 9
0
    def test_sum(self) -> None:

        a1 = StatisticalEstimate(1, 2)
        a2 = StatisticalEstimate(2, 3)
        a3 = StatisticalEstimate(3, 4)
        a4 = StatisticalEstimate(4, 5)

        actual = a1 + a2 + a3 + a4

        self.assertEqual(actual.estimate, sum([1, 2, 3, 4]))
        self.assertEqual(actual.standard_error, sqrt(sum([4, 9, 16, 25])))
Exemplo n.º 10
0
    def test_statistics_mean_2(self) -> None:

        a = StatisticalEstimate(1.1, 2.1)

        actual = mean([a, a, a, a])  #type: ignore

        self.assertEqual(actual.estimate, 1.1)
        self.assertEqual(actual.standard_error, 2.1 / sqrt(4))
Exemplo n.º 11
0
    def test_direct_mean(self) -> None:

        a = StatisticalEstimate(1, 2)

        actual = (a + a + a + a) / 4

        self.assertEqual(actual.estimate, 1)
        self.assertEqual(actual.standard_error, 2 / sqrt(4))
Exemplo n.º 12
0
    def test_weighted_mean(self) -> None:

        a1 = StatisticalEstimate(1, 2)
        a2 = StatisticalEstimate(2, 3)
        a3 = StatisticalEstimate(3, 4)
        a4 = StatisticalEstimate(4, 5)

        w1 = 1
        w2 = 2
        w3 = 3
        w4 = 4

        actual = (w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4) / (w1 + w2 + w3 + w4)

        expected_estimate = (1 + 4 + 9 + 16) / 10
        expected_standard_error = sqrt(
            (1 * 4 + 4 * 9 + 9 * 16 + 16 * 25) / 100)

        self.assertEqual(actual.estimate, expected_estimate)
        self.assertEqual(actual.standard_error, expected_standard_error)
Exemplo n.º 13
0
    def test_pandas_mean(self) -> None:

        check_pandas_support("coba.tests.test_statistics.test_pandas_mean")
        import pandas as pd  #type: ignore #ignored so that mypy won't complain

        a = StatisticalEstimate(1, 2)
        df = pd.DataFrame({'a': [a, a, a, a]})

        actual = df['a'].mean()

        self.assertEqual(actual, 1)
Exemplo n.º 14
0
    def test_fraction_1(self) -> None:
        e = StatisticalEstimate(1.1, 1.1)
        f = Fraction(e)

        self.assertIsInstance(f.numerator, Rational)
        self.assertIsInstance(f.denominator, Rational)
Exemplo n.º 15
0
    def test_from_statistical_estimate(self):
        a = StatisticalEstimate(1, 1)
        b = BatchMeanEstimator(a)

        self.assertEqual(b.estimate, 1)
        self.assertEqual(b.standard_error, 1)