From 01a4d71e262ef87489136abb281f87bb867bacf4 Mon Sep 17 00:00:00 2001 From: lvcheng93 Date: Wed, 15 Jan 2020 14:38:04 +0800 Subject: [PATCH 1/2] fix fizzbuzz: add fizzbuzz function and unit test --- helloworld.py | 11 +++++++++++ helloworld_test.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/helloworld.py b/helloworld.py index 449b948..aa63b7e 100644 --- a/helloworld.py +++ b/helloworld.py @@ -1,2 +1,13 @@ def get_greetings(): return 'Hello World!' + + +def fizzbuzz(i): + if i%3==0 and i%5==0: + return 'fizzbuzz' + elif i%3==0: + return 'fizz' + elif i%5==0: + return 'buzz' + else: + return str(i) diff --git a/helloworld_test.py b/helloworld_test.py index 4c27dfe..881cae3 100644 --- a/helloworld_test.py +++ b/helloworld_test.py @@ -1,5 +1,10 @@ from helloworld import get_greetings +from helloworld import fizzbuzz def test_get_helloworld(): assert get_greetings() == 'Hello World!' + assert fizzbuzz(1) == '1' + assert fizzbuzz(3) == 'fizz' + assert fizzbuzz(5) == 'buzz' + assert fizzbuzz(15) == 'fizzbuzz' From 6ff3e092b81217245a6dd88ee2f810872247c3a7 Mon Sep 17 00:00:00 2001 From: lvcheng93 Date: Wed, 15 Jan 2020 14:53:34 +0800 Subject: [PATCH 2/2] modify fizzbuzz: add fizzbuzz function and unit test --- helloworld.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helloworld.py b/helloworld.py index aa63b7e..1d43bc3 100644 --- a/helloworld.py +++ b/helloworld.py @@ -3,11 +3,11 @@ def get_greetings(): def fizzbuzz(i): - if i%3==0 and i%5==0: + if i % 3 == 0 and i % 5 == 0: return 'fizzbuzz' - elif i%3==0: + elif i % 3 == 0: return 'fizz' - elif i%5==0: + elif i % 5 == 0: return 'buzz' else: return str(i)