Exemplo n.º 1
0
class TestMultiply(unittest.TestCase):
    def setUp(self):
        self.calc = Calc()

    def test_multiply_int(self):
        result = self.calc.multiply(10, 15)
        self.assertEqual(result, 150)

    def test_multiply_float(self):
        result = self.calc.multiply(15.1, 10.2)
        self.assertEqual(round(result, 2), 154.02)

    def test_multiply_str(self):
        with self.assertRaises(TypeError):
            self.calc.multiply('aaa', 'bbb')

    def test_multiply_int_str(self):
        result = self.calc.multiply(2, 'aa')
        self.assertEqual(result, 'aaaa')
Exemplo n.º 2
0
class TestCalc(unittest.TestCase):
    """Basic calculator with add, subrtract, multiply and divide functions
    """

    def setUp(self):
        self.calc = Calc()

    def test_add(self):
        self.assertEqual(self.calc.add(20, 10), 30, "incorrect addition")

    def test_subtract(self):
        self.assertEqual(self.calc.subtract(20, 10), 10, "incorrect subtraction")

    def test_multiply(self):
        self.assertEqual(self.calc.multiply(20, 10), 200, "incorrect multiplication")

    def test_divide(self):
        self.assertEqual(self.calc.divide(20, 10), 2, "incorrect division")
Exemplo n.º 3
0
     except:
         exception()
 elif choice == 2:
     try:
         a = float(input("Enter your 1st number to substract: "))
         b = float(input("Enter your 2nd number to substract: "))
         cal.substract(a,b)
         time.sleep(2)
         menu()
     except:
         exception()
 elif choice == 3:
     try:
         a = float(input("Enter your 1st number to multiply: "))
         b = float(input("Enter your 2nd number to multiply: "))
         cal.multiply(a,b)
         time.sleep(2)
         menu()
     except:
         exception()
 elif choice == 4:
     try:
         a = float(input("Enter your 1st number to divide: "))
         b = float(input("Enter your 2nd number to divide: "))
         cal.divide(a,b)
         time.sleep(2)
         menu()
     except:
         exception()
 elif choice == 5:
     try: