Skip to content

Commit 7474de9

Browse files
committed
04-area_of_right_triangle
1 parent 1619ee4 commit 7474de9

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

exercises/04-area_of_right_triangle/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def area_of_triangle(arg1, arg2):
66
#your code here, please remove the "None"
7-
return None
7+
return int(arg1) * int(arg2) / 2
88

99
# Testing your function
1010
print(area_of_triangle(b, h))
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import io, sys, os, pytest, json, mock
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
3+
4+
35
@pytest.mark.it('The function area_of_triangle should exist')
46
def test_function_exists(capsys):
5-
67
try:
78
import app
89
app.area_of_triangle
910
except AttributeError:
1011
raise AttributeError("The function 'area_of_triangle' should exist on app.py")
1112

12-
@pytest.mark.it('Calculate the area of the triangle.')
13-
def test_area_of_triangle(stdin):
14-
15-
_stdin = json.loads(stdin)
16-
with mock.patch('builtins.input', lambda x: _stdin.pop(0)):
17-
18-
sys.stdout = buffer = io.StringIO()
19-
import app
20-
_stdin = json.loads(stdin)
21-
result = int(_stdin[0]) * int(_stdin[1]) / 2
22-
assert buffer.getvalue() == str(result) + "\n"
13+
@pytest.mark.it('The solution should return the expected output')
14+
def test_convert_inputs(capsys, app):
15+
app.area_of_triangle(3,5)
16+
captured = capsys.readouterr()
17+
assert "7.5\n" == captured.out
18+
# from app import area_of_triangle
19+
# result = area_of_triangle(3,5)
20+
# assert result == "7.5\n"
2321

2422

exercises/22-Integral/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest,os,re,io,sys, mock, json
22

33

4-
@pytest.mark.it('Almost there! But you need to convert the incoming input from string to integer')
4+
@pytest.mark.it('The solution should return the expected output')
55
def test_convert_inputs(capsys, app):
66

77
fake_input = ["8"] #fake input
@@ -11,7 +11,7 @@ def test_convert_inputs(capsys, app):
1111
assert captured.out == "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n"
1212

1313

14-
@pytest.mark.it('Almost there! But you need to convert the incoming input from string to integer')
14+
@pytest.mark.it('The solution should work with other entries')
1515
def test_convert_inputs_2(capsys, app):
1616

1717
fake_input = ["5"] #fake input

0 commit comments

Comments
 (0)