|
| 1 | +import math |
| 2 | +import sys |
| 3 | +import pytest |
| 4 | +import calculator |
| 5 | + |
| 6 | + |
| 7 | +class TestSumClass: |
| 8 | + calc = calculator.Calculator() |
| 9 | + |
| 10 | + def test_Sum(self): |
| 11 | + assert self.calc.add(3, 5) == 8 |
| 12 | + |
| 13 | + def test_SumOneNegative(self): |
| 14 | + assert self.calc.add(-5, 5) == 0 |
| 15 | + |
| 16 | + def test_SumTwoNegative(self): |
| 17 | + assert self.calc.add(-5, -5) == -10 |
| 18 | + |
| 19 | + def test_TypeError(self): |
| 20 | + with pytest.raises(TypeError): |
| 21 | + self.calc.add(3, '6') |
| 22 | + |
| 23 | + def pytest_sessionfinish(self): |
| 24 | + print("*** test run reporting finishing") |
| 25 | + |
| 26 | + |
| 27 | +class TestSubClass: |
| 28 | + calc = calculator.Calculator() |
| 29 | + |
| 30 | + def test_Sub(self): |
| 31 | + assert self.calc.sub(3, 5) == -2 |
| 32 | + |
| 33 | + def test_SubOneNegative(self): |
| 34 | + assert self.calc.sub(-5, 5) == -10 |
| 35 | + |
| 36 | + def test_SubTwoNegative(self): |
| 37 | + assert self.calc.sub(-5, -5) == 0 |
| 38 | + |
| 39 | + def test_TypeError(self): |
| 40 | + with pytest.raises(TypeError): |
| 41 | + self.calc.add(3, '6') |
| 42 | + |
| 43 | + |
| 44 | +class TestMulClass: |
| 45 | + calc = calculator.Calculator() |
| 46 | + |
| 47 | + def test_MultipleWithZero(self): |
| 48 | + assert self.calc.mul(213213, 0) == 0 |
| 49 | + |
| 50 | + def test_Multiple(self): |
| 51 | + assert self.calc.mul(12, 22) == 264 |
| 52 | + |
| 53 | + def test_MultipleOneNegative(self): |
| 54 | + assert self.calc.mul(12, -3) == -36 |
| 55 | + |
| 56 | + def test_MultipleTwoNegative(self): |
| 57 | + assert self.calc.mul(-35, -22) == 770 |
| 58 | + |
| 59 | + def test_TypeError(self): |
| 60 | + with pytest.raises(TypeError): |
| 61 | + self.calc.add(3, '6') |
| 62 | + |
| 63 | + |
| 64 | +class TestDivClass: |
| 65 | + calc = calculator.Calculator() |
| 66 | + |
| 67 | + def test_DivisionWithZero(self): |
| 68 | + with pytest.raises(ZeroDivisionError): |
| 69 | + self.calc.div(213213, 0) == 0 |
| 70 | + |
| 71 | + def test_Division(self): |
| 72 | + assert self.calc.div(5555, 5) == 1111 |
| 73 | + |
| 74 | + def test_DivisionOneNegative(self): |
| 75 | + assert self.calc.div(-54, 9) == -6 |
| 76 | + |
| 77 | + def test_DivisionTwoNegative(self): |
| 78 | + assert self.calc.div(-35, -5) == 7 |
| 79 | + |
| 80 | + def test_DivisionPart(self): |
| 81 | + assert self.calc.div(10, 4) == 2.5 |
| 82 | + |
| 83 | + def test_TypeError(self): |
| 84 | + with pytest.raises(TypeError): |
| 85 | + self.calc.add(3, '6') |
| 86 | + |
| 87 | + |
| 88 | +class TestRemClass: |
| 89 | + calc = calculator.Calculator() |
| 90 | + |
| 91 | + def test_RemWithZero(self): |
| 92 | + with pytest.raises(ZeroDivisionError): |
| 93 | + self.calc.div(24, 0) == 0 |
| 94 | + |
| 95 | + def test_Rem(self): |
| 96 | + assert self.calc.rem(13, 5) == 3 |
| 97 | + |
| 98 | + def test_RemOneNegative(self): |
| 99 | + assert self.calc.rem(-13, 5) == -13 - (math.floor((-13/5)) * 5) |
| 100 | + |
| 101 | + def test_RemTwoNegative(self): |
| 102 | + assert self.calc.rem(-35, -5) == -35 - math.floor(-35/-5) * -5 |
| 103 | + |
| 104 | + def test_TypeError(self): |
| 105 | + with pytest.raises(TypeError): |
| 106 | + self.calc.add(3, '6') |
| 107 | + |
| 108 | + |
| 109 | +class TestSqrtClass: |
| 110 | + calc = calculator.Calculator() |
| 111 | + |
| 112 | + |
| 113 | +class TestChecksumClass: |
| 114 | + calc = calculator.Calculator() |
| 115 | + |
| 116 | + |
| 117 | +class TestBandClass: |
| 118 | + calc = calculator.Calculator() |
| 119 | + |
| 120 | + |
| 121 | +class TestBorClass: |
| 122 | + calc = calculator.Calculator() |
| 123 | + |
| 124 | + |
| 125 | +class TestBxorClass: |
| 126 | + calc = calculator.Calculator() |
| 127 | + |
| 128 | + |
| 129 | +class TestBnotClass: |
| 130 | + calc = calculator.Calculator() |
| 131 | + |
| 132 | + |
| 133 | +class TestBshlClass: |
| 134 | + calc = calculator.Calculator() |
| 135 | + |
| 136 | + |
| 137 | +class TestBshrClass: |
| 138 | + calc = calculator.Calculator() |
0 commit comments