Skip to content

Commit 1619ee4

Browse files
committed
22-Integral
1 parent 7e44ea7 commit 1619ee4

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

exercises/22-Integral/solution.hide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
n=int(input(""))
1+
n=int(input("Insert a number"))
22
d=dict()
33
for i in range(1,n+1):
44
d[i]=i*i

exercises/22-Integral/test.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import pytest,os,re,io,sys, mock, json, unittest
2-
from unittest.mock import patch
1+
import pytest,os,re,io,sys, mock, json
32

43

5-
# @pytest.mark.it('The solution should work with other entries')
6-
# def test_expected_output_5(stdin):
4+
@pytest.mark.it('Almost there! But you need to convert the incoming input from string to integer')
5+
def test_convert_inputs(capsys, app):
76

8-
# _stdin = ['5']
9-
# with mock.patch('builtins.input', lambda x: _stdin.pop(0)):
7+
fake_input = ["8"] #fake input
8+
with mock.patch('builtins.input', lambda x: fake_input.pop()):
9+
app()
10+
captured = capsys.readouterr()
11+
assert captured.out == "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n"
1012

11-
# sys.stdout = buffer = io.StringIO()
12-
# import app
13-
# # _stdin = json.loads(stdin)
14-
# result = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
15-
# assert buffer.getvalue() == str(result) + "\n"
1613

17-
@pytest.mark.it('The solution should return the expected output')
18-
def test_expected_output_8(stdin):
14+
@pytest.mark.it('Almost there! But you need to convert the incoming input from string to integer')
15+
def test_convert_inputs_2(capsys, app):
16+
17+
fake_input = ["5"] #fake input
18+
with mock.patch('builtins.input', lambda x: fake_input.pop()):
19+
app()
20+
captured = capsys.readouterr()
21+
assert captured.out == "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n"
1922

20-
_stdin = ['8']
21-
with mock.patch('builtins.input', lambda x: _stdin.pop(0)):
2223

23-
sys.stdout = buffer = io.StringIO()
24-
import app
25-
# _stdin = json.loads(stdin)
26-
result = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
27-
assert buffer.getvalue() == str(result) + "\n"

0 commit comments

Comments
 (0)