-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_icalc.py
125 lines (87 loc) · 4.28 KB
/
test_icalc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import icalc
import pytest
class TestIcalcClass:
@pytest.mark.parametrize("test_input,expected", [("3 5", "8\n"), ("2 4", "6\n"), ("6 9", "15\n")])
def test_interactive_mode_add(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_add(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("3 5", "-2\n"), ("12 5", "7\n"), ("6 -9", "15\n")])
def test_interactive_mode_sub(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_sub(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("5555 5", "1111\n"), ("-54 9", "-6\n"), ("-35 -5", "7\n"), ("10 4", "2.5\n")])
def test_interactive_mode_div(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_div(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("10 5", "50\n"), ("232 0", "0\n"), ("6 -9", "-54\n")])
def test_interactive_mode_mul(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_mul(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("13 5", "3\n"), ("8 4", "0\n"), ("-35 -5", "0\n")])
def test_interactive_mode_rem(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_rem(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("9", "3\n"), ("0", "0\n"), ("25", "5\n")])
def test_interactive_mode_sqrt(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_sqrt(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156 52", "168\n"), ("351 21", "330\n"), ("159 65", "222\n")])
def test_interactive_mode_bxor(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_xor(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156 2", "39\n"), ("354 3", "44\n"), ("159 1", "79\n")])
def test_interactive_mode_bshr(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_shift_right(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156 2", "624\n"), ("354 3", "2832\n"), ("159 1", "318\n")])
def test_interactive_mode_bshl(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_shift_left(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156 52", "188\n"), ("351 21", "351\n"), ("159 65", "223\n")])
def test_interactive_mode_bor(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_or(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156", "-157\n"), ("351", "-352\n"), ("159", "-160\n")])
def test_interactive_mode_bnot(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_not(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''
@pytest.mark.parametrize("test_input,expected", [("156 52", "20\n"), ("351 21", "21\n"), ("159 65", "1\n")])
def test_interactive_mode_band(self, capsys, test_input, expected):
calc = icalc.InteractiveCalculator()
calc.do_bit_and(test_input)
out, err = capsys.readouterr()
assert out == expected
assert err == ''