From 27984cf51a59839a8014646f23027a428f7c28be Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2020 20:29:00 +0800 Subject: [PATCH 1/8] Frist --- FizzBuzz.py | 10 ++++++++++ helloworld.py | 2 -- helloworld_test.py | 5 ----- testFizzBuzz.py | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 FizzBuzz.py delete mode 100644 helloworld.py delete mode 100644 helloworld_test.py create mode 100644 testFizzBuzz.py diff --git a/FizzBuzz.py b/FizzBuzz.py new file mode 100644 index 0000000..1718a46 --- /dev/null +++ b/FizzBuzz.py @@ -0,0 +1,10 @@ +def FB(n): + if n%3 == 0: + if n%5 == 0: + return "FizzBuzz" + else: + return "Fizz" + elif n%5 == 0: + return "Buzz" + else: + return n \ No newline at end of file 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!' diff --git a/testFizzBuzz.py b/testFizzBuzz.py new file mode 100644 index 0000000..b9f25fc --- /dev/null +++ b/testFizzBuzz.py @@ -0,0 +1,17 @@ +import unittest +from FizzBuzz import FB + +class testFB(unittest.TestCase): + def test_1(self): + self.assertEqual(1,FB(1)) + def test_3(self): + self.assertEqual("Fizz",FB(3)) + def test_5(self): + self.assertEqual("Buzz",FB(5)) + def test_15(self): + self.assertEqual("FizzBuzz",FB(15)) + + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 322a514397768b4b83d1d6558a09aed1a799eabc Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2020 20:53:04 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FizzBuzz.py | 8 ++++---- testFizzBuzz.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 1718a46..46b101b 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,10 +1,10 @@ def FB(n): - if n%3 == 0: - if n%5 == 0: + if n % 3 == 0: + if n % 5 == 0: return "FizzBuzz" else: return "Fizz" - elif n%5 == 0: + elif n % 5 == 0: return "Buzz" else: - return n \ No newline at end of file + return n diff --git a/testFizzBuzz.py b/testFizzBuzz.py index b9f25fc..2232acd 100644 --- a/testFizzBuzz.py +++ b/testFizzBuzz.py @@ -1,17 +1,20 @@ import unittest from FizzBuzz import FB + class testFB(unittest.TestCase): def test_1(self): - self.assertEqual(1,FB(1)) + self.assertEqual(1, FB(1)) + def test_3(self): - self.assertEqual("Fizz",FB(3)) + self.assertEqual("Fizz", FB(3)) + def test_5(self): - self.assertEqual("Buzz",FB(5)) - def test_15(self): - self.assertEqual("FizzBuzz",FB(15)) + self.assertEqual("Buzz", FB(5)) + def test_15(self): + self.assertEqual("FizzBuzz", FB(15)) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From ef04d424cda873df1f3b13f15bd35a3090b492d2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2020 21:03:17 +0800 Subject: [PATCH 3/8] test check --- helloworld.py | 2 ++ helloworld_test.py | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 helloworld.py create mode 100644 helloworld_test.py diff --git a/helloworld.py b/helloworld.py new file mode 100644 index 0000000..449b948 --- /dev/null +++ b/helloworld.py @@ -0,0 +1,2 @@ +def get_greetings(): + return 'Hello World!' diff --git a/helloworld_test.py b/helloworld_test.py new file mode 100644 index 0000000..4c27dfe --- /dev/null +++ b/helloworld_test.py @@ -0,0 +1,5 @@ +from helloworld import get_greetings + + +def test_get_helloworld(): + assert get_greetings() == 'Hello World!' From 412aa8d13b1239e57aaced6746d8a93d815de521 Mon Sep 17 00:00:00 2001 From: joke2233 Date: Tue, 14 Jan 2020 15:56:44 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=B8=89=E7=9B=AE=E8=BF=90=E7=AE=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FizzBuzz.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 46b101b..da25c82 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,10 +1,3 @@ def FB(n): - if n % 3 == 0: - if n % 5 == 0: - return "FizzBuzz" - else: - return "Fizz" - elif n % 5 == 0: - return "Buzz" - else: - return n + r = "Fizz" if n % 3 == 0 else '' + return r + "Buzz" if n % 5 == 0 else n if r == '' else r From 4362fcf2899e387f1749f125b571921e71080371 Mon Sep 17 00:00:00 2001 From: joke2233 Date: Tue, 14 Jan 2020 19:13:11 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testFizzBuzz.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/testFizzBuzz.py b/testFizzBuzz.py index 2232acd..bc97c18 100644 --- a/testFizzBuzz.py +++ b/testFizzBuzz.py @@ -1,19 +1,14 @@ import unittest from FizzBuzz import FB +x = [1, 3, 5, 15] +y = [1, "Fizz", "Buzz", "FizzBuzz"] -class testFB(unittest.TestCase): - def test_1(self): - self.assertEqual(1, FB(1)) - - def test_3(self): - self.assertEqual("Fizz", FB(3)) - def test_5(self): - self.assertEqual("Buzz", FB(5)) - - def test_15(self): - self.assertEqual("FizzBuzz", FB(15)) +class testFB(unittest.TestCase): + def test_case(self): + for i in zip(x, y): + self.assertEqual(i[1], FB(i[0])) if __name__ == "__main__": From b3745c191da39002947e18d1ac128996ac1801c4 Mon Sep 17 00:00:00 2001 From: joke2233 Date: Thu, 23 Jan 2020 12:51:55 +0800 Subject: [PATCH 6/8] faster --- .vscode/settings.json | 12 ++++++++++++ .vscode/tasks.json | 19 +++++++++++++++++++ FizzBuzz.py | 3 --- testFizzBuzz.py | 19 ++++++------------- 4 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json delete mode 100644 FizzBuzz.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..77382ee --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..204d632 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "TDD", + "type": "shell", + "command": "python", + "args": [ + "c:/Users/Michael/Documents/Python Scripts/2/testFizzBuzz.py" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/FizzBuzz.py b/FizzBuzz.py deleted file mode 100644 index da25c82..0000000 --- a/FizzBuzz.py +++ /dev/null @@ -1,3 +0,0 @@ -def FB(n): - r = "Fizz" if n % 3 == 0 else '' - return r + "Buzz" if n % 5 == 0 else n if r == '' else r diff --git a/testFizzBuzz.py b/testFizzBuzz.py index bc97c18..7e42540 100644 --- a/testFizzBuzz.py +++ b/testFizzBuzz.py @@ -1,15 +1,8 @@ -import unittest -from FizzBuzz import FB +def bf(n): + return 'fizzbuzz' if n % 15 == 0 else 'fizz' if n % 3 == 0 else 'buzz' if n % 5 == 0 else n -x = [1, 3, 5, 15] -y = [1, "Fizz", "Buzz", "FizzBuzz"] - -class testFB(unittest.TestCase): - def test_case(self): - for i in zip(x, y): - self.assertEqual(i[1], FB(i[0])) - - -if __name__ == "__main__": - unittest.main() +assert bf(1) == 1 +assert bf(3) == 'fizz' +assert bf(5) == 'buzz' +assert bf(15) == 'fizzbuzz' From cce16dc0b5c23fd1104d47c8e17027eee903f1a7 Mon Sep 17 00:00:00 2001 From: joke2233 Date: Thu, 23 Jan 2020 13:06:10 +0800 Subject: [PATCH 7/8] more faster --- testFizzBuzz.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/testFizzBuzz.py b/testFizzBuzz.py index 7e42540..75000f6 100644 --- a/testFizzBuzz.py +++ b/testFizzBuzz.py @@ -1,5 +1,11 @@ def bf(n): - return 'fizzbuzz' if n % 15 == 0 else 'fizz' if n % 3 == 0 else 'buzz' if n % 5 == 0 else n + if n % 15 == 0: + return 'fizzbuzz' + if n % 3 == 0: + return 'fizz' + if n % 5 == 0: + return 'buzz' + return n assert bf(1) == 1 From 9607d81c0adf2683c94585a40021cedc1d46f1b7 Mon Sep 17 00:00:00 2001 From: joke2233 Date: Thu, 13 Feb 2020 20:01:39 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=88=86=E5=BC=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 ++-- f.py | 3 +++ testFizzBuzz.py | 19 +++++-------------- 3 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 f.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 77382ee..757f3cf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,9 +2,9 @@ "python.testing.unittestArgs": [ "-v", "-s", - ".", + "./__pycache__", "-p", - "test_*.py" + "*test.py" ], "python.testing.pytestEnabled": false, "python.testing.nosetestsEnabled": false, diff --git a/f.py b/f.py new file mode 100644 index 0000000..e8e25b2 --- /dev/null +++ b/f.py @@ -0,0 +1,3 @@ +def f(n): + return 'fizzbuzz' if n % 15 == 0 else 'fizz' \ + if n % 3 == 0 else 'buzz' if n % 5 == 0 else n diff --git a/testFizzBuzz.py b/testFizzBuzz.py index 75000f6..94eefd2 100644 --- a/testFizzBuzz.py +++ b/testFizzBuzz.py @@ -1,14 +1,5 @@ -def bf(n): - if n % 15 == 0: - return 'fizzbuzz' - if n % 3 == 0: - return 'fizz' - if n % 5 == 0: - return 'buzz' - return n - - -assert bf(1) == 1 -assert bf(3) == 'fizz' -assert bf(5) == 'buzz' -assert bf(15) == 'fizzbuzz' +from f import * +assert f(1) == 1 +assert f(3) == 'fizz' +assert f(5) == 'buzz' +assert f(15) == 'fizzbuzz'