Skip to content
2 changes: 1 addition & 1 deletion exercises/03-Print-Variables-In-The-Console/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_for_printing_variable():

with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"print(\s*)\(\s*color\s*\)")
regex = re.compile(r"print\s*\(\s*color\s*\)")
assert bool(regex.search(content)) == True

@pytest.mark.it('The printed value on the console should be "red"')
Expand Down
5 changes: 3 additions & 2 deletions exercises/04-Multiply-Two-Values/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def test_use_variable_name():
def test_for_file_output(capsys):
captured = buffer.getvalue()
assert captured == '17172435\n'

@pytest.mark.it('Print on the console the variables_are_cool variable')
def test_for_print():

with open(path, 'r') as content_file:
content = content_file.read()
# makes sure we are calling print function with a variable and not the hard coded value
regex = re.compile(r"print\s*\(\s*[^\d\W][_a-zA-Z0-9]*\s*\)\s*")
regex = re.compile(r"print\s*\(\s*variables_are_cool\s*\)")
assert bool(regex.search(content)) == True
1 change: 0 additions & 1 deletion exercises/05-User-Inputed-Values/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def test_for_file_output(capsys):
regex = re.compile(pattern)
assert bool(regex.search(content)) == True


@pytest.mark.it("We tried with age 50 and it was supposed to return 60")
@mock.patch('builtins.input', lambda x: 50)
def test_plus_ten(stdin):
Expand Down
13 changes: 3 additions & 10 deletions exercises/06-String-Concatenation/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def test_my_var1_exists():
except ImportError:
raise ImportError("The variable 'my_var1' should exist on app.py")


@pytest.mark.it("Create a variable named my_var2")
def test_my_var2_exists():
try:
Expand All @@ -24,9 +23,10 @@ def test_my_var1_value():
assert my_var1 == "Hello"

@pytest.mark.it("Variable my_var2 value should be 'World'")
def test_my_var1_value():
def test_my_var2_value():
from app import my_var2
assert my_var2 == "World"

@pytest.mark.it("Variable my_var2 value should be 'World'")
def test_the_new_string_exists():
import app
Expand All @@ -38,11 +38,4 @@ def test_the_new_string_exists():
@pytest.mark.it('Print "Hello World" on the console')
def test_for_file_output():
captured = buffer.getvalue()
assert captured == "Hello World\n" #add \n because the console jumps the line on every print
def test_for_print_variable():

with open(path, 'r') as content_file:
content = content_file.read()
# makes sure we are calling print function with a variable and not the hard coded string
regex = re.compile(r"print\s*\(\s*[^\d\W][_a-zA-Z0-9]*\s*\)\s*")
assert bool(regex.search(content)) == True
assert captured == "Hello World\n" #add \n because the console jumps the line on every print
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `08` Your First If...
# `08.1` Your First If...

La aplicación actual está preguntando cuánto dinero tiene el usuario. Una vez el usuario ingresa la cantidad, debemos 'imprimir' usando **print** una de las siguientes respuestas:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tutorial: "https://www.youtube.com/watch?v=x9wqa5WQZiM"
---

# `08` Your First if...
# `08.1` Your First if...

The current application is prompting asking how much money the user has. Once the user inputs the amount, we need to **print** one of the following answers:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
total = int(input('How much money do you have in your pocket\n'))

# YOUR CODE HERE
# YOUR CODE HERE
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def test_for_print(capsys):
content = content_file.read()
regex = re.compile(r"if\s*")
regex2 = re.compile(r"elif\s*")
assert bool(regex.search(content)) == True or bool(regex.search(content))==False
assert ((bool(regex.search(content)) == True) and (bool(regex2.search(content))==True))

@pytest.mark.it('Use the function print()')
def test_for_print(capsys):
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"print\(.+\)")
regex = re.compile(r"print\s*\(")
assert bool(regex.search(content)) == True

@pytest.mark.it("When input for more than 100 it should print: Give me your money!")
Expand Down Expand Up @@ -64,8 +64,4 @@ def test_for_output_when_49(capsys, app):
with mock.patch('builtins.input', lambda x: 49):
app()
captured = capsys.readouterr()
assert "You are a poor guy, go away!\n" == captured.out




assert "You are a poor guy, go away!\n" == captured.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `08.1` Cuánto costará la boda (if...else)
# `08.2` Cuánto costará la boda (if...else)

Aquí tenemos una tabla de precios de una compañía de catering de bodas:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tutorial: "https://www.youtube.com/watch?v=Wu7uK8BN4nI"
---

# `08.1` How Much The Wedding Costs (if...else)
# `08.2` How Much The Wedding Costs (if...else)

Here is a table of prices for a wedding catering company:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_for_print(capsys):
with open(path, 'r') as content_file:
content = content_file.read()
regex2 = re.compile(r"elif\s*")
assert bool(regex2.search(content)) == True or bool(regex2.search(content)) == False
assert bool(regex2.search(content)) == True

@pytest.mark.it("Between 101 and 199 guests sould be priced 15,000")
def test__between_100_and_200(capsys, app):
Expand Down
10 changes: 10 additions & 0 deletions exercises/09-Random-Numbers/solution.hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import random

def get_randomInt():
# CHANGE ONLY THIS LINE BELOW
random_number = random.randint(1,10)
return random_number



print(get_randomInt())
55 changes: 34 additions & 21 deletions exercises/09-Random-Numbers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,45 @@
import pytest
import os
import re
import app

@pytest.mark.it("You should edit the function randint() to generate a random number between 1 and 10")
def test_conditional():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
pattern = r"random_number(\s*)=(\s*)random\.rand\w+(\s)*\((\s)*1(\s)*,(\s)*10(\s)*\)"
regex = re.compile(pattern)
assert bool(regex.search(content)) == True

@pytest.mark.it("You should only change line 5")
@pytest.mark.it("You should be printing the get_randomInt function")
def test_only_change_line_5():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
line_1 = r"import(\s)random"
line_2 = r"def(\s)get_randomInt\((\s*)\)(\s*)\:"
line_3 = r"return(\s)random_number"
line_4 = r"print(\s*)\(get_randomInt(\s*)\((\s*)\)(\s*)\)"
line = r"print\s*\(\s*get_randomInt\s*\(\s*\)\s*\)"
regex = re.compile(line)
assert bool(regex.search(content)) == True

@pytest.mark.it("get_randomInt function should exist")
def test_function_exists():
try:
assert app.get_randomInt()
except AttributeError:
raise AttributeError('The function "get_randomInt" should exist')

regex_1 = re.compile(line_1)
regex_2 = re.compile(line_2)
regex_3 = re.compile(line_3)
regex_4 = re.compile(line_4)
@pytest.mark.it("get_randomInt function should return a random integer between 1 and 10")
def test_function_returns_random_integer():
try:
for i in range(10):
# only asserting if value is outside the range, else it will pass
result = app.get_randomInt()
assert result >= 1 and result <= 10
except AttributeError:
raise AttributeError('The function "get_randomInt" is returning values outside the specified range')

assert bool(regex_1.search(content)) == True
assert bool(regex_2.search(content)) == True
assert bool(regex_3.search(content)) == True
assert bool(regex_4.search(content)) == True
@pytest.mark.it("get_randomInt function should NOT be returning a static integer value")
# in case user returns single value between [1 and 10]
def test_function_return_no_static():
try:
tries = 0
output = app.get_randomInt()
for i in range(10):
if output == app.get_randomInt():
tries+=1
# only asserting if value is outside the range, else it will pass
assert tries < 10
except AttributeError:
raise AttributeError('The function "get_randomInt" is returning a static value, not a random one')