From ccd7bc3b2e9c8cf065f06618422b7151d17485c7 Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sun, 28 Jan 2024 15:39:13 +0100 Subject: [PATCH] added test for conversion of 360 degrees to radians as well as corresponding functionality --- src/main/py/trigonometry.py | 2 +- src/test/py/test_trigonometry.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index 3bfddac..a2616b8 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -15,7 +15,7 @@ def rad2deg(radNumber): return (radNumber * 180) / math.pi def deg2rad(degNumber): - return degNumber + return (degNumber * math.pi) / 180 def sin_approx_bhaskara(radNumber): shallFlipTheResult = False #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 diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index 9045e49..3a347d4 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -40,6 +40,12 @@ class MyTestCase(unittest.TestCase): def test_0_deg_to_rad_should_be_0(self): self.assertEqual(deg2rad(0), 0) + def test_360_deg_to_rad_should_be_2pi(self): + delta = deg2rad(360) - math.pi*2 + if delta < 0: + delta *= -1 + self.assertLess(delta, 0.01) + def test_sin_0_should_be_0(self): self.assertEqual(sin_approx_bhaskara(0), 0)