Skip to content

Commit 3422ebc

Browse files
authored
feat: add testcase of polynom_for_points (TheAlgorithms#11811)
* feat: add testcase of polynom_for_points * fix: remove the print from the testcase of points_to_polynomial * fix: remove print statement from old test cases
1 parent fcf82a1 commit 3422ebc

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Diff for: linear_algebra/src/polynom_for_points.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,36 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
33
coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
44
number of points you want to use
55
6-
>>> print(points_to_polynomial([]))
6+
>>> points_to_polynomial([])
77
Traceback (most recent call last):
88
...
99
ValueError: The program cannot work out a fitting polynomial.
10-
>>> print(points_to_polynomial([[]]))
10+
>>> points_to_polynomial([[]])
11+
Traceback (most recent call last):
12+
...
13+
ValueError: The program cannot work out a fitting polynomial.
14+
>>> points_to_polynomial([[1, 0], [2, 0], [3, 0]])
15+
'f(x)=x^2*0.0+x^1*-0.0+x^0*0.0'
16+
>>> points_to_polynomial([[1, 1], [2, 1], [3, 1]])
17+
'f(x)=x^2*0.0+x^1*-0.0+x^0*1.0'
18+
>>> points_to_polynomial([[1, 3], [2, 3], [3, 3]])
19+
'f(x)=x^2*0.0+x^1*-0.0+x^0*3.0'
20+
>>> points_to_polynomial([[1, 1], [2, 2], [3, 3]])
21+
'f(x)=x^2*0.0+x^1*1.0+x^0*0.0'
22+
>>> points_to_polynomial([[1, 1], [2, 4], [3, 9]])
23+
'f(x)=x^2*1.0+x^1*-0.0+x^0*0.0'
24+
>>> points_to_polynomial([[1, 3], [2, 6], [3, 11]])
25+
'f(x)=x^2*1.0+x^1*-0.0+x^0*2.0'
26+
>>> points_to_polynomial([[1, -3], [2, -6], [3, -11]])
27+
'f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0'
28+
>>> points_to_polynomial([[1, 5], [2, 2], [3, 9]])
29+
'f(x)=x^2*5.0+x^1*-18.0+x^0*18.0'
30+
>>> points_to_polynomial([[1, 1], [1, 2], [1, 3]])
31+
'x=1'
32+
>>> points_to_polynomial([[1, 1], [2, 2], [2, 2]])
1133
Traceback (most recent call last):
1234
...
1335
ValueError: The program cannot work out a fitting polynomial.
14-
>>> print(points_to_polynomial([[1, 0], [2, 0], [3, 0]]))
15-
f(x)=x^2*0.0+x^1*-0.0+x^0*0.0
16-
>>> print(points_to_polynomial([[1, 1], [2, 1], [3, 1]]))
17-
f(x)=x^2*0.0+x^1*-0.0+x^0*1.0
18-
>>> print(points_to_polynomial([[1, 3], [2, 3], [3, 3]]))
19-
f(x)=x^2*0.0+x^1*-0.0+x^0*3.0
20-
>>> print(points_to_polynomial([[1, 1], [2, 2], [3, 3]]))
21-
f(x)=x^2*0.0+x^1*1.0+x^0*0.0
22-
>>> print(points_to_polynomial([[1, 1], [2, 4], [3, 9]]))
23-
f(x)=x^2*1.0+x^1*-0.0+x^0*0.0
24-
>>> print(points_to_polynomial([[1, 3], [2, 6], [3, 11]]))
25-
f(x)=x^2*1.0+x^1*-0.0+x^0*2.0
26-
>>> print(points_to_polynomial([[1, -3], [2, -6], [3, -11]]))
27-
f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0
28-
>>> print(points_to_polynomial([[1, 5], [2, 2], [3, 9]]))
29-
f(x)=x^2*5.0+x^1*-18.0+x^0*18.0
3036
"""
3137
if len(coordinates) == 0 or not all(len(pair) == 2 for pair in coordinates):
3238
raise ValueError("The program cannot work out a fitting polynomial.")

0 commit comments

Comments
 (0)