Created
May 19, 2020 21:25
-
-
Save dunossauro/ff9c2d346ba05ee66887346ccd36c20a to your computer and use it in GitHub Desktop.
pythonMG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def soma(x, y): | |
"""Função que soma dois números.""" | |
return x + y | |
def subtracao(x, y): | |
"""Função que subrai dois números.""" | |
... | |
def expr(x, y, z): | |
""" | |
Uma expressão usando soma e subtração. | |
x + y - z | |
""" | |
return subtracao(soma(x, y), z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import TestCase, main | |
from unittest.mock import patch | |
from code import soma, expr | |
class CalculatorTest(TestCase): | |
def test_soma_com_0_1_deve_retornar_1(self): | |
x = 0 | |
y = 1 | |
esperado = 1 | |
self.assertEqual(soma(x, y), esperado) | |
def teste_expressao_com_1_1_1_deve_retonar_1(self): | |
x = 1 | |
y = 1 | |
z = 1 | |
esperado = 1 | |
with patch('code.subtracao', return_value=1): | |
self.assertEqual(expr(x, y, z), esperado) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment