Created
December 21, 2010 03:32
-
-
Save fzmaster/749448 to your computer and use it in GitHub Desktop.
Função do problema FizzBuzz
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
# -*- 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 |
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank's