Skip to content

Commit 1964c64

Browse files
committed
ex 28, 29. 30, 32, 34, 36, 37 changed
1 parent dd62b9a commit 1964c64

File tree

14 files changed

+147
-153
lines changed

14 files changed

+147
-153
lines changed
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
lines = []
2-
while True:
3-
s = input("")
4-
if s:
5-
lines.append(s.upper())
6-
else:
7-
break;
1+
def lines(text):
2+
return text.upper()
83

9-
for sentence in lines:
10-
print (sentence)
4+
print(lines('Hello world'))
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import pytest, io, sys, json, mock, re, os
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it('The solution should return the expected output')
5-
def test_input_output(capsys, app):
4+
@pytest.mark.it('The function lines must exist')
5+
def test_function_existence(capsys, app):
6+
assert app.lines
67

7-
fake_input = ["Hello world Practice makes perfect"]
8-
with mock.patch('builtins.input', lambda x: fake_input.pop(0)):
9-
app()
10-
captured = capsys.readouterr()
11-
assert captured.out == "HELLO WORLD PRACTICE MAKES PERFECT\n"
8+
@pytest.mark.it('The function should return the expected output')
9+
def test_expected_output(capsys, app):
10+
assert app.lines("hello world") == "HELLO WORLD"
11+
12+
@pytest.mark.it('The function should return the expected output')
13+
def test_another_output(capsys, app):
14+
assert app.lines("LeT the WOrld know YoU") == "LET THE WORLD KNOW YOU"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
s = input("")
2-
words = [word for word in s.split(" ")]
3-
print (" ".join(sorted(list(set(words)))))
1+
def remove_duplicate_words(text):
2+
words = text.split()
3+
return (" ".join(sorted(list(set(words)))))
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
import pytest, io, sys, json, mock, re, os
22

3-
@pytest.mark.it('Your solution should work as expected')
3+
@pytest.mark.it('The function remove_duplicate_words must exist')
4+
def test_function_existence(capsys, app):
5+
app.remove_duplicate_words
6+
7+
@pytest.mark.it('The function should return the expected output')
48
def test_expected_output(capsys, app):
5-
fake_input=['Hola como Hola']
6-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
7-
app()
8-
captured = capsys.readouterr()
9-
assert captured.out == "Hola como\n"
9+
assert app.remove_duplicate_words("hello world and practice makes perfect and hello world again") == "again and hello makes perfect practice world"
1010

11-
@pytest.mark.it('Your solution should work as expected')
11+
@pytest.mark.it('The function should work with other entries')
1212
def test_expected_output_2(capsys, app):
13-
fake_input=['ayer como ayer es hoy']
14-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
15-
app()
16-
captured = capsys.readouterr()
17-
assert captured.out == "ayer como es hoy\n"
13+
assert app.remove_duplicate_words("lets try this again with another try") == "again another lets this try with"
1814

15+
@pytest.mark.it('The function should work with other entries')
16+
def test_expected_output_3(capsys, app):
17+
assert app.remove_duplicate_words("Jacke was Named Jacke by his mother") == "Jacke Named by his mother was"
1918

20-
@pytest.mark.it('Your solution should work as expected')
21-
def test_expected_output_no_repetead(capsys, app):
22-
fake_input=['Hola como estas']
23-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
24-
app()
25-
captured = capsys.readouterr()
26-
assert captured.out == "Hola como estas\n"
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
value = []
2-
items=[x for x in input("").split(',')]
3-
for p in items:
4-
intp = int(p, 2)
5-
if not intp%5:
6-
value.append(p)
1+
def divisable_binary(text):
2+
value=[]
3+
items=[x for x in text.split(',')]
4+
for p in items:
5+
intp = int(p, 2)
6+
if not intp%5:
7+
value.append(p)
78

8-
print (','.join(value))
9+
return (','.join(value))
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest, io, sys, json, mock, re, os
22

3-
@pytest.mark.it('Your solution should work as expected')
3+
@pytest.mark.it('The function divisable_binary must exist')
4+
def test_function_existence(capsys, app):
5+
assert app.divisable_binary
6+
7+
@pytest.mark.it('The function should return the expected output')
48
def test_expected_output(capsys, app):
5-
fake_input=['0100,0011,1010,1001']
6-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
7-
app()
8-
captured = capsys.readouterr()
9-
assert captured.out == "1010\n"
9+
assert app.divisable_binary("0100,0011,1010,1001") == "1010"
1010

