Last active
October 13, 2015 14:36
-
-
Save airsoull/50632b476cd97e11b29e to your computer and use it in GitHub Desktop.
Katacode FizzBuzz with test
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
def fizzbuzz(number): | |
value = str() | |
if number % 3 == 0: | |
value += 'fizz' | |
if number % 5 == 0: | |
value += 'buzz' | |
return value or number |
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 | |
from fizzbuzz import fizzbuzz | |
class TestFizzBuzz(unittest.TestCase): | |
def test_simple_number(self): | |
self.assertEqual(fizzbuzz(1), 1) | |
self.assertEqual(fizzbuzz(2), 2) | |
self.assertEqual(fizzbuzz(4), 4) | |
def test_fizz(self): | |
self.assertEqual(fizzbuzz(3), 'fizz') | |
self.assertEqual(fizzbuzz(6), 'fizz') | |
self.assertEqual(fizzbuzz(9), 'fizz') | |
def test_buzz(self): | |
self.assertEqual(fizzbuzz(5), 'buzz') | |
self.assertEqual(fizzbuzz(10), 'buzz') | |
self.assertEqual(fizzbuzz(20), 'buzz') | |
def test_fizzbuzz(self): | |
self.assertEqual(fizzbuzz(15), 'fizzbuzz') | |
self.assertEqual(fizzbuzz(30), 'fizzbuzz') | |
self.assertEqual(fizzbuzz(45), 'fizzbuzz') | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment