Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / trial / calculus / test / test_base_3.py
1 from calculus.base_3 import Calculation
2 from twisted.trial import unittest
3
4
5
6 class CalculationTestCase(unittest.TestCase):
7     def setUp(self):
8         self.calc = Calculation()
9
10
11     def _test(self, operation, a, b, expected):
12         result = operation(a, b)
13         self.assertEqual(result, expected)
14
15
16     def _test_error(self, operation):
17         self.assertRaises(TypeError, operation, "foo", 2)
18         self.assertRaises(TypeError, operation, "bar", "egg")
19         self.assertRaises(TypeError, operation, [3], [8, 2])
20         self.assertRaises(TypeError, operation, {"e": 3}, {"r": "t"})
21
22
23     def test_add(self):
24         self._test(self.calc.add, 3, 8, 11)
25
26
27     def test_subtract(self):
28         self._test(self.calc.subtract, 7, 3, 4)
29
30
31     def test_multiply(self):
32         self._test(self.calc.multiply, 6, 9, 54)
33
34
35     def test_divide(self):
36         self._test(self.calc.divide, 12, 5, 2)
37
38
39     def test_errorAdd(self):
40         self._test_error(self.calc.add)
41
42
43     def test_errorSubtract(self):
44         self._test_error(self.calc.subtract)
45
46
47     def test_errorMultiply(self):
48         self._test_error(self.calc.multiply)
49
50
51     def test_errorDivide(self):
52         self._test_error(self.calc.divide)