Skip to content

Instantly share code, notes, and snippets.

@fzmaster
Created December 21, 2010 03:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzmaster/749448 to your computer and use it in GitHub Desktop.
Save fzmaster/749448 to your computer and use it in GitHub Desktop.
Função do problema FizzBuzz
# -*- coding:utf-8 -*-
def executaFizzBuzz(numero):
"""
Autor: fzmaster
Data: 21/12/2010
Problema: Fizz Buzz
http://codingkata.org/katas/unit/fizz-buzz
Esta é a função responsável por converter múltiplos de 3 em 'fizz', múltiplos de 5 em 'buzz' e múltiplos de ambos
em 'fizz-buzz'. Números não divisíveis, são retornados normalmente.
"""
if numero % 5 == 0 and numero % 3 == 0:
return 'fizz-buzz'
elif numero % 3 == 0:
return 'fizz'
elif numero % 5 == 0:
return 'buzz'
else:
return numero
import unittest
from fizzbuzz import *
class FizzBuzzTestCase(unittest.TestCase):
def test_retornaFizzBuzz_com_1(self):
assert executaFizzBuzz(1) == 1
def test_retornaFizzBuzz_com_2(self):
assert executaFizzBuzz(2) == 2
def test_retornaFizzBuzz_com_3(self):
assert executaFizzBuzz(3) == 'fizz'
def test_retornaFizzBuzz_com_4(self):
assert executaFizzBuzz(4) == 4
def test_retornaFizzBuzz_com_5(self):
assert executaFizzBuzz(5) == 'buzz'
def test_retornaFizzBuzz_com_15(self):
assert executaFizzBuzz(15) == 'fizz-buzz'
def test_retornaFizzBuzz_com_25(self):
assert executaFizzBuzz(25) == 'buzz'
def test_retornaFizzBuzz_com_99(self):
assert executaFizzBuzz(99) == 'fizz'
def test_retornaFizzBuzz_com_125(self):
assert executaFizzBuzz(125) == 'buzz'
if __name__ == '__main__':
unittest.main()
@fabiodex
Copy link

thank's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment