Created
October 19, 2018 16:13
-
-
Save airtonzanon/f7fd34c5601e6689f80121f865f8bc27 to your computer and use it in GitHub Desktop.
FizzBuzz implementation
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
class FizzBuzz: | |
def display(self): | |
return map(lambda n: ['fizz', 'buzz', 'fizzbuzz', n][[(True, False), (False, True), (True, True), (False, False)].index((n%3 == 0, n%5 == 0))], range(1,21)) |
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_display(self): | |
fizzBuzz = FizzBuzz() | |
self.assertEqual([1, 2, "fizz", 4, 'buzz', "fizz", 7, 8, "fizz", 'buzz', 11, "fizz", 13, 14, "fizzbuzz", 16, 17, "fizz", 19, 'buzz'], fizzBuzz.display()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment