~canonical-livepatch-dependencies/canonical-livepatch-service-dependencies/twisted

« back to all changes in this revision

Viewing changes to docs/core/howto/listings/trial/calculus/test/test_base_2b.py

  • Committer: Free Ekanayaka
  • Date: 2016-07-01 12:22:33 UTC
  • Revision ID: free.ekanayaka@canonical.com-20160701122233-nh55w514zwzoz1ip
Tags: upstream-16.2.0
ImportĀ upstreamĀ versionĀ 16.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from calculus.base_2 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_add(self):
 
17
        self._test(self.calc.add, 3, 8, 11)
 
18
 
 
19
 
 
20
    def test_subtract(self):
 
21
        self._test(self.calc.subtract, 7, 3, 4)
 
22
 
 
23
 
 
24
    def test_multiply(self):
 
25
        self._test(self.calc.multiply, 6, 9, 54)
 
26
 
 
27
 
 
28
    def test_divide(self):
 
29
        self._test(self.calc.divide, 12, 5, 2)