Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dojo com fizzbuzz
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
You can’t perform that action at this time.