From 068330af98542da40eecc9d8c78aeb6aa99ac033 Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sun, 28 Jan 2024 13:41:44 +0100 Subject: [PATCH] added test for sin of rad value in the limits of one period of sin as well as corresponding functionality --- src/main/py/trigonometry.py | 4 +++- src/test/py/test_trigonometry.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index cd98d97..ae1aeb8 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -15,4 +15,6 @@ def rad2deg(radNumber): return (radNumber * 180) / math.pi def sin_approx_bhaskara(radNumber): - return radNumber \ No newline at end of file + num = 16 * radNumber * (math.pi - radNumber) + denom = 5 * math.pow(math.pi, 2) - 4 * radNumber * (math.pi - radNumber) + return num/denom \ No newline at end of file diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index b7324ff..8297175 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -1,5 +1,6 @@ import unittest from src.main.py.trigonometry import * +import math class MyTestCase(unittest.TestCase): @@ -39,6 +40,10 @@ class MyTestCase(unittest.TestCase): def test_sin_0_should_be_0(self): self.assertEqual(sin_approx_bhaskara(0), 0) + def test_sin_quarter_pi_should_be_point707(self): + delta = sin_approx_bhaskara(0.25*math.pi) - 0.707 + self.assertLess(delta, 0.01) + if __name__ == '__main__': unittest.main()