Skip to content

Commit

Permalink
update test test_construct_matrix_3_3
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Dec 8, 2022
1 parent 5617fc2 commit 8886c08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/approximations/rational.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import polynomial

def construct_rational_eval_matrix(x_list: list, y_list: list, num_terms_numerator: int, num_terms_denominator) -> list[list]:
def construct_rational_eval_matrix(x_list: list, y_list: list, num_terms_numerator: int, num_terms_denominator) -> sp.Matrix:
""" Constructs a matrix to use for computing coefficients for a rational approximation
from the list of x and y values given.
len(x_list) * len(x_list)
Expand Down
18 changes: 8 additions & 10 deletions scripts/approximations/rational_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import math
import sympy as sp

import rational

Expand All @@ -15,24 +16,21 @@ def test_construct_matrix_3_3(self):
x = [1, 2, 3, 4, 5]
y = list(map(fn, x))

coeffs = rational.construct_rational_eval_matrix(x, y)
coeffs = rational.construct_rational_eval_matrix(x, y, 3, 3)

# number of rows is correct
self.assertEqual(len(x), len(coeffs))
# correct matrix size
self.assertEqual(len(x) * len(x), len(coeffs))

# first row is correct
for i in range(len(coeffs)):
# number of columns in each row is correct
self.assertEqual(len(coeffs), len(coeffs[i]))

for i in range(len(x)):
x_i = x[i]
y_i = y[i]

expected_row = [1, x_i, x_i**2, -1 * x_i * y_i, -1 * x_i**2 * y_i]
expected_row = [sp.Pow(x_i, 0), sp.Pow(x_i, 1), sp.Pow(x_i, 2), -1 * sp.Pow(x_i, 1) * y_i, -1 * sp.Pow(x_i, 2) * y_i]

actual_rot = coeffs[i]
actual_row = coeffs.row(i).tolist()[0]

self.assertEqual(expected_row, actual_rot)
self.assertEqual(expected_row, actual_row)

if __name__ == '__main__':
unittest.main()

0 comments on commit 8886c08

Please sign in to comment.