Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_gaussian.py 1.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  1. import unittest
  2. from distributions.gaussian import Gaussian
  3. class TestGaussianClass(unittest.TestCase):
  4. def setUp(self):
  5. self.gaussian = Gaussian(35, 6)
  6. self.gaussian.read_data_file('data/random.txt')
  7. def test_initialization(self):
  8. self.assertEqual(self.gaussian.mean, 35, 'incorrect mean')
  9. self.assertEqual(self.gaussian.stdev, 6, 'incorrect standard deviation')
  10. def test_readdata(self):
  11. self.assertEqual(self.gaussian.data,\
  12. [10, 23, 45, 12, 23, 45, 67, 100, 300, 250, 45, 68, 29, 59, 239, 934, 12, 321, 12, 32, 1], 'data not read in correctly')
  13. def test_meancalculation(self):
  14. self.assertEqual(self.gaussian.calculate_mean(),\
  15. sum(self.gaussian.data) / float(len(self.gaussian.data)), 'calculated mean not as expected')
  16. def test_stdevcalculation(self):
  17. self.assertEqual(round(self.gaussian.calculate_stdev(), 2), 210.77, 'sample standard deviation incorrect')
  18. self.assertEqual(round(self.gaussian.calculate_stdev(0), 2), 205.69, 'population standard deviation incorrect')
  19. def test_pdf(self):
  20. self.assertEqual(round(self.gaussian.pdf(25), 5), 0.01658,\
  21. 'pdf function does not give expected result')
  22. self.gaussian.calculate_mean()
  23. self.gaussian.calculate_stdev()
  24. self.assertEqual(round(self.gaussian.pdf(75), 5), 0.00184,\
  25. 'pdf function after calculating mean and stdev does not give expected result')
  26. def test_add(self):
  27. gaussian_one = Gaussian(25, 3)
  28. gaussian_two = Gaussian(30, 4)
  29. gaussian_sum = gaussian_one + gaussian_two
  30. self.assertEqual(gaussian_sum.mean, 55)
  31. self.assertEqual(gaussian_sum.stdev, 5)
  32. if __name__ == '__main__':
  33. unittest.main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...