# coding: utf-8 import unittest import numbers from fib import fib import logging import pandas as pd 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) def test_excel(self): data = pd.read_excel('./Fib-Testdaten.xlsx') results = data["Ergebnis"] for key, result in data.items(): if isinstance(key, numbers.Number): #Überspringen der Überschriftenzeile self.assertEqual(result, fib(int(key))) print(f'Testdatentyp: ${type(data)}') print(f'Testdaten ${results}') if __name__ == '__main__': unittest.main()