Browse Source

added test for approximating pi as well as corresponding functionality using the leibniz-series

remotes/origin/feature/feature-trigonometry
fdai7764 11 months ago
parent
commit
509de48aed
  1. 10
      src/main/py/trigonometry.py
  2. 6
      src/test/py/test_trigonometry.py

10
src/main/py/trigonometry.py

@ -1,3 +1,13 @@
import math
from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate
def pi_approx_leibniz(precision):
result = 0
for i in range(precision):
num = potentiate(-1, i)
denom = 2*i + 1
result += num/denom
return result * 4
def rad2deg(radNumber):
return (radNumber * 180) / math.pi

6
src/test/py/test_trigonometry.py

@ -9,6 +9,12 @@ class MyTestCase(unittest.TestCase):
def tearDown(self):
pass
def test_pi_precision_1000000_should_be_3_point_141592(self):
delta = pi_approx_leibniz(1000000) - 3.141592
if delta < 0:
delta *= -1
self.assertLess(delta, 0.01)
def test_rad_2_to_deg_should_be_114_point_59(self):
delta = rad2deg(2) - 114.59
if delta < 0:

Loading…
Cancel
Save