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.
58 lines
1.4 KiB
58 lines
1.4 KiB
2 years ago
|
# coding: utf-8
|
||
2 years ago
|
import unittest
|
||
2 years ago
|
import numbers
|
||
2 years ago
|
from fib import fib
|
||
|
import logging
|
||
2 years ago
|
import pandas as pd
|
||
2 years ago
|
|
||
|
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)
|
||
|
|
||
2 years ago
|
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)))
|
||
|
|
||
|
|
||
2 years ago
|
if __name__ == '__main__':
|
||
|
unittest.main()
|