Browse Source

added test for sin of rad value between pi and 2pi as well as corresponding functionality

remotes/origin/feature/feature-trigonometry
fdai7764 11 months ago
parent
commit
e7eac8472b
  1. 13
      src/main/py/trigonometry.py
  2. 3
      src/test/py/test_trigonometry.py

13
src/main/py/trigonometry.py

@ -15,6 +15,13 @@ def rad2deg(radNumber):
return (radNumber * 180) / math.pi
def sin_approx_bhaskara(radNumber):
shallFlipTheResult = 0
if math.pi < radNumber < 2 * math.pi:
radNumber -= math.pi
shallFlipTheResult = 1
num = multiply(16, radNumber)
num = multiply(num, subract(radNumber, math.pi))
@ -23,4 +30,8 @@ def sin_approx_bhaskara(radNumber):
denomFrag2 = multiply(denomFrag2, radNumber)
denomFrag2 = multiply(denomFrag2, 4)
return divide(num, subract(denomFrag2, denomFrag1))
sinResult = divide(num, subract(denomFrag2, denomFrag1))
if(shallFlipTheResult == 1):
return sinResult * -1
return sinResult

3
src/test/py/test_trigonometry.py

@ -44,6 +44,9 @@ class MyTestCase(unittest.TestCase):
delta = sin_approx_bhaskara(0.25*math.pi) - 0.707
self.assertLess(delta, 0.01)
def test_sin_1point5_pi_should_be_negative_1(self):
self.assertEqual(sin_approx_bhaskara(1.5*math.pi), -1)
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save