11-
@pytest.mark.it('Your solution should work with other parameters')
11+
@pytest.mark.it('The function should work with other parameters. testing with 1111,1000,0101,0000')
1212
def test_expected_output_2(capsys, app):
13-
fake_input=['1111,1000,0101,0000']
14-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
15-
app()
16-
captured = capsys.readouterr()
17-
assert captured.out == "1111,0101,0000\n"
13+
assert app.divisable_binary("1111,1000,0101,0000") == "1111,0101,0000"
14+
15+
@pytest.mark.it("The function should work with other parameters. Testing with 1000")
16+
def test_expected_output_3(capsys, app):
17+
assert app.divisable_binary("1000,1000,1000,1000") == ""
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
s = input("")
2-
d={"DIGITS":0, "LETTERS":0}
3-
for c in s:
4-
if c.isdigit():
5-
d["DIGITS"]+=1
6-
elif c.isalpha():
7-
d["LETTERS"]+=1
8-
else:
9-
pass
10-
print ("LETTERS", d["LETTERS"])
11-
print ("DIGITS", d["DIGITS"])
1+
def letters_and_digits(text):
2+
d={"DIGITS":0, "LETTERS":0}
3+
for c in text:
4+
if c.isdigit():
5+
d["DIGITS"]+=1
6+
elif c.isalpha():
7+
d["LETTERS"]+=1
8+
else:
9+
pass
10+
11+
return ("LETTERS {} DIGITS {}".format(d['LETTERS'], d['DIGITS']))
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import mock, pytest
1+
import mock, pytest, io, sys
22

3-
@pytest.mark.it('The solution should return the expected output')
3+
4+
@pytest.mark.it('The function letters_and_digits must exist')
5+
def test_function_existence(capsys, app):
6+
assert app.letters_and_digits
7+
8+
9+
@pytest.mark.it('The function should return the expected output')
410
def test_output(capsys, app):
5-
fake_input = ["hello world! 123"] #fake input
6-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
7-
app()
8-
captured = capsys.readouterr()
9-
assert captured.out != "LETTERS 10 DIGITS 3\n"
11+
app.letters_and_digits("hello world! 123") == "LETTERS 10 DIGITS 3"
1012

11-
@pytest.mark.it('The solution should work with others inputs')
12-
def test_output_2(capsys, app):
13-
fake_input = ["How are you 11111"] #fake input
14-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
15-
app()
16-
captured = capsys.readouterr()
17-
assert captured.out != "LETTERS 9 DIGITS 5\n"
13+
@pytest.mark.it('The solution should work with other parameters')
14+
def test_another_entry(capsys, app):
15+
assert app.letters_and_digits("My name is C200 and i live in apartment 3H") == "LETTERS 29 DIGITS 4"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
a = input("")
2-
n1 = int( "%s" % a )
3-
n2 = int( "%s%s" % (a,a) )
4-
n3 = int( "%s%s%s" % (a,a,a) )
5-
n4 = int( "%s%s%s%s" % (a,a,a,a) )
6-
print (n1+n2+n3+n4)
1+
def computed_value(param):
2+
n1 = int( "%s" % param )
3+
n2 = int( "%s%s" % (param,param) )
4+
n3 = int( "%s%s%s" % (param,param,param) )
5+
n4 = int( "%s%s%s%s" % (param,param,param,param) )
6+
return (n1+n2+n3+n4)

exercises/34-a_aa_aaa_aaaa/test.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import io, sys, pytest, os, re, mock
22

3-
@pytest.mark.it('The solution should return the expected output')
4-
def test_convert_inputs(capsys, app):
5-
6-
fake_input = ["9"] #fake input
7-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
8-
app()
9-
captured = capsys.readouterr()
10-
assert captured.out == "11106\n"
3+
@pytest.mark.it('The function computed_value must exist')
4+
def test_function_existence(capsys, app):
5+
assert app.computed_value
6+
7+
@pytest.mark.it('The function should return the expected output')
8+
def test_expected_output(capsys, app):
9+
assert app.computed_value(9) == 11106
10+
11+
@pytest.mark.it('The function should work with other enties. Testing with 123')
12+
def test_another_output(capsys, app):
13+
assert app.computed_value(123) == 123246369492
14+
15+
@pytest.mark.it('The function should work with other enties. Testing with 0')
16+
def test_with_zero(capsys, app):
17+
assert app.computed_value(0) == 0

0 commit comments

Comments
 (0)