def test_invalid_approx_order_error(self): """Test that an error is raised if order < 1 or not an integer""" with pytest.raises(ValueError, match="order must be a positive integer"): finite_diff_coeffs(1, 0, 1) with pytest.raises(ValueError, match="order must be a positive integer"): finite_diff_coeffs(1, 1.7, 1) with pytest.raises(ValueError, match="Centered finite-difference requires an even order"): finite_diff_coeffs(1, 1, "center")
def test_correct_second_derivative_center_order4(self): """Test that the correct forward order 4 method is returned""" coeffs, shifts = finite_diff_coeffs(2, 4, "center") assert np.allclose(coeffs, [-2.5, 4 / 3, 4 / 3, -1 / 12, -1 / 12]) assert np.allclose(shifts, [0, -1, 1, -2, 2])
def test_correct_second_derivative_forward_order1(self): """Test that the correct forward order 1 method is returned""" coeffs, shifts = finite_diff_coeffs(2, 1, "forward") assert np.allclose(coeffs, [1, -2, 1]) assert np.allclose(shifts, [0, 1, 2])
def test_correct_backward_order1(self): """Test that the correct backward order 1 method is returned""" coeffs, shifts = finite_diff_coeffs(1, 1, "backward") assert np.allclose(coeffs, [1, -1]) assert np.allclose(shifts, [0, -1])
def test_correct_center_order2(self): """Test that the correct centered order 2 method is returned""" coeffs, shifts = finite_diff_coeffs(1, 2, "center") assert np.allclose(coeffs, [-0.5, 0.5]) assert np.allclose(shifts, [-1, 1])
def test_correct_forward_order2(self): """Test that the correct forward order 2 method is returned""" coeffs, shifts = finite_diff_coeffs(1, 2, "forward") assert np.allclose(coeffs, [-1.5, 2, -0.5]) assert np.allclose(shifts, [0, 1, 2])
def test_invalid_strategy(self): """Test that an error is raised if the strategy is not recognized""" with pytest.raises(ValueError, match="Unknown strategy"): finite_diff_coeffs(1, 1, 1)