Graphs and tables for your Spotify account.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.1 KiB

  1. from django.test import TestCase
  2. from .views import update_std_dev
  3. import math
  4. # Create your tests here.
  5. class UpdateStdDevTest(TestCase):
  6. def test_two_data_points(self):
  7. """
  8. tests if update_std_dev behaves correctly for two data points
  9. """
  10. cur_mean = 5
  11. cur_std_dev = 0
  12. new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 10, 2)
  13. self.assertTrue(math.isclose(new_mean, 7.5, rel_tol=0.01))
  14. self.assertTrue(math.isclose(new_std_dev, 3.5355, rel_tol=0.01))
  15. def test_three_data_points(self):
  16. """
  17. tests if update_std_dev behaves correctly for three data points
  18. """
  19. cur_mean = 7.5
  20. cur_std_dev = 3.5355
  21. new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 15, 3)
  22. self.assertTrue(math.isclose(new_mean, 10, rel_tol=0.01))
  23. self.assertTrue(math.isclose(new_std_dev, 5, rel_tol=0.01))
  24. def test_four_data_points(self):
  25. """
  26. tests if update_std_dev behaves correctly for four data points
  27. """
  28. cur_mean = 10
  29. cur_std_dev = 5
  30. new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 20, 4)
  31. self.assertTrue(math.isclose(new_mean, 12.5, rel_tol=0.01))
  32. self.assertTrue(math.isclose(new_std_dev, 6.455, rel_tol=0.01))
  33. def test_five_data_points(self):
  34. """
  35. tests if update_std_dev behaves correctly for five data points
  36. """
  37. cur_mean = 12.5
  38. cur_std_dev = 6.455
  39. new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 63, 5)
  40. self.assertTrue(math.isclose(new_mean, 22.6, rel_tol=0.01))
  41. self.assertTrue(math.isclose(new_std_dev, 23.2658, rel_tol=0.01))
  42. def test_sixteen_data_points(self):
  43. """
  44. tests if update_std_dev behaves correctly for sixteen data points
  45. """
  46. cur_mean = 0.4441
  47. cur_std_dev = 0.2855
  48. new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 0.7361, 16)
  49. self.assertTrue(math.isclose(new_mean, 0.4624, rel_tol=0.01))
  50. self.assertTrue(math.isclose(new_std_dev, 0.2853, rel_tol=0.01))