I am creating unit tests by using the unittest module, and simply asserting Equal a result that is correct when calculating the Fibonacci sequence. Below is the working code- the 5th number is 2+3 = 5.
num1 = 0
num2 = 1
find = 2
fib_num = 0
while find <= N:
fib_num = num1 + num2
num1 = num2
num2 = fib_num
find = find + 1
return(fib_num)
print(fibFind(5))
This is mu Unittest
from fibfind import fibFind
class TestFibonnaciResult(unittest.TestCase):
def test_number(self):
self.assertEqual(fibFind(5)== 5),
self.assertEqual(fibFind(6)==8),
self.assertEqual(fibFind(7)== 13)
5, 8, 13
def test_input_type(self):
self.assertTrue(fibFind("some-string") == error)
if __name__ == "__main__":
unittest.main()
In the terminal however, I get this?
$ python -m unittest test_fibFind.py
EE
======================================================================
ERROR: test_input_type (test_fibFind.TestFibonnaciResult)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\XYZ\dev\repos\testing_python\test_fibFind.py", line 14, in test_input_type
self.assertTrue(fibFind("some-string") == error)
File "C:\Users\XYZ\dev\repos\testing_python\fibfind.py", line 7, in fibFind
while find <= N:
TypeError: '<=' not supported between instances of 'int' and 'str'
======================================================================
ERROR: test_number (test_fibFind.TestFibonnaciResult)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\XYZ\dev\repos\testing_python\test_fibFind.py", line 8, in test_number
self.assertEqual(fibFind(5)== 5),
TypeError: assertEqual() missing 1 required positional argument: 'second'
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (errors=2)
5
The second test is wanting to make sure only an integer is parsed through but clearly is having issues with the comparator <=
Any help here before I move onto pytest would be great.