예제 #1
0
파일: test.py 프로젝트: es-g/newtonMethod
class TestGaussianClass(unittest.TestCase):
    def setUp(self):
        self.newton = Newton(f='x**2 - 9', max_iter=1e6)

    def test_initialization(self):
        self.assertEqual(self.newton.f, 'x**2 - 9', 'incorrect function')
        self.assertEqual(self.newton.max_iter, 1e6,
                         'incorrect maximum number of iterations')

    def test_solution1calc(self):
        self.assertEqual(round(self.newton.find_solution(1000), 2), 3.00,
                         'root incorrect')

    def test_solution2calc(self):
        self.assertEqual(round(self.newton.find_solution(-1000), 2), -3.00,
                         'root incorrect')

    def test_handlingZeroDivision(self):
        self.assertEqual(round(self.newton.find_solution(0), 2), 3.00,
                         'Zero Division error occured')
예제 #2
0
파일: test1.py 프로젝트: es-g/newtonMethod
from newton import Newton

f = '2*x**2 - 50'
newton = Newton(f)

newton.find_solution(1)