From 3817cb4fd0fe4ae27f4bdda04226c88d29f37a33 Mon Sep 17 00:00:00 2001 From: Mark Driver <mdd31@cam.ac.uk> Date: Fri, 11 Aug 2017 18:08:45 +0100 Subject: [PATCH] added finctionality to deal with the passing of floats as x_values to the function, so it mimics the numpy.polynomial.polynomial.polyval signature. --- .../polynomialanalysis/polynomialvaluecalculator.py | 6 +++++- .../polynomialanalysistest/polynomialvaluecalculatortest.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/solventmapcreator/polynomialanalysis/polynomialvaluecalculator.py b/solventmapcreator/polynomialanalysis/polynomialvaluecalculator.py index d02cb2e..c247b76 100644 --- a/solventmapcreator/polynomialanalysis/polynomialvaluecalculator.py +++ b/solventmapcreator/polynomialanalysis/polynomialvaluecalculator.py @@ -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) diff --git a/solventmapcreator/test/polynomialanalysistest/polynomialvaluecalculatortest.py b/solventmapcreator/test/polynomialanalysistest/polynomialvaluecalculatortest.py index 5035ffb..21cb44a 100644 --- a/solventmapcreator/test/polynomialanalysistest/polynomialvaluecalculatortest.py +++ b/solventmapcreator/test/polynomialanalysistest/polynomialvaluecalculatortest.py @@ -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. """ -- GitLab