Skip to content

Commit

Permalink
Create Unit Test for fit.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjekyejoannah committed Jan 23, 2018
1 parent 1cf1c84 commit 9b1d467
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gpfit/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 36 additions & 0 deletions gpfit/tests/t_fit.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9b1d467

Please sign in to comment.