Ejemplo n.º 1
0
 def test_mul(self):
     calc = Calculator(-100000, 100000)
     self.assertEqual(calc.mul(1, 1), 1)
     self.assertEqual(calc.mul(1, 0), 0)
     self.assertEqual(calc.mul(0, 1), 0)
     self.assertEqual(calc.mul(100, 10), 1000)
     self.assertEqual(calc.mul(1, 1), 1)
Ejemplo n.º 2
0
 def test_div(self):
     calc = Calculator(-100000, 100000)
     self.assertEqual(calc.div(1, 1), 1)
     self.assertEqual(calc.div(0, 1), 0)
     self.assertEqual(calc.div(100, 10), 10)
     self.assertEqual(calc.div(1, 1), 1)
     self.assertRaises(ZeroDivisionError, lambda: calc.div(1, 0))
Ejemplo n.º 3
0
 def test_valid(self):
     calc = Calculator(-100000, 100000)
     self.assertRaises(ValueTooLowException,
                       lambda: calc.div(-100000000000, 1))
     self.assertRaises(ValueTooHighException,
                       lambda: calc.div(100000000000, 1))
     self.assertRaises(ValueTooLowException,
                       lambda: calc.div(1, -100000000000))
     self.assertRaises(ValueTooHighException,
                       lambda: calc.div(1, 100000000000))
Ejemplo n.º 4
0
 def test_div_with_a_possitive_and_negative_number(self):
     c = Calculator()
     assert c.div(50,-10) == -5
Ejemplo n.º 5
0
 def test_mul_with_two_negative_numbers(self):
     c = Calculator()
     self.assertEqual(c.mul(-1, -8), 8)
Ejemplo n.º 6
0
 def test_mul_with_two_positive_numbers(self):
     c = Calculator()
     assert c.mul(5, 10) == 50
Ejemplo n.º 7
0
 def test_div_throws_e_when_dividing_by_zero(self):
     with pytest.raises(ZeroDivisionError):
         c = Calculator()
         c.div(50, 0)
Ejemplo n.º 8
0
 def test_div_with_two_negative_numbers(self):
     c = Calculator()
     assert c.div(-50, -10) == 5
Ejemplo n.º 9
0
 def test_mul_with_one_negative_one_positive_number(self):
     c = Calculator()
     assert c.mul(-5, 10) == -50
 def test_mul(self):
     c = Calculator()
     res = c.mul(3, 3)
     self.assertEqual(res, 9)
 def test_mul_with_one_negative_one_positive_number(self):
     c = Calculator()
     res = c.mul(-5, 5)
     self.assertEqual(res, -25)
 def test_mul_with_two_negative_numbers(self):
     c = Calculator()
     res = c.mul(-5, -5)
     self.assertEqual(res, 25)
Ejemplo n.º 13
0
 def setUp(self):
     self.calculator = Calculator()
Ejemplo n.º 14
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.calculator = Calculator()

    def test_mul_with_5_and_10(self):
        assert self.calculator.mul(5, 10) == 50

    def test_mul_with_two_positive_numbers(self):
        assert self.calculator.mul(3, 7) == 21

    def test_mul_with_two_negative_numbers(self):
        assert self.calculator.mul(-8, -4) == 32

    def test_mul_with_one_positive_and_one_negative_number(self):
        assert self.calculator.mul(6, -3) == -18

    def test_mul_raises_ValueError_if_a_too_high(self):
        with pytest.raises(ValueError):
            self.calculator.mul(1001, 2)

    def test_mul_raises_ValueError_if_a_too_low(self):
        with pytest.raises(ValueError):
            self.calculator.mul(-1001, 2)

    def test_mul_raises_ValueError_if_b_too_high(self):
        with pytest.raises(ValueError):
            self.calculator.mul(2, 1001)

    def test_mul_raises_ValueError_if_b_too_low(self):
        with pytest.raises(ValueError):
            self.calculator.mul(2, -1001)

    def test_div_with_two_positive_numbers(self):
        assert self.calculator.div(10, 5) == 2
    
    def test_div_with_two_negative_numbers(self):
        assert self.calculator.div(-20, -5) == 4

    def test_div_with_one_negative_and_one_positive(self):
        assert self.calculator.div(-30, 5) == -6

    def test_div_raises_ValueError_a_too_high(self):
        with pytest.raises(ValueError):
            self.calculator.div(1001, 2)

    def test_div_raises_ValueError_b_too_high(self):
        with pytest.raises(ValueError):
            self.calculator.div(2, 1001)

    def test_div_raises_ValueError_a_too_low(self):
        with pytest.raises(ValueError):
            self.calculator.div(-1001, 2)

    def test_div_raises_ValueError_b_too_low(self):
        with pytest.raises(ValueError):
            self.calculator.div(2, -1001)

    def test_div_raises_divide_by_zero_exception(self):
        with pytest.raises(ZeroDivisionError):
            self.calculator.div(2, 0)
Ejemplo n.º 15
0
 def test_div_with_out_of_bounds_throws_e(self):
     with pytest.raises(ValueError):
         calculator = Calculator()
         calculator.div(-1001,100)
 def test_mul_with_two_positive_numbers(self):
     c = Calculator()
     res = c.mul(5, 5)
     self.assertEqual(res, 25)
Ejemplo n.º 17
0
 def test_div_by_zero(self):
     with pytest.raises(ZeroDivisionError):
         calculator = Calculator()
         calculator.div(50,0)
Ejemplo n.º 18
0
 def test_mul(self):
     assert Calculator().mul(100, 10) == 1000
Ejemplo n.º 19
0
 def test_div_with_two_positive_numbers(self):
     c = Calculator()
     assert c.div(50, 10) == 5
Ejemplo n.º 20
0
 def test_div(self):
     assert Calculator().div(100, 10) == 10
Ejemplo n.º 21
0
 def test_div_with_one_negative_one_positive_number(self):
     c = Calculator()
     assert c.div(-50, 10) == -5
Ejemplo n.º 22
0
 def test_div(self):
     c = Calculator()
     pass
Ejemplo n.º 23
0
 def test_div_throws_e_when_out_of_bounds_low(self):
     with pytest.raises(ValueError):
         c = Calculator()
         c.div(-1001,100)
Ejemplo n.º 24
0
 def test_mul_with_two_positive_numbers(self):
     c = Calculator()
     self.assertEqual(c.mul(22, 10), 220)
Ejemplo n.º 25
0
 def test_mul_with_two_negative_numbers(self):
     c = Calculator()
     assert c.mul(-5, -10) == 50
Ejemplo n.º 26
0
 def test_boundaries(self):
     calc = Calculator(-100, 100)
     self.assertRaises(ValueTooLowException, lambda: calc.div(-101, 1))
     self.assertRaises(ValueTooHighException, lambda: calc.mul(101, 1))
     self.assertEqual(calc.div(-100, 1), -100)
     self.assertEqual(calc.mul(100, 1), 100)