Initial Refactoring of yoshi_otter and Test Implementation
This commit is contained in:
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()
|
||||
Reference in New Issue
Block a user