comparison tests/test_derivative.py @ 83:1b61ce99ee82

derivative calculation: midpoint rule
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:51:13 -0800
parents
children
comparison
equal deleted inserted replaced
82:c05ce6b7f941 83:1b61ce99ee82
1 #!/usr/bin/env python
2
3 import os
4 import shutil
5 import tempfile
6 import unittest
7 from tvii import derivative
8
9 class TestDerivatives(unittest.TestCase):
10
11 def test_midpoint(self):
12 def cube(x):
13 return x**3
14
15 exact = 3
16 expected = 3.0001
17 got = derivative.midpoint(cube, 1, 0.01)
18 assert abs(expected - got) < 1e-6, "Expected {}; got {}".format(expected, got)
19
20 if __name__ == '__main__':
21 unittest.main()