Update README and tests for new integral function
This commit was merged in pull request #27.
This commit is contained in:
@@ -18,6 +18,13 @@ def quadratic_func() -> Function:
|
||||
f.set_coeffs([2, -3, -5])
|
||||
return f
|
||||
|
||||
@pytest.fixture
|
||||
def int_func() -> Function:
|
||||
"""Provides a function for easy integral calculation."""
|
||||
f = Function(largest_exponent=2)
|
||||
f.set_coeffs([3, -4, -5])
|
||||
return f
|
||||
|
||||
@pytest.fixture
|
||||
def linear_func() -> Function:
|
||||
"""Provides a standard linear function: x + 10."""
|
||||
@@ -70,6 +77,20 @@ def test_nth_derivative(quadratic_func):
|
||||
# The derivative of 2x^2 - 3x - 5 is 4x - 3
|
||||
assert np.array_equal(derivative.coefficients, [4])
|
||||
|
||||
def test_integral(int_func):
|
||||
"""Tests the calculation of the function's integral."""
|
||||
integral = int_func.integral()
|
||||
assert integral.largest_exponent == 3
|
||||
# The integral of 2x^2 -3x - 5 is x^3 - 2x^2 - 5x
|
||||
assert np.array_equal(integral.coefficients, [1, -2, -5, 0])
|
||||
|
||||
def test_integral_custom_constant(int_func):
|
||||
"""Tests the calculation of the function's integral with custom constant of integration."""
|
||||
integral = int_func.integral(constant_of_integration=42)
|
||||
assert integral.largest_exponent == 3
|
||||
# The integral of 2x^2 -3x - 5 is x^3 - 2x^2 - 5x
|
||||
assert np.array_equal(integral.coefficients, [1, -2, -5, 42])
|
||||
|
||||
def test_quadratic_solve(quadratic_func):
|
||||
"""Tests the analytical quadratic solver for exact roots."""
|
||||
roots = quadratic_func.quadratic_solve()
|
||||
|
||||
Reference in New Issue
Block a user