6
6
from numpy .polynomial import Polynomial
7
7
8
8
9
- def compute_legendre_polynomial_coefficients (n : int ) -> [float ]:
9
+ def legendre (n : int ) -> [float ]:
10
10
"""
11
11
Compute the coefficients of the nth Legendre polynomial.
12
12
@@ -23,30 +23,38 @@ def compute_legendre_polynomial_coefficients(n: int) -> [float]:
23
23
return legendre_polynomial .deriv (n ).coef .tolist ()
24
24
25
25
26
- def test_legendre_polynomial_degree_0 () -> None :
26
+ def test_legendre_0 () :
27
27
"""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]"
29
29
30
30
31
- def test_legendre_polynomial_degree_1 () -> None :
31
+ def test_legendre_1 () :
32
32
"""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]"
34
34
35
35
36
- def test_legendre_polynomial_degree_2 () -> None :
36
+ def test_legendre_2 () :
37
37
"""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]"
40
43
41
44
42
- def test_legendre_polynomial_degree_3 () -> None :
45
+ def test_legendre_3 () :
43
46
"""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]"
45
53
46
54
47
- def test_legendre_polynomial_degree_4 () -> None :
55
+ def test_legendre_4 () :
48
56
"""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 ])
50
58
"The 4th Legendre polynomial should be [0.375, 0.0, -3.75, 0.0, 4.375]"
51
59
52
60
0 commit comments