From c6c4897ce0cd6cf2a994d81853e910e56c4ea3bb Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Mon, 21 May 2018 11:55:32 -0400 Subject: [PATCH 1/2] Added four tests for update_std_dev() --- spotifyvis/tests.py | 53 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/spotifyvis/tests.py b/spotifyvis/tests.py index 7ce503c..8a9a2d5 100644 --- a/spotifyvis/tests.py +++ b/spotifyvis/tests.py @@ -1,3 +1,54 @@ from django.test import TestCase - +from .views import update_std_dev +import math # Create your tests here. + +class UpdateStdDevTest(TestCase): + + def test_two_data_points(self): + """ + tests if update_std_dev behaves correctly for two data points + """ + cur_mean = 5 + cur_std_dev = 0 + + new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 10, 2) + + self.assertTrue(math.isclose(new_mean, 7.5, rel_tol=0.01)) + self.assertTrue(math.isclose(new_std_dev, 3.5355, rel_tol=0.01)) + + def test_three_data_points(self): + """ + tests if update_std_dev behaves correctly for three data points + """ + cur_mean = 7.5 + cur_std_dev = 3.5355 + + new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 15, 3) + + self.assertTrue(math.isclose(new_mean, 10, rel_tol=0.01)) + self.assertTrue(math.isclose(new_std_dev, 5, rel_tol=0.01)) + + def test_four_data_points(self): + """ + tests if update_std_dev behaves correctly for four data points + """ + cur_mean = 10 + cur_std_dev = 5 + + new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 20, 4) + self.assertTrue(math.isclose(new_mean, 12.5, rel_tol=0.01)) + self.assertTrue(math.isclose(new_std_dev, 6.455, rel_tol=0.01)) + + + + def test_five_data_points(self): + """ + tests if update_std_dev behaves correctly for five data points + """ + cur_mean = 12.5 + cur_std_dev = 6.455 + + new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 63, 5) + self.assertTrue(math.isclose(new_mean, 22.6, rel_tol=0.01)) + self.assertTrue(math.isclose(new_std_dev, 23.2658, rel_tol=0.01)) \ No newline at end of file From 3a733e18b3fa470aadc864b8edfeafe196b1cf8c Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Mon, 21 May 2018 12:05:43 -0400 Subject: [PATCH 2/2] Added one more test for update_std_dev() --- spotifyvis/tests.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spotifyvis/tests.py b/spotifyvis/tests.py index 8a9a2d5..b88c1e2 100644 --- a/spotifyvis/tests.py +++ b/spotifyvis/tests.py @@ -17,6 +17,7 @@ class UpdateStdDevTest(TestCase): self.assertTrue(math.isclose(new_mean, 7.5, rel_tol=0.01)) self.assertTrue(math.isclose(new_std_dev, 3.5355, rel_tol=0.01)) + def test_three_data_points(self): """ tests if update_std_dev behaves correctly for three data points @@ -28,7 +29,8 @@ class UpdateStdDevTest(TestCase): self.assertTrue(math.isclose(new_mean, 10, rel_tol=0.01)) self.assertTrue(math.isclose(new_std_dev, 5, rel_tol=0.01)) - + + def test_four_data_points(self): """ tests if update_std_dev behaves correctly for four data points @@ -41,7 +43,6 @@ class UpdateStdDevTest(TestCase): self.assertTrue(math.isclose(new_std_dev, 6.455, rel_tol=0.01)) - def test_five_data_points(self): """ tests if update_std_dev behaves correctly for five data points @@ -51,4 +52,16 @@ class UpdateStdDevTest(TestCase): new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 63, 5) self.assertTrue(math.isclose(new_mean, 22.6, rel_tol=0.01)) - self.assertTrue(math.isclose(new_std_dev, 23.2658, rel_tol=0.01)) \ No newline at end of file + self.assertTrue(math.isclose(new_std_dev, 23.2658, rel_tol=0.01)) + + + def test_sixteen_data_points(self): + """ + tests if update_std_dev behaves correctly for sixteen data points + """ + cur_mean = 0.4441 + cur_std_dev = 0.2855 + + new_mean, new_std_dev = update_std_dev(cur_mean, cur_std_dev, 0.7361, 16) + self.assertTrue(math.isclose(new_mean, 0.4624, rel_tol=0.01)) + self.assertTrue(math.isclose(new_std_dev, 0.2853, rel_tol=0.01)) \ No newline at end of file