added
This commit is contained in:
BIN
Freitag/__pycache__/mathematik.cpython-39.pyc
Normal file
BIN
Freitag/__pycache__/mathematik.cpython-39.pyc
Normal file
Binary file not shown.
6
Freitag/check_env.py
Normal file
6
Freitag/check_env.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#start python umgebung
|
||||||
|
# python3 -m venv ~/pyenv
|
||||||
|
# virtualenv ~/pyenv
|
||||||
|
# virtualenv
|
||||||
|
#source ~/pyenv/activate
|
||||||
|
#
|
||||||
0
Freitag/db_insert.py
Normal file → Executable file
0
Freitag/db_insert.py
Normal file → Executable file
14
Freitag/mathematik.py
Normal file
14
Freitag/mathematik.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
def fak(n):
|
||||||
|
if n == 0:
|
||||||
|
return 1
|
||||||
|
if n < 0:
|
||||||
|
raise ValueError("Fak ist eine negative Zahl")
|
||||||
|
if type(n) is not int:
|
||||||
|
raise TypeError("Fak ist keine ganze Zahl")
|
||||||
|
return n * fak(n-1)
|
||||||
|
|
||||||
|
|
||||||
|
print(fak(4))
|
||||||
31
Freitag/test_fak.py
Normal file
31
Freitag/test_fak.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from unittest import TestCase, main
|
||||||
|
|
||||||
|
from mathematik import fak
|
||||||
|
|
||||||
|
class FacultyTester(TestCase):
|
||||||
|
def test_basic(self):
|
||||||
|
self.assertEqual(fak(0), 1)
|
||||||
|
self.assertEqual(fak(1), 1)
|
||||||
|
|
||||||
|
def test_basic2(self):
|
||||||
|
self.assertTrue(fak(0) == 1)
|
||||||
|
self.assertTrue(fak(1) == 1)
|
||||||
|
|
||||||
|
def test_basic3(self):
|
||||||
|
self.assertFalse(fak(0) == 0)
|
||||||
|
|
||||||
|
def test_greater(self):
|
||||||
|
for n in range(2,10):
|
||||||
|
self.assertGreater(fak(n), fak(n-1))
|
||||||
|
def test_invalid(self):
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
fak(-1)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
fak(-1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user