Created
May 24, 2018 16:55
-
-
Save herberthamaral/0ae974cb045d3fc19f6879cd3c728bea to your computer and use it in GitHub Desktop.
Dojo com fizzbuzz
This file contains hidden or 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
import unittest | |
def fizzbuzz(num): | |
retorno = '' | |
if num == 0: | |
return retorno | |
if num % 3 == 0: | |
retorno = 'fizz' | |
if num % 5 == 0: | |
retorno += 'buzz' | |
return retorno | |
class TestCase(unittest.TestCase): | |
def test_is_empty(self): | |
self.assertEqual(fizzbuzz(0), '') | |
def test_fizz_quando_divisivel_por_3(self): | |
self.assertEqual(fizzbuzz(3), 'fizz') | |
def test_vazio_quando_nao_divisivel(self): | |
self.assertEqual(fizzbuzz(4), '') | |
def test_buzz_quando_divisivel_por_5(self): | |
self.assertEqual(fizzbuzz(5), 'buzz') | |
def test_fizzbuzz_quando_por_5_e_3(self): | |
self.assertEqual(fizzbuzz(15), 'fizzbuzz') | |
def test_fizz_quando_negativo(self): | |
self.assertEqual(fizzbuzz(-3), 'fizz') | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment