From c49a773e0e25cd96891408bd34889e57d5efdfbc Mon Sep 17 00:00:00 2001 From: brunombpereira Date: Tue, 16 May 2023 18:40:03 +0100 Subject: [PATCH] [LABI] tema02: added fibonacci.py --- .idea/git_toolbox_prj.xml | 15 +++++++++++++ 1ano/2semestre/labi/tema02/fibonacci.py | 30 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .idea/git_toolbox_prj.xml create mode 100644 1ano/2semestre/labi/tema02/fibonacci.py diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/1ano/2semestre/labi/tema02/fibonacci.py b/1ano/2semestre/labi/tema02/fibonacci.py new file mode 100644 index 0000000..e48db47 --- /dev/null +++ b/1ano/2semestre/labi/tema02/fibonacci.py @@ -0,0 +1,30 @@ +import pytest + + +def fibonacci(n): + res = [] + + if n < 0: + return res + elif n == 0: + res.append(n) + return res + elif n == 1: + res = [0, 1] + return res + else: + res = [0, 1] + for i in range(2, n + 1): + x = res[i - 1] + res[i - 2] + res.append(x) + return res + + +def test_inferior_1(): + print("Testa comportamento com n < 1") + + assert fibonacci(-1) == [] + assert fibonacci(0) == [0] + assert fibonacci(1) == [0, 1] + assert fibonacci(2) == [0, 1, 1] + assert fibonacci(5) == [0, 1, 1, 2, 3, 5]