diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index 12107e2..4d4d694 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -15,6 +15,8 @@ def rad2deg(radNumber): return (radNumber * 180) / math.pi def sin_approx_bhaskara(radNumber): + while(radNumber > 2 * math.pi): + radNumber -= 2 * math.pi shallFlipTheResult = 0 #the bhaskara function can only be used between zero and pi. For the rest of the sin period I simply mirrored the first arch of the curve to match the actual sine wave if math.pi < radNumber < 2 * math.pi: diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index 9c1829c..4224fd7 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -47,6 +47,9 @@ class MyTestCase(unittest.TestCase): def test_sin_1point5_pi_should_be_negative_1(self): self.assertEqual(sin_approx_bhaskara(1.5*math.pi), -1) + def test_sin_2point5_pi_should_be_1(self): + self.assertEqual(sin_approx_bhaskara(2.5*math.pi), 1) + if __name__ == '__main__': unittest.main()