def test_heron(self): """Tests heron()""" from kap5 import heron a = sqrt(2) self.assertAlmostEqual(heron(2), a, delta=1.e-12) self.assertAlmostEqual(heron(2, iters=10), a, delta=1.e-15) self.assertAlmostEqual(heron(2, iters=10, x0=100), a, delta=1e-12)
def test_heron_fehlerschaetzer(self): """Tests heron_fehlerschaetzer()""" from kap5 import heron_fehlerschaetzer as heron a = sqrt(2) self.assertAlmostEqual(heron(2, 1, 1.141), a, delta=1.e-12) self.assertAlmostEqual(heron(2, 1, 1.141, eps=1.e-15), a, delta=1.e-15) self.assertAlmostEqual(heron(2, 100, 1.141), a, delta=1e-12)
def test_heron_kombiniert(self): """Tests heron_kombiniert()""" from kap5 import heron_kombiniert as heron a = sqrt(2) self.assertAlmostEqual(heron(2, 1, 1.141), a, delta=1.e-12) self.assertAlmostEqual(heron(2, 1, 1.141, eps=1.e-15), a, delta=1.e-15) self.assertAlmostEqual(heron(2, 100, 1.141), a, delta=1e-12)
def test_heron_abbruchkriterium(self): """Tests heron_abbruchkriterium()""" from kap5 import heron_abbruchkriterium as heron a = sqrt(2) self.assertAlmostEqual(heron(2, 1), a, delta=1.e-12) self.assertAlmostEqual(heron(2, 1, eps=1.e-15), a, delta=1.e-15) self.assertAlmostEqual(heron(2, 100), a, delta=1e-12)
def test_heron_mpmath(self): """"Tests heron() with arbitrary precision""" from kap5 import heron from mpmath import mp mp.dps = 128 mp.pretty = False A = mp.mpf(('1.4142135623730950488016887242096980785696718753769480731' '766797379907324784621070388503875343276416016397857783845' '578298249912463702')) a = heron(mp.mpf(2), 7, mp.mpf(1.)) self.assertEqual(a, A)