2021-05-06 12:44:29 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
import unittest;
|
|
|
|
from unittest import TestCase;
|
|
|
|
|
2021-05-06 15:29:44 +02:00
|
|
|
from aussagenlogik.schema import stringToSyntaxbaum;
|
2021-05-10 14:32:52 +02:00
|
|
|
from aussagenlogik.rekursion import rekursivEval;
|
|
|
|
from aussagenlogik.rekursion import rekursivAtoms;
|
|
|
|
from aussagenlogik.rekursion import rekursivDepth;
|
|
|
|
from aussagenlogik.rekursion import rekursivLength;
|
|
|
|
from aussagenlogik.rekursion import rekursivParentheses;
|
2021-05-06 12:44:29 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBALE KONSTANTEN
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
#
|
|
|
|
|
2021-05-06 15:29:44 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# TESTFALL eval(·, ·)
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
# @unittest.skip('Methode noch nicht implementiert')
|
|
|
|
class TestRekursivEval(TestCase):
|
|
|
|
def test_literale(self):
|
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, []);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 0;
|
|
|
|
fml = stringToSyntaxbaum('! A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 0;
|
|
|
|
fml = stringToSyntaxbaum('! A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, []);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
|
|
|
|
|
|
|
def test_complex1(self):
|
|
|
|
fml = stringToSyntaxbaum('( ! A0 || (( A0 && A3 ) || A2 ))');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0', 'A2' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0', 'A3' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 0;
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A4', 'A8' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
|
|
|
|
|
|
|
def test_complex2(self):
|
|
|
|
fml = stringToSyntaxbaum('( ! A0 || (( A0 && A3 ) || ! A2 ))');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0', 'A2' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 0;
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivEval(fml, [ 'A0', 'A3' ]);
|
2021-05-06 15:29:44 +02:00
|
|
|
assert val == 1;
|
|
|
|
pass;
|
|
|
|
|
2021-05-06 12:44:29 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# TESTFALL Atome(·)
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 12:55:11 +02:00
|
|
|
@unittest.skip('Methode noch nicht implementiert')
|
2021-05-06 12:44:29 +02:00
|
|
|
class TestRekursivAtoms(TestCase):
|
|
|
|
def test_noduplicates(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('( A4 && ( A4 || A4 ))');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = sorted(rekursivAtoms(fml));
|
2021-05-06 12:44:29 +02:00
|
|
|
assert len([_ for _ in val if _ == 'A4']) == 1, 'Atome dürfen nicht mehrfach vorkommen!';
|
|
|
|
|
|
|
|
def test_nononatoms(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('( {F} || A3 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = sorted(rekursivAtoms(fml));
|
2021-05-06 12:44:29 +02:00
|
|
|
assert 'F' not in val, 'Nichtatomare Formeln dürfen nicht vorkommen!';
|
|
|
|
|
|
|
|
def test_calc1(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = sorted(rekursivAtoms(fml));
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == ['A0'], 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc2(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = sorted(rekursivAtoms(fml));
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == ['A0', 'A3', 'A4', 'A8'], 'computed {}'.format(val);
|
|
|
|
pass;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# TESTFALL Depth(·)
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 12:55:11 +02:00
|
|
|
@unittest.skip('Methode noch nicht implementiert')
|
2021-05-06 12:44:29 +02:00
|
|
|
class TestRekursivDepth(TestCase):
|
|
|
|
def test_calc1(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivDepth(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 0, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc2(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('!! A8');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivDepth(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 2, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc3(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('( ! A0 && A3 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivDepth(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 2, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc4(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivDepth(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 4, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc5(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('! ((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivDepth(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 5, 'computed {}'.format(val);
|
|
|
|
pass;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# TESTFALL Länge(·)
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 12:55:11 +02:00
|
|
|
@unittest.skip('Methode noch nicht implementiert')
|
2021-05-06 12:44:29 +02:00
|
|
|
class TestRekursivLength(TestCase):
|
|
|
|
def test_calc1(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivLength(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 1, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc2(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('!! A8');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivLength(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 3, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc3(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('( ! A0 && A3 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivLength(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 4, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc4(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivLength(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 8, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc5(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('! ((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivLength(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 9, 'computed {}'.format(val);
|
|
|
|
pass;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# TESTFALL Anzahl Klammern(·)
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 12:55:11 +02:00
|
|
|
@unittest.skip('Methode noch nicht implementiert')
|
2021-05-06 12:44:29 +02:00
|
|
|
class TestRekursivParentheses(TestCase):
|
|
|
|
def test_calc1(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('A0');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivParentheses(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 0, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc2(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('!! A8');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivParentheses(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 0, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc3(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('( ! A0 && A3 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivParentheses(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 2, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc4(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivParentheses(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 6, 'computed {}'.format(val);
|
|
|
|
|
|
|
|
def test_calc5(self):
|
2021-05-06 15:29:44 +02:00
|
|
|
fml = stringToSyntaxbaum('! ((( ! A0 && A3 ) || A4 ) && A8 )');
|
2021-05-10 14:32:52 +02:00
|
|
|
val = rekursivParentheses(fml);
|
2021-05-06 12:44:29 +02:00
|
|
|
assert val == 6, 'computed {}'.format(val);
|
|
|
|
pass;
|