Created
February 8, 2016 04:03
-
-
Save bylatt/954dff0b4ba870850b51 to your computer and use it in GitHub Desktop.
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 __init__(self, number): | |
| if FizzBuzz.is_valid_number(number): | |
| self.number = number | |
| @property | |
| def result(self): | |
| if FizzBuzz.is_divide_by(self.number, (3 * 5)): | |
| return "FizzBuzz" | |
| elif FizzBuzz.is_divide_by(self.number, 3): | |
| return "Fizz" | |
| elif FizzBuzz.is_divide_by(self.number, 5): | |
| return "Buzz" | |
| return self.number | |
| @staticmethod | |
| def is_valid_number(number): | |
| if number <= 0 or number >= 101: | |
| raise ValueError | |
| return True | |
| @staticmethod | |
| def is_divide_by(number, divider): | |
| if number % divider == 0: | |
| return True | |
| return False |
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_0_should_raise_value_error(self): | |
| with self.assertRaises(ValueError): | |
| FizzBuzz(0) | |
| def test_101_should_raise_value_error(self): | |
| with self.assertRaises(ValueError): | |
| FizzBuzz(101) | |
| def test_1_should_return_1(self): | |
| self.assertEqual(FizzBuzz(1).result, 1) | |
| def test_2_shuld_return_2(self): | |
| self.assertEqual(FizzBuzz(2).result, 2) | |
| def test_3_should_return_fizz(self): | |
| self.assertEqual(FizzBuzz(3).result, "Fizz") | |
| def test_6_shuold_return_fizz(self): | |
| self.assertEqual(FizzBuzz(6).result, "Fizz") | |
| def test_5_should_return_buzz(self): | |
| self.assertEqual(FizzBuzz(5).result, "Buzz") | |
| def test_10_should_return_buzz(self): | |
| self.assertEqual(FizzBuzz(10).result, "Buzz") | |
| def tset_15_should_return_fizzbuzz(self): | |
| self.assertEqual(FizzBuzz(15).result, "FizzBuzz") | |
| def test_30_should_return_fizzbuzz(self): | |
| self.assertEqual(FizzBuzz(30).result, "FizzBuzz") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment