Browse Source

added test for approximating pi with a negative precision number and added functionality to return negaive one in this case to indicate error

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

2
src/main/py/trigonometry.py

@ -2,6 +2,8 @@ import math
from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate
def pi_approx_leibniz(precision): def pi_approx_leibniz(precision):
if precision < 0:
return -1
result = 0 result = 0
for i in range(precision): for i in range(precision):
num = potentiate(-1, i) num = potentiate(-1, i)

3
src/test/py/test_trigonometry.py

@ -15,6 +15,9 @@ class MyTestCase(unittest.TestCase):
delta *= -1 delta *= -1
self.assertLess(delta, 0.01) self.assertLess(delta, 0.01)
def test_pi_precision_negative_10_should_be_negative_1_for_error(self):
self.assertEqual(pi_approx_leibniz(-10), -1)
def test_rad_2_to_deg_should_be_114_point_59(self): def test_rad_2_to_deg_should_be_114_point_59(self):
delta = rad2deg(2) - 114.59 delta = rad2deg(2) - 114.59
if delta < 0: if delta < 0:

Loading…
Cancel
Save