From 6845c8c27aa37958b3c020591d613ceb530f781a Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sun, 28 Jan 2024 12:48:12 +0100 Subject: [PATCH] added test for approximating pi with a negative precision number and added functionality to return negaive one in this case to indicate error --- src/main/py/trigonometry.py | 2 ++ src/test/py/test_trigonometry.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index d679dea..c2e6635 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -2,6 +2,8 @@ import math from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate def pi_approx_leibniz(precision): + if precision < 0: + return -1 result = 0 for i in range(precision): num = potentiate(-1, i) diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index f4b7442..8e06ee1 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -15,6 +15,9 @@ class MyTestCase(unittest.TestCase): delta *= -1 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): delta = rad2deg(2) - 114.59 if delta < 0: