def testPlayTenFirstNumbers(self): self.assertEqual(self.game.play(1), "1", 'incorrect reponse for 1') self.assertEqual(self.game.play(2), "Fizz", 'incorrect reponse for 2') self.game = FizzBuzz() self.assertEqual(self.game.play(3), "3", 'incorrect reponse for 3') self.assertEqual(self.game.play(4), "Fizz", 'incorrect reponse for 4') self.assertEqual(self.game.play(5), "Buzz", 'incorrect reponse for 5') self.assertEqual(self.game.play(6), "Fizz", 'incorrect reponse for 6') self.assertEqual(self.game.play(7), "7", 'incorrect reponse for 7') self.assertEqual(self.game.play(8), "Fizz", 'incorrect reponse for 8') self.assertEqual(self.game.play(9), "9", 'incorrect reponse for 9') self.assertEqual(self.game.play(10), self.game.name, 'incorrect reponse for 10')
class TestFizzBuzz(unittest.TestCase): def setUp(self): self.fizzbuzz = FizzBuzz() def tearDown(self): pass def test_fizzbuzz_value_3_returns_fizz(self): self.assertEqual(self.fizzbuzz.value(3), 'fizz') def test_fizzbuzz_value_5_returns_buzz(self): self.assertEqual(self.fizzbuzz.value(5), 'buzz') def test_fizzbuzz_value_15_returns_fizzbuzz(self): self.assertEqual(self.fizzbuzz.value(15), 'fizzbuzz') def test_fizzbuzz_value_7_returns_buzz(self): self.assertEqual(self.fizzbuzz.value(7), 7)
def testPlayTenFirstNumbersInString(self): self.assertEqual(self.game.play("1"), "1", 'incorrect reponse for 1') self.assertEqual(self.game.play("2"), "Fizz", 'incorrect reponse for 2') self.game = FizzBuzz() self.assertEqual(self.game.play("3"), "3", 'incorrect reponse for 3') self.assertEqual(self.game.play("4"), "Fizz", 'incorrect reponse for 4') self.assertEqual(self.game.play("5"), "Buzz", 'incorrect reponse for 5') self.assertEqual(self.game.play("6"), "Fizz", 'incorrect reponse for 6') self.assertEqual(self.game.play("7"), "7", 'incorrect reponse for 7') self.assertEqual(self.game.play("8"), "Fizz", 'incorrect reponse for 8') self.assertEqual(self.game.play("9"), "9", 'incorrect reponse for 9') self.assertEqual(self.game.play("10"), self.game.name, 'incorrect reponse for 10')
def test_it_says_the_rule_value_if_the_input_applies_to_the_rule(self): rules = [Rule((lambda i: True), 'foo')] self.assertEqual('foo', FizzBuzz(rules).say(0))
# -*- coding: utf-8 -*- import argparse from fizzbuzz.buzz import Buzz from fizzbuzz.fizz import Fizz from fizzbuzz.fizzbuzz import FizzBuzz parser = argparse.ArgumentParser() parser.add_argument("number", help="donnez votre nombre") parser.add_argument("game", help="donnez votre jeu") args = parser.parse_args() availableGames = [Buzz(), Fizz(), FizzBuzz()] for currentGame in availableGames: if currentGame.accept(args.game): print(currentGame.play(args.number))
def setUp(self): self.fizzbuzz = FizzBuzz()
def test_fizz_start_end(self): res = [] expected_list = ['Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz'] for i in FizzBuzz(10, 15): res.append(str(i)) self.assertEqual(res, expected_list)
class TestBuzz(unittest.TestCase): def setUp(self): self.game = FizzBuzz() def testPlayTenFirstNumbers(self): self.assertEqual(self.game.play(1), "1", 'incorrect reponse for 1') self.assertEqual(self.game.play(2), "Fizz", 'incorrect reponse for 2') self.game = FizzBuzz() self.assertEqual(self.game.play(3), "3", 'incorrect reponse for 3') self.assertEqual(self.game.play(4), "Fizz", 'incorrect reponse for 4') self.assertEqual(self.game.play(5), "Buzz", 'incorrect reponse for 5') self.assertEqual(self.game.play(6), "Fizz", 'incorrect reponse for 6') self.assertEqual(self.game.play(7), "7", 'incorrect reponse for 7') self.assertEqual(self.game.play(8), "Fizz", 'incorrect reponse for 8') self.assertEqual(self.game.play(9), "9", 'incorrect reponse for 9') self.assertEqual(self.game.play(10), self.game.name, 'incorrect reponse for 10') def testPlayTenFirstNumbersInString(self): self.assertEqual(self.game.play("1"), "1", 'incorrect reponse for 1') self.assertEqual(self.game.play("2"), "Fizz", 'incorrect reponse for 2') self.game = FizzBuzz() self.assertEqual(self.game.play("3"), "3", 'incorrect reponse for 3') self.assertEqual(self.game.play("4"), "Fizz", 'incorrect reponse for 4') self.assertEqual(self.game.play("5"), "Buzz", 'incorrect reponse for 5') self.assertEqual(self.game.play("6"), "Fizz", 'incorrect reponse for 6') self.assertEqual(self.game.play("7"), "7", 'incorrect reponse for 7') self.assertEqual(self.game.play("8"), "Fizz", 'incorrect reponse for 8') self.assertEqual(self.game.play("9"), "9", 'incorrect reponse for 9') self.assertEqual(self.game.play("10"), self.game.name, 'incorrect reponse for 10') def testPlayMultiplicationsNumber(self): self.assertEqual(self.game.play(15), "Buzz", 'incorrect reponse for 15') self.assertEqual(self.game.play(22), "Fizz", 'incorrect reponse for 22') self.assertEqual(self.game.play(35), "Buzz", 'incorrect reponse for 35') self.assertEqual(self.game.play(42), "Fizz", 'incorrect reponse for 42') self.assertEqual(self.game.play(56), "Fizz", 'incorrect reponse for 56') self.assertEqual(self.game.play(70), self.game.name, 'incorrect reponse for 70') def testPlayNan(self): with self.assertRaises(ArgsException): self.game.play(math.nan) def testPlayLargeNumber(self): self.assertEqual( self.game.play( "133463891334689133463891334689133463891334689133463891334689133463891334689133463891334689133463891" ), "133463891334689133463891334689133463891334689133463891334689133463891334689133463891334689133463891", 'incorrect reponse for 133463891334689133463891334689133463891334689133463891334689133463891334689133463891334689133463891' ) self.assertEqual( self.game.play( "123467891234689123467891234689123467891234689123467891234689123467891234689123467891234689123467895" ), self.game.name, 'incorrect reponse for 123467891234689123467891234689123467891234689123467891234689123467891234689123467891234689123467895' ) self.assertEqual( self.game.play("2000300624103679337202883934330700182830667"), "Fizz", 'incorrect reponse for 2000300624103679337202883934330700182830667' ) self.assertEqual( self.game.play("10002303120328396686014429771633300914233330"), self.game.name, 'incorrect reponse for 10002303120328396686014429771633300914233330' )
def setUp(self): super().setUp() self.fizzbuzz = FizzBuzz()
class FizzBuzzTest(TestCase): def setUp(self): super().setUp() self.fizzbuzz = FizzBuzz() def test_should_return_number_when_not_divisible_by_three_or_five(self): self.assertEqual(1, self.fizzbuzz.execute(1)) self.assertEqual(2, self.fizzbuzz.execute(2)) self.assertEqual(4, self.fizzbuzz.execute(4)) def test_should_return_fizz_when_number_is_divisible_by_three(self): self.assertEqual("fizz", self.fizzbuzz.execute(3)) self.assertEqual("fizz", self.fizzbuzz.execute(9)) def test_should_return_buzz_when_number_is_divisible_by_five(self): self.assertEqual("buzz", self.fizzbuzz.execute(5)) self.assertEqual("buzz", self.fizzbuzz.execute(10)) def test_should_return_fizzbuzz_when_number_is_divisible_by_three_and_five( self): self.assertEqual("fizzbuzz", self.fizzbuzz.execute(15)) self.assertEqual("fizzbuzz", self.fizzbuzz.execute(30)) def test_should_return_pop_when_number_is_divisible_by_seven(self): self.assertEqual("pop", self.fizzbuzz.execute(7)) def test_should_return_fizzpop_when_number_is_divisible_by_three_and_seven( self): self.assertEqual("fizzpop", self.fizzbuzz.execute(21)) def test_should_return_buzz_pop_when_number_is_divisible_by_five_and_seven( self): self.assertEqual("buzzpop", self.fizzbuzz.execute(35)) def test_should_return_fizzbuzzpop_when_number_is_divisible_by_three_and_five_and_seven( self): self.assertEqual("fizzbuzzpop", self.fizzbuzz.execute(105)) self.assertEqual("fizzbuzzpop", self.fizzbuzz.execute(210)) def test_should_return_fuzz_when_number_is_divisible_by_two(self): custom_variation = {"fuzz": 2} self.assertEqual("fuzz", self.fizzbuzz.execute(2, custom_variation)) self.assertEqual("fuzz", self.fizzbuzz.execute(10, custom_variation))
def test_assertions_int_1(self): self.assertRaises(AssertionError, lambda: FizzBuzz(3.5))
def test_fizz_end_equal_start(self): res = [] expected_list = ['FizzBuzz'] for i in FizzBuzz(15, 15): res.append(str(i)) self.assertEqual(res, expected_list)
def test_fizz_end_start(self): res = [] expected_list = ['Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz'] for i in FizzBuzz(15, 10): res.append(str(i)) self.assertEqual(res, expected_list[::-1])
def test_it_applies_multiple_rules(self): rules = [Rule((lambda i: True), 'foo'), Rule((lambda i: True), 'bar')] self.assertEqual('foobar', FizzBuzz(rules).say(0))
def test_it_says_the_input_if_it_does_not_apply_to_any_rules(self): rules = [Rule((lambda i: False), 'foo')] self.assertEqual(0, FizzBuzz(rules).say(0))
class FizzBuzzTest(TestCase): def setUp(self): super().setUp() self.fizzbuzz = FizzBuzz() def test_should_return_number_when_not_divisible_by_three_or_five(self): self.assertEqual(1, self.fizzbuzz.execute(1)) self.assertEqual(2, self.fizzbuzz.execute(2)) self.assertEqual(4, self.fizzbuzz.execute(4)) def test_should_return_fizz_when_number_is_divisible_by_three(self): self.assertEqual("fizz", self.fizzbuzz.execute(3)) self.assertEqual("fizz", self.fizzbuzz.execute(9)) def test_should_return_buzz_when_number_is_divisible_by_five(self): self.assertEqual("buzz", self.fizzbuzz.execute(5)) self.assertEqual("buzz", self.fizzbuzz.execute(10)) def test_should_return_fizzbuzz_when_number_is_divisible_by_three_and_five(self): self.assertEqual("fizzbuzz", self.fizzbuzz.execute(15)) self.assertEqual("fizzbuzz", self.fizzbuzz.execute(30)) def test_should_return_pop_when_number_is_divisible_by_seven(self): self.assertEqual("pop", self.fizzbuzz.execute(7)) def test_should_return_fizzpop_when_number_is_divisible_by_three_and_seven(self): self.assertEqual("fizzpop", self.fizzbuzz.execute(21)) def test_should_return_buzz_pop_when_number_is_divisible_by_five_and_seven(self): self.assertEqual("buzzpop", self.fizzbuzz.execute(35)) def test_should_return_fizzbuzzpop_when_number_is_divisible_by_three_and_five_and_seven(self): self.assertEqual("fizzbuzzpop", self.fizzbuzz.execute(105)) self.assertEqual("fizzbuzzpop", self.fizzbuzz.execute(210)) def test_should_return_fuzz_when_number_is_divisible_by_two(self): custom_variation = {"fuzz": 2} self.assertEqual("fuzz", self.fizzbuzz.execute(2, custom_variation)) self.assertEqual("fuzz", self.fizzbuzz.execute(10, custom_variation))
def setUp(self): self.game = FizzBuzz()
def test_fizz_start(self): res = [] for i in FizzBuzz(3): res.append(str(i)) self.assertEqual(res, ['1', '2', 'Fizz'])