Skip to content

Commit

Permalink
Merge branch 'master' into another_plotfit_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pgkirsch committed Jul 9, 2021
2 parents 425517a + bd3b9ca commit 48d8eeb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gpfit/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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
4 changes: 3 additions & 1 deletion gpfit/tests/t_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
import os
from gpkit.tests.helpers import generate_example_tests
from gpkit import settings


class TestExamples(unittest.TestCase):
Expand Down Expand Up @@ -37,7 +38,8 @@ def test_hoburgabbeel_ex6_1(self, example):
FILE_DIR = os.path.dirname(os.path.realpath(__file__))
EXAMPLE_DIR = os.path.abspath(FILE_DIR + '../../../docs/source/examples')
# use gpkit.tests.helpers.generate_example_tests default: only default solver
TESTS = generate_example_tests(EXAMPLE_DIR, [TestExamples])
TESTS = generate_example_tests(EXAMPLE_DIR, [TestExamples],
settings["installed_solvers"])


if __name__ == "__main__":
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 numpy import logspace, log10, log, vstack
from gpfit.fit import fit

class t_fit(unittest.TestCase):

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(self.x, self.y, self.K, "SMA")
self.assertTrue(rms_error < 1e-4)
cstrt, rms_error = fit(self.x, self.y, self.K, "ISMA")
self.assertTrue(rms_error < 1e-5)
cstrt, rms_error = fit(self.x, self.y, self.K, "MA")
self.assertTrue(rms_error < 1e-2)

def test_incorrect_inputs(self):
with self.assertRaises(ValueError):
fit(self.x, vstack((self.y, self.y)), self.K, "MA")


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 48d8eeb

Please sign in to comment.