From 9b1d467621cdb706459bdcf8970f68426f54e159 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Tue, 23 Jan 2018 16:45:34 +0300 Subject: [PATCH] Create Unit Test for fit.py --- gpfit/tests/run_tests.py | 3 +++ gpfit/tests/t_fit.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 gpfit/tests/t_fit.py diff --git a/gpfit/tests/run_tests.py b/gpfit/tests/run_tests.py index e3d7fe7..ae62e07 100644 --- a/gpfit/tests/run_tests.py +++ b/gpfit/tests/run_tests.py @@ -32,6 +32,9 @@ from gpfit.tests import t_examples TESTS += t_examples.TESTS +from gpfit.tests import t_fit +TESTS += t_fit.TESTS + def run(xmloutput=False): """Run all gpfit unit tests. diff --git a/gpfit/tests/t_fit.py b/gpfit/tests/t_fit.py new file mode 100644 index 0000000..416a957 --- /dev/null +++ b/gpfit/tests/t_fit.py @@ -0,0 +1,36 @@ +#unit tests for gpfit.fit module" +import unittest +from gpfit.fit import fit + +class t_fit(unittest.TestCase): + m = 501 + u = logspace(0,log10(3),501) + w = (u**2 + 3)/(u+1)**2 + x = log(u) + y = log(w) + K = 3 + + def test_rms_error(self): + cstrt, rms_error = fit(x, y, K, "SMA") + self.assertTrue(self.rms_error < 1e-4) + cstrt, rms_error = fit(x, y, K, "ISMA") + self.assertTrue(self.rms_error < 1e-5) + cstrt, rms_error = fit(x, y, K, "MA") + self.assertTrue(self.rms_error < 1e-2) + + def test_incorrect_inputs(self): + err = fit(x, 0, K, "MA") + self.assertEqual(self.err, 'Dependent data should be a 1D numpy array') + + +TESTS = [t_fit] + +if __name__ == '__main__': + SUITE = unittest.TestSuite() + LOADER = unittest.TestLoader() + + for t in TESTS: + SUITE.addTests(LOADER.loadTestsFromTestCase(t)) + + unittest.TextTestRunner(verbosity=2).run(SUITE) + \ No newline at end of file