Browse Source

added test for sin of value between zero and negative pi as well as corresponding functionality

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

5
src/main/py/trigonometry.py

@ -15,6 +15,7 @@ def rad2deg(radNumber):
return (radNumber * 180) / math.pi return (radNumber * 180) / math.pi
def sin_approx_bhaskara(radNumber): def sin_approx_bhaskara(radNumber):
while(radNumber > 2 * math.pi): while(radNumber > 2 * math.pi):
radNumber -= 2 * math.pi radNumber -= 2 * math.pi
@ -23,6 +24,10 @@ def sin_approx_bhaskara(radNumber):
radNumber = subract(math.pi, radNumber) radNumber = subract(math.pi, radNumber)
shallFlipTheResult = 1 shallFlipTheResult = 1
if 0 > radNumber > -2*math.pi:
radNumber *= -1
shallFlipTheResult = 1
num = multiply(16, radNumber) num = multiply(16, radNumber)
num = multiply(num, subract(radNumber, math.pi)) num = multiply(num, subract(radNumber, math.pi))

3
src/test/py/test_trigonometry.py

@ -50,6 +50,9 @@ class MyTestCase(unittest.TestCase):
def test_sin_2point5_pi_should_be_1(self): def test_sin_2point5_pi_should_be_1(self):
self.assertEqual(sin_approx_bhaskara(2.5*math.pi), 1) self.assertEqual(sin_approx_bhaskara(2.5*math.pi), 1)
def test_sin_negative_point5_pi_should_be_negative_1(self):
self.assertEqual(sin_approx_bhaskara(-0.5*math.pi), -1)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save