Initial Refactoring of yoshi_otter and Test Implementation

This commit is contained in:
2022-12-08 05:30:17 -03:00
parent 3b319573ee
commit b24723467e
106 changed files with 1010 additions and 8186 deletions

View File

View File

View 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()

View File

View 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()

View 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()

View File

View 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()

View 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()