Skip to content

Commit 603e345

Browse files
zeelrupaparafortarch
authored andcommitted
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 603e345

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-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.")

Diff for: mytest.ipynb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"print(\"hello\")"
10+
]
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "base",
16+
"language": "python",
17+
"name": "python3"
18+
},
19+
"language_info": {
20+
"name": "python",
21+
"version": "3.10.14"
22+
}
23+
},
24+
"nbformat": 4,
25+
"nbformat_minor": 2
26+
}

0 commit comments

Comments
 (0)