From a0283ddf64d54ef80330e1b88096d59450d145e2 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Fri, 14 Mar 2025 14:08:28 +0100 Subject: [PATCH] added tests for rooting --- tests/functions/test_rooting.py | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/functions/test_rooting.py diff --git a/tests/functions/test_rooting.py b/tests/functions/test_rooting.py new file mode 100644 index 0000000..76ab423 --- /dev/null +++ b/tests/functions/test_rooting.py @@ -0,0 +1,44 @@ +import pytest +from fabelous_math import rooting +import math + +def test_fabelous_sqrt(): + # Test with a perfect square + assert rooting(4) == 2 + + # Test with a non-perfect square + expected_value = math.sqrt(5) + assert abs(rooting(5) - expected_value) < 1e-8 + + # Test with zero + assert rooting(0) == 0 + + # Test with a large number + assert abs(rooting(1000000) - 1000) < 1e-8 + + # Test with a negative number (should raise ValueError) + with pytest.raises(ValueError): + rooting(-1) + +def test_fabelous_sqrt_edge_cases(): + # Test with very small positive number + assert abs(rooting(1e-10, 2) - 1e-5) < 1e-8 # For square root + + # Test with very large positive number + assert abs(rooting(1e+308) - 1e+154) < 1e-8 + +def test_fabelous_sqrt_invalid_input(): + # Test with non-numeric input (should raise TypeError) + with pytest.raises(TypeError): + rooting("string") + + # Test with None input (should raise TypeError) + with pytest.raises(TypeError): + rooting(None) + +def test_fabelous_sqrt_consistency(): + # Test consistency with known values + known_values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + for value in known_values: + expected_value = math.sqrt(value) + assert abs(rooting(value) - expected_value) < 1e-8