66from numpy .polynomial import Polynomial
77
88
9- def compute_legendre_polynomial_coefficients (n : int ) -> [float ]:
9+ def legendre (n : int ) -> [float ]:
1010 """
1111 Compute the coefficients of the nth Legendre polynomial.
1212
@@ -23,30 +23,38 @@ def compute_legendre_polynomial_coefficients(n: int) -> [float]:
2323 return legendre_polynomial .deriv (n ).coef .tolist ()
2424
2525
26- def test_legendre_polynomial_degree_0 () -> None :
26+ def test_legendre_0 () :
2727 """Test the 0th Legendre polynomial."""
28- assert compute_legendre_polynomial_coefficients (0 ) == [1.0 ], "The 0th Legendre polynomial should be [1.0]"
28+ assert legendre (0 ) == [1.0 ], "The 0th Legendre polynomial should be [1.0]"
2929
3030
31- def test_legendre_polynomial_degree_1 () -> None :
31+ def test_legendre_1 () :
3232 """Test the 1st Legendre polynomial."""
33- assert compute_legendre_polynomial_coefficients (1 ) == [0.0 , 1.0 ], "The 1st Legendre polynomial should be [0.0, 1.0]"
33+ assert legendre (1 ) == [0.0 , 1.0 ], "The 1st Legendre polynomial should be [0.0, 1.0]"
3434
3535
36- def test_legendre_polynomial_degree_2 () -> None :
36+ def test_legendre_2 () :
3737 """Test the 2nd Legendre polynomial."""
38- assert compute_legendre_polynomial_coefficients (2 ) == [- 0.5 , 0.0 , 1.5 ],
39- "The 2nd Legendre polynomial should be [-0.5, 0.0, 1.5]"
38+ assert legendre (2 ) == [
39+ - 0.5 ,
40+ 0.0 ,
41+ 1.5 ,
42+ ], "The 2nd Legendre polynomial should be [-0.5, 0.0, 1.5]"
4043
4144
42- def test_legendre_polynomial_degree_3 () -> None :
45+ def test_legendre_3 () :
4346 """Test the 3rd Legendre polynomial."""
44- assert compute_legendre_polynomial_coefficients (3 ) == [0.0 , - 1.5 , 0.0 , 2.5 ], "The 3rd Legendre polynomial should be [0.0, -1.5, 0.0, 2.5]"
47+ assert legendre (3 ) == [
48+ 0.0 ,
49+ - 1.5 ,
50+ 0.0 ,
51+ 2.5 ,
52+ ], "The 3rd Legendre polynomial should be [0.0, -1.5, 0.0, 2.5]"
4553
4654
47- def test_legendre_polynomial_degree_4 () -> None :
55+ def test_legendre_4 () :
4856 """Test the 4th Legendre polynomial."""
49- assert compute_legendre_polynomial_coefficients (4 ) == pytest .approx ([0.375 , 0.0 , - 3.75 , 0.0 , 4.375 ])
57+ assert legendre (4 ) == pytest .approx ([0.375 , 0.0 , - 3.75 , 0.0 , 4.375 ])
5058 "The 4th Legendre polynomial should be [0.375, 0.0, -3.75, 0.0, 4.375]"
5159
5260
0 commit comments