From 7dc3c58da68a0650470387eb188ac93df59ba479 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:19:20 -0400 Subject: [PATCH 01/11] Add .circleci/config.yml --- .circleci/config.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..12a4918 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,21 @@ +version: 2.1 + +orbs: + python: circleci/python@0.2.1 + +jobs: + build-and-test: + executor: python/default + steps: + - checkout + - python/load-cache + - python/install-deps + - python/save-cache + - run: + command: ./manage.py test + name: Test + +workflows: + main: + jobs: + - build-and-test From 25059bcdd1c07f9aee706e023baddc85c70e9512 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:22:53 -0400 Subject: [PATCH 02/11] Add req.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ + From 33438cfd534684b7811842f9de452bb88e93627e Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:26:36 -0400 Subject: [PATCH 03/11] Python test file --- fib.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 fib.py diff --git a/fib.py b/fib.py new file mode 100644 index 0000000..f8c487d --- /dev/null +++ b/fib.py @@ -0,0 +1,48 @@ +""" +Fibonacci numbers function. +""" + +# Copyright 2014 The University of Edinburgh. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. + +import sys + +def fibonacci(n): + """ + Calculate the Fibonacci number of the given integer. + @param n If n <= 0 then 0 is assumed. + @return fibonacci number. + """ + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +def print_usage(): + """ Print usage information. """ + print("Usage: python fibonacci.py N") + print(" where N >= 0") + +if __name__ == '__main__': + if (len(sys.argv) < 2): + print_usage() + exit(1) + n = int(sys.argv[1]) + if (n < 0): + print_usage() + exit(2) + fib = fibonacci(n) + print("fibonacci(%d) = %d" % (n, fib)) From 96146a5d2e4326996def2f550aba22fe6b9b5b6a Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:27:17 -0400 Subject: [PATCH 04/11] unit test --- fib_test.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 fib_test.py diff --git a/fib_test.py b/fib_test.py new file mode 100644 index 0000000..f957c7e --- /dev/null +++ b/fib_test.py @@ -0,0 +1,57 @@ +""" +Fibonacci numbers test class. +""" + +# Copyright 2014 The University of Edinburgh. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. + +import unittest + +from maths.fibonacci import fibonacci + +class TestFibonacci(unittest.TestCase): + """ + Fibonacci numbers test class. + """ + + def setUp(self): + """ Initialise test suite - no-op. """ + pass + + def tearDown(self): + """ Clean up test suite - no-op. """ + pass + + def test_fibonacci0(self): + """ Test fibonacci(0). """ + self.assertEqual(0, fibonacci(0)) + + def test_fibonacci1(self): + """ Test fibonacci(1). """ + self.assertEqual(1, fibonacci(1)) + + def test_fibonacci2(self): + """ Test fibonacci(2). """ + self.assertEqual(1, fibonacci(2)) + + def test_fibonacci3(self): + """ Test fibonacci(3). """ + self.assertEqual(2, fibonacci(3)) + + def test_fibonacci30(self): + """ Test fibonacci(30). """ + self.assertEqual(832040, fibonacci(30)) + +if __name__ == '__main__': + unittest.main() From faef892ad30991a144f86948aedce7338895bbc8 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:29:37 -0400 Subject: [PATCH 05/11] test --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12a4918..54e3c7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: - python/install-deps - python/save-cache - run: - command: ./manage.py test + command: ./fib_test.py test name: Test workflows: From b5d1a95cc2cd5304b88aa4ae2c95341a72b8e06d Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:33:50 -0400 Subject: [PATCH 06/11] test --- .circleci/config.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 54e3c7b..d709899 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - python: circleci/python@0.2.1 + python: circleci/python@1.2.0 jobs: build-and-test: @@ -11,11 +11,10 @@ jobs: - python/load-cache - python/install-deps - python/save-cache - - run: - command: ./fib_test.py test - name: Test - workflows: main: jobs: - - build-and-test + - python/test: + args: '--dev' + pkg-manager: pipenv + test-tool: pytest From 5bfb24ce9b7338d4d6391863b357d85c20daf0a3 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:35:39 -0400 Subject: [PATCH 07/11] update --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 8b13789..490d735 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +pytest From a9b21b5fbc9ffc099a714dec074be46094e0ab03 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:37:33 -0400 Subject: [PATCH 08/11] test --- fib_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fib_test.py b/fib_test.py index f957c7e..76bbf2c 100644 --- a/fib_test.py +++ b/fib_test.py @@ -18,7 +18,7 @@ import unittest -from maths.fibonacci import fibonacci +from testing import fibonacci class TestFibonacci(unittest.TestCase): """ From 748e28f2ac7d363f99e4de4390bb11db793bebe0 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:37:54 -0400 Subject: [PATCH 09/11] test --- fib.py => fibonacci.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fib.py => fibonacci.py (100%) diff --git a/fib.py b/fibonacci.py similarity index 100% rename from fib.py rename to fibonacci.py From 9b844232bcbdd50c7af144fb24671e1498468a17 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:38:25 -0400 Subject: [PATCH 10/11] update --- __init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ + From 7c1af1e388157ee7f3f54b8fc0a9989895dcea10 Mon Sep 17 00:00:00 2001 From: Jason McFall Date: Tue, 13 Oct 2020 16:40:20 -0400 Subject: [PATCH 11/11] test --- fib_test.py | 57 +++-------------------------------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/fib_test.py b/fib_test.py index 76bbf2c..93e783f 100644 --- a/fib_test.py +++ b/fib_test.py @@ -1,57 +1,6 @@ -""" -Fibonacci numbers test class. -""" - -# Copyright 2014 The University of Edinburgh. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing -# permissions and limitations under the License. - import unittest -from testing import fibonacci - -class TestFibonacci(unittest.TestCase): - """ - Fibonacci numbers test class. - """ - - def setUp(self): - """ Initialise test suite - no-op. """ - pass - - def tearDown(self): - """ Clean up test suite - no-op. """ - pass - - def test_fibonacci0(self): - """ Test fibonacci(0). """ - self.assertEqual(0, fibonacci(0)) - - def test_fibonacci1(self): - """ Test fibonacci(1). """ - self.assertEqual(1, fibonacci(1)) - - def test_fibonacci2(self): - """ Test fibonacci(2). """ - self.assertEqual(1, fibonacci(2)) - - def test_fibonacci3(self): - """ Test fibonacci(3). """ - self.assertEqual(2, fibonacci(3)) - - def test_fibonacci30(self): - """ Test fibonacci(30). """ - self.assertEqual(832040, fibonacci(30)) +class TestCase(unittest.TestCase): -if __name__ == '__main__': - unittest.main() + def test_true(self): + assert True