Created
July 16, 2011 11:51
-
-
Save mattyw/1086293 to your computer and use it in GitHub Desktop.
The Fizzbuzz kata in Python
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(value): | |
if value % 5 == 0 and value % 3 == 0: | |
return 'fizzbuzz' | |
elif value % 5 == 0: | |
return 'buzz' | |
elif value % 3 == 0: | |
return 'fizz' | |
else: | |
return value | |
class FizzBuzzTest(unittest.TestCase): | |
def setUp(self): | |
pass | |
def test_fizz(self): | |
self.assertEqual('fizz', fizzbuzz(3)) | |
def test_value(self): | |
self.assertEqual(2, fizzbuzz(2)) | |
def test_buzz(self): | |
self.assertEqual('buzz', fizzbuzz(5)) | |
def test_fizzbuzz(self): | |
self.assertEqual('fizzbuzz', fizzbuzz(15)) | |
if __name__ == '__main__': | |
unittest.main() | |
#for x in xrange(1,101): | |
# print fizzbuzz(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment