Skip to content

Commit

Permalink
feat: add testcase of polynom_for_points (#11811)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zeelrupapara authored Oct 7, 2024
1 parent fcf82a1 commit 3422ebc
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions linear_algebra/src/polynom_for_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,36 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
number of points you want to use
>>> print(points_to_polynomial([]))
>>> points_to_polynomial([])
Traceback (most recent call last):
...
ValueError: The program cannot work out a fitting polynomial.
>>> print(points_to_polynomial([[]]))
>>> points_to_polynomial([[]])
Traceback (most recent call last):
...
ValueError: The program cannot work out a fitting polynomial.
>>> points_to_polynomial([[1, 0], [2, 0], [3, 0]])
'f(x)=x^2*0.0+x^1*-0.0+x^0*0.0'
>>> points_to_polynomial([[1, 1], [2, 1], [3, 1]])
'f(x)=x^2*0.0+x^1*-0.0+x^0*1.0'
>>> points_to_polynomial([[1, 3], [2, 3], [3, 3]])
'f(x)=x^2*0.0+x^1*-0.0+x^0*3.0'
>>> points_to_polynomial([[1, 1], [2, 2], [3, 3]])
'f(x)=x^2*0.0+x^1*1.0+x^0*0.0'
>>> points_to_polynomial([[1, 1], [2, 4], [3, 9]])
'f(x)=x^2*1.0+x^1*-0.0+x^0*0.0'
>>> points_to_polynomial([[1, 3], [2, 6], [3, 11]])
'f(x)=x^2*1.0+x^1*-0.0+x^0*2.0'
>>> points_to_polynomial([[1, -3], [2, -6], [3, -11]])
'f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0'
>>> points_to_polynomial([[1, 5], [2, 2], [3, 9]])
'f(x)=x^2*5.0+x^1*-18.0+x^0*18.0'
>>> points_to_polynomial([[1, 1], [1, 2], [1, 3]])
'x=1'
>>> points_to_polynomial([[1, 1], [2, 2], [2, 2]])
Traceback (most recent call last):
...
ValueError: The program cannot work out a fitting polynomial.
>>> print(points_to_polynomial([[1, 0], [2, 0], [3, 0]]))
f(x)=x^2*0.0+x^1*-0.0+x^0*0.0
>>> print(points_to_polynomial([[1, 1], [2, 1], [3, 1]]))
f(x)=x^2*0.0+x^1*-0.0+x^0*1.0
>>> print(points_to_polynomial([[1, 3], [2, 3], [3, 3]]))
f(x)=x^2*0.0+x^1*-0.0+x^0*3.0
>>> print(points_to_polynomial([[1, 1], [2, 2], [3, 3]]))
f(x)=x^2*0.0+x^1*1.0+x^0*0.0
>>> print(points_to_polynomial([[1, 1], [2, 4], [3, 9]]))
f(x)=x^2*1.0+x^1*-0.0+x^0*0.0
>>> print(points_to_polynomial([[1, 3], [2, 6], [3, 11]]))
f(x)=x^2*1.0+x^1*-0.0+x^0*2.0
>>> print(points_to_polynomial([[1, -3], [2, -6], [3, -11]]))
f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0
>>> print(points_to_polynomial([[1, 5], [2, 2], [3, 9]]))
f(x)=x^2*5.0+x^1*-18.0+x^0*18.0
"""
if len(coordinates) == 0 or not all(len(pair) == 2 for pair in coordinates):
raise ValueError("The program cannot work out a fitting polynomial.")
Expand Down

0 comments on commit 3422ebc

Please sign in to comment.