FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 3817cb4f authored by M.D. Driver's avatar M.D. Driver
Browse files

added finctionality to deal with the passing of floats as x_values to the...

added finctionality to deal with the passing of floats as x_values to the function, so it mimics the numpy.polynomial.polynomial.polyval signature.
parent 037ba924
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,11 @@ def calculate_polynomial_values(x_values, polynomial_coefficients):
was given.
"""
if type(polynomial_coefficients) is dict:
return calculate_poly_value_for_array_from_dict(x_values, polynomial_coefficients)
if type(x_values) is float or type(x_values) is np.float64:
return calculate_poly_value_from_dict(x_values, polynomial_coefficients)
else:
return calculate_poly_value_for_array_from_dict(x_values, polynomial_coefficients)
else:
return calculate_polynomial_value(x_values, polynomial_coefficients)
......
......@@ -37,6 +37,9 @@ class PolynomialValueCalculatorTestCase(unittest.TestCase):
expected_array2 = np.array([4.5, 1.5, 0.5, 1.5, 4.5])
actual_array2 = polyvalcalc.calculate_polynomial_values(self.input_array, self.poly_coeff_dict["positive"])
np.testing.assert_array_almost_equal(expected_array2, actual_array2)
expected_value = -0.5
actual_value = polyvalcalc.calculate_polynomial_values(-1.0, self.poly_coeff_dict)
self.assertAlmostEqual(expected_value, actual_value)
def test_calculate_poly_value_for_array_from_dict(self):
"""Test to see if expected array iss produced.
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment