Beispiel #1
0
    def test_add(self):
        bernoulli_one = Bernoulli(0.2)
        bernoulli_two = Bernoulli(0.2)
        bernoulli_sum = bernoulli_one + bernoulli_two

        self.assertEqual(bernoulli_sum.p, 0.2)
        self.assertEqual(bernoulli_sum.n, 2)
Beispiel #2
0
 def setUp(self):
     self.bernoulli = Bernoulli(0.3)
     self.bernoulli.read_data_file('numbers_bernoulli.txt')
Beispiel #3
0
class TestBernoulliClass(unittest.TestCase):
    def setUp(self):
        self.bernoulli = Bernoulli(0.3)
        self.bernoulli.read_data_file('numbers_bernoulli.txt')

    def test_initialization(self):
        self.assertEqual(self.bernoulli.p, 0.3, 'p value incorrect')

    def test_readdata(self):
        self.assertEqual(self.bernoulli.data, [1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                         'data not read in correctly')

    def test_calculatemean(self):
        self.bernoulli.calculate_mean()
        self.assertEqual(self.bernoulli.mean, 0.3)

    def test_calculatestdev(self):
        stdev = self.bernoulli.calculate_stdev()
        self.assertEqual(stdev, 0.46)

    def test_replace_stats_with_data(self):
        p = self.bernoulli.replace_stats_with_data()
        self.assertEqual(round(p, 2), 0.17, 'p value not correct after reading data')

    def test_pdf(self):
        self.assertEqual(self.bernoulli.calculate_pdf(0, 1), 0.7)
        self.assertEqual(self.bernoulli.calculate_pdf(1, 1), 0.3)

        self.bernoulli.replace_stats_with_data()
        self.assertEqual(self.bernoulli.calculate_pdf(0), 0.83)
        self.assertEqual(self.bernoulli.calculate_pdf(1), 0.17)

    def test_cdf(self):
        self.assertEqual(self.bernoulli.calculate_cdf(0.5, 1), 0.7)

        self.bernoulli.replace_stats_with_data()

        self.assertEqual(self.bernoulli.calculate_cdf(2, 1), 1.0)

    def test_add(self):
        bernoulli_one = Bernoulli(0.2)
        bernoulli_two = Bernoulli(0.2)
        bernoulli_sum = bernoulli_one + bernoulli_two

        self.assertEqual(bernoulli_sum.p, 0.2)
        self.assertEqual(bernoulli_sum.n, 2)