You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
import unittest
|
|
from fib import fib
|
|
import logging
|
|
|
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG)
|
|
|
|
class TestFib(unittest.TestCase):
|
|
|
|
# Methode zur Division a/b.
|
|
def divide(self, a,b):
|
|
if b == 0:
|
|
raise ValueError('Dividend darf nicht 0 sein.')
|
|
|
|
return int(a/b)
|
|
|
|
|
|
# Die setUp() Methode wird zu Beginn jedes Testcases aufgrufen
|
|
def setUp(self):
|
|
logging.debug('setting up test')
|
|
self.results = [1,1,2,3,5,8,13,21,34,55]
|
|
|
|
#die beiden Tests aus ./testfib.py mit unittest
|
|
def test_fib(self):
|
|
|
|
# assertEqual(n,r) testet, ob das Resultat r der Vorgabe n entspricht.
|
|
self.assertEqual(8,fib(5))
|
|
self.assertEqual(34,fib(8))
|
|
|
|
def test_mult_fib(self):
|
|
results =[1,1,2,3,5,8,13,21,34,55]
|
|
|
|
for n in range(0,9):
|
|
self.assertEqual(results[n],fib(n))
|
|
|
|
def test_divide(self):
|
|
|
|
self.assertEqual(2, self.divide(2,1))
|
|
self.assertEqual(2, self.divide(4,2))
|
|
self.assertEqual(3, self.divide(6,2))
|
|
|
|
with self.assertRaises(ValueError):
|
|
self.divide(1,0)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
|