From 888f244311b137b17efbbccdb3f9fd315aaf3af0 Mon Sep 17 00:00:00 2001 From: fuzhao <1451853111@qq.com> Date: Tue, 14 Jan 2020 18:35:22 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fizzbuzz.py | 9 +++++++++ test_FizzBuzz.py | 9 +++++++++ 2 files changed, 18 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..da6a9bd --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,9 @@ +def fb(N): + res = "" + if N % 3 == 0: + res += "Fizz" + if N % 5 == 0: + res += "Buzz" + if len(res) == 0: + res = str(N) + return res diff --git a/test_FizzBuzz.py b/test_FizzBuzz.py new file mode 100644 index 0000000..814cea2 --- /dev/null +++ b/test_FizzBuzz.py @@ -0,0 +1,9 @@ +from fizzbuzz import fb + +inputs = [1, 3, 5, 15] +results = ["1", "Fizz", "Buzz", "FizzBuzz"] + + +def test_fb(): + for i in range(len(inputs)): + assert fb(inputs[i]) == results[i]