added tests for rooting
Gitea Actions For Fabelous-Math / Explore-Gitea-Actions (push) Waiting to run Details

This commit is contained in:
Falko Victor Habel 2025-03-14 14:08:28 +01:00
parent 2bcb4f3d3d
commit a0283ddf64
1 changed files with 44 additions and 0 deletions

View File

@ -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