Skip to content

Instantly share code, notes, and snippets.

@iwangu
Created March 16, 2016 19:03
Show Gist options
  • Save iwangu/11d84cb6d045e301d33d to your computer and use it in GitHub Desktop.
Save iwangu/11d84cb6d045e301d33d to your computer and use it in GitHub Desktop.
import unittest
def f(x, i): return i % x == 0
def f5(i): return f(5, i)
def f3(i): return f(3, i)
def f7(i): return f(7, i)
def fizzbuzz(c):
if f5(c) and f3(c):
return 'BingoBongo'
elif f3(c):
return 'Bingo'
elif f5(c):
return 'Bongo'
elif f7(c):
return 'Conga'
else:
return c
def fizzbuzz_all(c):
result_list = []
for i in range(1, c + 1):
result_list.append(fizzbuzz(i))
return result_list
class Test(unittest.TestCase):
def test_business_as_usual(self):
'''
test that an integer >= 0 not evenly divisible
by three or five returns the same
'''
self.assertEqual(fizzbuzz(1), 1)
self.assertEqual(fizzbuzz(2), 2)
self.assertEqual(fizzbuzz(3), 'Bingo')
self.assertEqual(fizzbuzz(7), 'Conga')
self.assertEqual(fizzbuzz_all(10), [1, 2, 'Bingo', 4, 'Bongo', 'Bingo', 'Conga', 8, 'Bingo', 'Bongo'])
def main():
unittest.main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment