[LABI] tema02: added fibonacci.py

This commit is contained in:
brunombpereira 2023-05-16 18:40:03 +01:00
parent d2e535ef37
commit 306eb84df7
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
2 changed files with 45 additions and 0 deletions

15
.idea/git_toolbox_prj.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>

View File

@ -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]