From 73a63f2fe87d72ddfba07a3a165287df6446d49d Mon Sep 17 00:00:00 2001 From: Yu Nan Date: Mon, 13 Jan 2020 23:11:26 +0800 Subject: [PATCH 1/2] Initial commit --- helloworld.py | 2 -- helloworld_test.py | 5 ----- 2 files changed, 7 deletions(-) delete mode 100644 helloworld.py delete mode 100644 helloworld_test.py diff --git a/helloworld.py b/helloworld.py deleted file mode 100644 index 449b948..0000000 --- a/helloworld.py +++ /dev/null @@ -1,2 +0,0 @@ -def get_greetings(): - return 'Hello World!' diff --git a/helloworld_test.py b/helloworld_test.py deleted file mode 100644 index 4c27dfe..0000000 --- a/helloworld_test.py +++ /dev/null @@ -1,5 +0,0 @@ -from helloworld import get_greetings - - -def test_get_helloworld(): - assert get_greetings() == 'Hello World!' From f02ee3f093b8f57c19d488c4a486aa1c140c4a03 Mon Sep 17 00:00:00 2001 From: Yu Nan Date: Tue, 14 Jan 2020 00:06:30 +0800 Subject: [PATCH 2/2] Complete raw code and test case --- FizzBuzz.py | 11 +++++++++++ test_FizzBuzz.py | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 FizzBuzz.py create mode 100644 test_FizzBuzz.py diff --git a/FizzBuzz.py b/FizzBuzz.py new file mode 100644 index 0000000..852c330 --- /dev/null +++ b/FizzBuzz.py @@ -0,0 +1,11 @@ +class Game(object): + def __init__(self, num): + self.raw_num = num + + def number_off(self): + result = "" + if self.raw_num % 3 == 0: + result += 'Fizz' + if self.raw_num % 5 == 0: + result += 'Buzz' + return str(self.raw_num) if result == "" else result diff --git a/test_FizzBuzz.py b/test_FizzBuzz.py new file mode 100644 index 0000000..38f3007 --- /dev/null +++ b/test_FizzBuzz.py @@ -0,0 +1,24 @@ +import unittest +from FizzBuzz import Game + + +class MyTestCase(unittest.TestCase): + def test_get_1_if_pass_1(self): + game = Game(1) + self.assertEqual('1', game.number_off()) + + def test_get_Fizz_if_pass_3(self): + game = Game(3) + self.assertEqual('Fizz', game.number_off()) + + def test_get_Buzz_if_pass_5(self): + game = Game(5) + self.assertEqual('Buzz', game.number_off()) + + def test_get_FizzBuzz_if_pass_15(self): + game = Game(15) + self.assertEqual('FizzBuzz', game.number_off()) + + +if __name__ == '__main__': + unittest.main()