From 97d1d645ac445c4d5f0b4d1f736e24dfb65c9610 Mon Sep 17 00:00:00 2001 From: guwenyuan Date: Tue, 14 Jan 2020 11:34:06 +0800 Subject: [PATCH 1/2] fizzbuzz fizzbuzz --- fizzbuzz.py | 3 +++ fizzbuzz_test.py | 8 ++++++++ helloworld.py | 2 -- helloworld_test.py | 5 ----- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 fizzbuzz.py create mode 100644 fizzbuzz_test.py delete mode 100644 helloworld.py delete mode 100644 helloworld_test.py diff --git a/fizzbuzz.py b/fizzbuzz.py new file mode 100644 index 0000000..f398dfb --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,3 @@ +def fizzbuzz(n): + for i in range(1,n + 1): + print('fizz'[i % 3 * 4:] + 'buzz'[i % 5 * 4:] or i) diff --git a/fizzbuzz_test.py b/fizzbuzz_test.py new file mode 100644 index 0000000..d9310d3 --- /dev/null +++ b/fizzbuzz_test.py @@ -0,0 +1,8 @@ +from fizzbuzz import fizzbuzz + + +def test_fizzbuzz(): + fizzbuzz(100) + +if __name__ == '__main__': + test_fizzbuzz() 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 dcd5613426d887cdb34775ce2ea2ee77f6d14049 Mon Sep 17 00:00:00 2001 From: guwenyuan Date: Wed, 15 Jan 2020 14:46:06 +0800 Subject: [PATCH 2/2] fizzbuzz v2 --- fizzbuzz.py | 16 ++++++++++++++-- fizzbuzz_test.py | 22 +++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/fizzbuzz.py b/fizzbuzz.py index f398dfb..2e380f9 100644 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,3 +1,15 @@ +# @File : fizzbuzz.py +# @Author: Wenyuan Gu +# @Date : 2020/1/15 + + def fizzbuzz(n): - for i in range(1,n + 1): - print('fizz'[i % 3 * 4:] + 'buzz'[i % 5 * 4:] or i) + return 'Fizz'[n % 3 * 4:] + 'Buzz'[n % 5 * 4:] or n + + +def main(): + for i in range(1, 101): + print(fizzbuzz(i)) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/fizzbuzz_test.py b/fizzbuzz_test.py index d9310d3..132e38b 100644 --- a/fizzbuzz_test.py +++ b/fizzbuzz_test.py @@ -1,8 +1,20 @@ -from fizzbuzz import fizzbuzz +# @File : fizzbuzz_test.py +# @Author: Wenyuan Gu +# @Date : 2020/1/15 + +import pytest +from fizzbuzz import fizzbuzz -def test_fizzbuzz(): - fizzbuzz(100) +class Test_fizzbuzz(): + def test2(self): + assert fizzbuzz(2) == 2 + def test3(self): + assert fizzbuzz(3) == 'Fizz' + def test5(self): + assert fizzbuzz(5) == 'Buzz' + def test15(self): + assert fizzbuzz(15) == 'FizzBuzz' -if __name__ == '__main__': - test_fizzbuzz() +if __name__ == "__main__": + pytest.main()