1#!/usr/bin/env python
2
3from __future__ import print_function
4import unittest
5import pygsl.diff
6
7lone = lambda x: x**3
8ltwo = lambda x, y: x**3
9lthree = lambda x, y: x**3 * y
10lfour = lambda x, y: (x**3, y)
11
12def lfive(x, args):
13    return x**3, 1
14
15class _TestDiff(unittest.TestCase):
16    func = None
17    def test1(self):
18        self.failUnlessRaises(TypeError, self.func, lone, 1)
19
20    def test2(self):
21        tmp = self.func(ltwo, 1)
22        test = 0
23        try:
24            assert((tmp[0] - 3) < tmp[1]*5)
25            test = 1
26        finally:
27            if test == 0:
28                print ("I recieved %s. But it should be (3, ??)" % (tmp,))
29
30    def test3(self):
31        tmp = self.func(lthree, 1, 2)
32        test = 0
33        try:
34            assert((tmp[0] - 3*2) < tmp[1]*5)
35            test = 1
36        finally:
37            if test == 0:
38                print ("I recieved %s. But it should be (3, ??)" % (tmp,))
39
40    def test4(self):
41        """
42        Check if it flags an error if not a float is returned
43
44        Why is it put to float, and not the number of arguments are checked?XF
45        """
46        self.failUnlessRaises(TypeError, self.func, lfour, 1)
47
48    def test5(self):
49        """
50        Check if it flags an error if more than a float is returned
51        """
52        self.failUnlessRaises(TypeError, self.func, lfour, 1)
53
54class TestCentral(_TestDiff):
55    func = pygsl.diff.central
56
57class TestForward(_TestDiff):
58    func = pygsl.diff.forward
59
60class TestBackward(_TestDiff):
61    func = pygsl.diff.backward
62
63del _TestDiff
64if __name__ == '__main__':
65    unittest.main()
66