From 188b11506582db6f5f88f5421897e0c73c51a262 Mon Sep 17 00:00:00 2001 From: DavidZang Date: Tue, 14 Jan 2020 23:27:00 +0800 Subject: [PATCH] update --- helloworld.py | 15 +++++++++++++++ helloworld_test.py | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/helloworld.py b/helloworld.py index 449b948..0705b2d 100644 --- a/helloworld.py +++ b/helloworld.py @@ -1,2 +1,17 @@ def get_greetings(): return 'Hello World!' + + +def divided(n, i): + return n % i == 0 + + +def get_fizzbuzz(n): + out_str = '' + if divided(n, 3): + out_str += 'Fizz' + if divided(n, 5): + out_str += 'Buzz' + if len(out_str) == 0: + out_str += str(n) + return out_str diff --git a/helloworld_test.py b/helloworld_test.py index 4c27dfe..b03cf9d 100644 --- a/helloworld_test.py +++ b/helloworld_test.py @@ -1,5 +1,17 @@ from helloworld import get_greetings +from helloworld import get_fizzbuzz def test_get_helloworld(): assert get_greetings() == 'Hello World!' + + +def test_get_fizzbuzz(): + test_simple = [ + [1, '1'], + [3, 'Fizz'], + [5, 'Buzz'], + [15, 'FizzBuzz'], + ] + for i in range(len(test_simple)): + assert get_fizzbuzz(test_simple[i][0]) == test_simple[i][1]