Initial Refactoring of yoshi_otter and Test Implementation
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/algebra/__init__.py
Normal file
0
tests/algebra/__init__.py
Normal file
0
tests/algebra/edo/__init__.py
Normal file
0
tests/algebra/edo/__init__.py
Normal file
38
tests/algebra/edo/test_edo.py
Normal file
38
tests/algebra/edo/test_edo.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from yoshi_otter.algebra.edo import Edo
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestEdo(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def f(x, y):
|
||||
return 2*x
|
||||
|
||||
self.f = f
|
||||
|
||||
def test_class_instantiation(self):
|
||||
edo = Edo(self.f)
|
||||
self.assertIsInstance(edo, Edo)
|
||||
|
||||
def test_euler(self):
|
||||
edo = Edo(self.f)
|
||||
y = edo.euler(0, 0, 1)
|
||||
|
||||
self.assertAlmostEqual(y, 1, 5)
|
||||
|
||||
def test_runge(self):
|
||||
edo = Edo(self.f)
|
||||
y = edo.runge(0, 0, 1)
|
||||
|
||||
self.assertAlmostEqual(y, 1, 5)
|
||||
|
||||
def test_adams(self):
|
||||
edo = Edo(self.f)
|
||||
y = edo.adams(0, 0, 1)
|
||||
|
||||
self.assertAlmostEqual(y, 1, 5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
0
tests/algebra/integral/__init__.py
Normal file
0
tests/algebra/integral/__init__.py
Normal file
35
tests/algebra/integral/test_integral_double.py
Normal file
35
tests/algebra/integral/test_integral_double.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from yoshi_otter.algebra.integral.double import Double
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def g(x, y):
|
||||
return x*y
|
||||
|
||||
self.g = g
|
||||
|
||||
def test_class_instantiation(self):
|
||||
Double(self.g)
|
||||
|
||||
def test_riemann(self):
|
||||
|
||||
double = Double(self.g)
|
||||
|
||||
integral = double.riemann(0, 1, 0, 1, n=10**3)
|
||||
|
||||
self.assertAlmostEqual(integral, .25, 2)
|
||||
|
||||
def test_simpson(self):
|
||||
|
||||
double = Double(self.g)
|
||||
|
||||
integral = double.simpson(0, 1, 0, 1, n=10)
|
||||
|
||||
self.assertAlmostEqual(integral, .25, 7) # add assertion here
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
35
tests/algebra/integral/test_integral_simple.py
Normal file
35
tests/algebra/integral/test_integral_simple.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from yoshi_otter.algebra.integral.simple import Simple
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def f(x):
|
||||
return 2*x
|
||||
|
||||
self.f = f
|
||||
|
||||
def test_class_instantiation(self):
|
||||
Simple(self.f)
|
||||
|
||||
def test_riemann(self):
|
||||
|
||||
simple = Simple(self.f)
|
||||
|
||||
integral = simple.riemann(0, 1)
|
||||
|
||||
self.assertAlmostEqual(integral, 1, 5)
|
||||
|
||||
def test_simpson(self):
|
||||
|
||||
simple = Simple(self.f)
|
||||
|
||||
integral = simple.simpson(0, 1)
|
||||
|
||||
self.assertAlmostEqual(integral, 1, 5) # add assertion here
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
0
tests/algebra/roots/__init__.py
Normal file
0
tests/algebra/roots/__init__.py
Normal file
38
tests/algebra/roots/test_roots.py
Normal file
38
tests/algebra/roots/test_roots.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import unittest
|
||||
|
||||
from yoshi_otter.algebra.roots import Roots
|
||||
|
||||
|
||||
class TestRoots(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def f(x):
|
||||
return x
|
||||
|
||||
self.f = f
|
||||
|
||||
def test_class_instantiation(self):
|
||||
roots = Roots(self.f)
|
||||
self.assertIsInstance(roots, Roots)
|
||||
|
||||
def test_bissec(self):
|
||||
roots = Roots(self.f)
|
||||
result = roots.bissec(-1, 1)
|
||||
|
||||
self.assertAlmostEqual(result, 0, 6)
|
||||
|
||||
def test_newton(self):
|
||||
roots = Roots(self.f)
|
||||
result = roots.newton(-1)
|
||||
|
||||
self.assertAlmostEqual(result, 0, 6)
|
||||
|
||||
def test_bissec_newton(self):
|
||||
roots = Roots(self.f)
|
||||
result = roots.bissec_newton(-1, 1)
|
||||
|
||||
self.assertAlmostEqual(result, 0, 6)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
37
tests/algebra/test_algebra.py
Normal file
37
tests/algebra/test_algebra.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from yoshi_otter.shared import InvalidFunctionSignature
|
||||
from yoshi_otter import algebra as ot
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestOtterAlgebra(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def f(x):
|
||||
return 2*x
|
||||
|
||||
def g(x, y):
|
||||
return x*y
|
||||
|
||||
self.f = f
|
||||
self.g = g
|
||||
|
||||
def test_class_instantiation(self):
|
||||
algebra = ot.Algebra(self.f)
|
||||
self.assertIsInstance(algebra, ot.Algebra)
|
||||
|
||||
def test_derivative(self):
|
||||
algebra = ot.Algebra(self.f)
|
||||
derivative = algebra.d(0)
|
||||
|
||||
self.assertEqual(derivative, 2)
|
||||
|
||||
def test_derivative_raises_exception(self):
|
||||
algebra = ot.Algebra(self.g)
|
||||
|
||||
with self.assertRaises(InvalidFunctionSignature):
|
||||
algebra.d(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
0
tests/interpolation/__init__.py
Normal file
0
tests/interpolation/__init__.py
Normal file
67
tests/interpolation/test_interpolation.py
Normal file
67
tests/interpolation/test_interpolation.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from yoshi_otter.interpolation import Interpolation
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestInterpolation(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
def f(x):
|
||||
return 2 * x
|
||||
|
||||
def g(x):
|
||||
return x + x**2
|
||||
|
||||
X = np.linspace(0, 1000, num=1000)
|
||||
Y = [f(x) for x in X]
|
||||
|
||||
self.data = pd.DataFrame(data={'X': X, 'Y': Y})
|
||||
|
||||
Y = [g(x) for x in X]
|
||||
|
||||
self.data_pol = pd.DataFrame(data={'X': X, 'Y': Y})
|
||||
|
||||
def test_class_instantiation(self):
|
||||
interpolation = Interpolation(self.data)
|
||||
self.assertIsInstance(interpolation, Interpolation)
|
||||
|
||||
def test_minimums(self):
|
||||
interpolation = Interpolation(self.data)
|
||||
func, r2 = interpolation.minimums()
|
||||
|
||||
self.assertEqual(func(1), 2)
|
||||
|
||||
@unittest.skip("Temporally not working")
|
||||
def test_polynomial_vandermonde(self):
|
||||
interpolation = Interpolation(self.data_pol)
|
||||
func = interpolation.polynomial.vandermonde()
|
||||
|
||||
self.assertEqual(func(1), 2)
|
||||
|
||||
@unittest.skip("Temporally not working")
|
||||
def test_polynomial_lagrange(self):
|
||||
interpolation = Interpolation(self.data_pol)
|
||||
result = interpolation.polynomial.lagrange(1)
|
||||
|
||||
self.assertEqual(result, 2)
|
||||
|
||||
@unittest.skip("Temporally not working")
|
||||
def test_polynomial_newton(self):
|
||||
interpolation = Interpolation(self.data_pol)
|
||||
result = interpolation.polynomial.newton(1)
|
||||
|
||||
self.assertEqual(result, 2)
|
||||
|
||||
@unittest.skip("Temporally not working")
|
||||
def test_polynomial_gregory(self):
|
||||
interpolation = Interpolation(self.data_pol)
|
||||
result = interpolation.polynomial.gregory(1)
|
||||
|
||||
self.assertEqual(result, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user