Created
January 2, 2018 21:26
-
-
Save ramsesoriginal/5e9691f290c76495168ff39612fd266b to your computer and use it in GitHub Desktop.
PA08 Testfunktion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test(title="Test", expression="x0", expectedResult=(True, 0), expectedException = False, arguments=[True], hideOK = False): | |
| out = "\n" + title + "\n" | |
| out = out + '\tauswertung ("' + expression + '", ' + str(arguments) + ')' | |
| reraise = False | |
| if expectedException: | |
| out = out + "\n" + "\tResult should be an exception" | |
| else: | |
| out = out + "\n" + "\tResult should be: " + str(expectedResult) | |
| try: | |
| result = auswertung(expression, arguments) | |
| out = out + "\n" + "\tResult is: " + str(result) | |
| resultOK = (expectedResult == result) and not expectedException | |
| except Exception as ex: | |
| out = out + "\n" + "\tResult is Exception with message: " + str(ex) | |
| resultOK = expectedException | |
| if type(ex) != type(Exception("test")): | |
| resultOK = False | |
| reraise = ex | |
| if resultOK: | |
| out = "\n" + title + "\n [OK]" | |
| else: | |
| out = out + "\n" + " [ERROR]" | |
| if not (hideOK and resultOK): | |
| print(out) | |
| if reraise: | |
| raise reraise | |
| def debug(hidePassedTests = False): | |
| print("\n~~ Tests aus der Angabe - mit ergebnis ~~") | |
| test( | |
| title = "return erstes - ignoriere 2 und 3", | |
| expression = "!!x0|x1&x2", | |
| arguments = [True , True , False ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Tiefe 1", | |
| expression = "(!!x0|x1)&x2", | |
| arguments = [True , True , False ], | |
| expectedResult = (False , 1), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Going in deep!", | |
| expression = "!([!x0]|[[x1]&x2])", | |
| arguments = [True , True , False ], | |
| expectedResult = (True , 3), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Teutologie", | |
| expression = "x0|!x0", | |
| arguments = [ True ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| print("\n~~ Tests aus der Angabe - mit Exception ~~") | |
| test( | |
| title = "Falsche syntax in Ausdruck", | |
| expression = "x0x1", | |
| arguments = [True , True ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Klammern inkonsistent", | |
| expression = "(x0|x1]", | |
| arguments = [False , False ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Klammern offen gelassen", | |
| expression = "(x0|x1", | |
| arguments = [True , False ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Not Falsch verwendet", | |
| expression = "x0!|x1", | |
| arguments = [True , False ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| print("\n~~ Sonderfaelle mit ergebnis ~~") | |
| test( | |
| title = "Lange verkettung an not, gerade", | |
| expression = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x0", | |
| arguments = [True ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Lange verkettung an not, ungerade", | |
| expression = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x0", | |
| arguments = [True ], | |
| expectedResult = (False , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Geklammerte nots", | |
| expression = "!(!(!(![!(!(![![![![!(!x0)]]]]))])))", | |
| arguments = [True ], | |
| expectedResult = (True , 11), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Einfach True", | |
| expression = "x0", | |
| arguments = [True ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Lange kette an True/False Or", | |
| expression = "x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1|x0|x1", | |
| arguments = [True, False ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Lange kette an True/False And", | |
| expression = "x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1&x0&x1", | |
| arguments = [True, False ], | |
| expectedResult = (False , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "verkettete Verklammerte Statements", | |
| expression = "!x1|(x0&x1)|(!x0&!x1)|(!x0&x1)|(x0&!x1)|(x0&(x1|!x1))", | |
| arguments = [True, False ], | |
| expectedResult = (True , 2), | |
| hideOK = hidePassedTests | |
| ) | |
| ''' | |
| x0 & x1 | x1 & !x0 | x2 & !x1 | |
| (F & T) | (T & T) | (T & F) = T | |
| (x0 & x1) | (x1 & !x0) | (x2 & !x1) = T <- Falls & vor | | |
| x0 & (x1 | x1) & (!x0 | x2) & !x1 = F <- Falls | vor & | |
| F & (T | T) & (T | T) & F = F | |
| ''' | |
| test( | |
| title = "Und-Vor-Oder", | |
| expression = "x0&x1|x1&!x0|x2&!x1", | |
| arguments = [False, True, True], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| ''' | |
| !F | !F | |
| !(F | (!F) = !(F | T) = !T = F <- Falls ! vor | | |
| (!F) | (!F) = T | T = T <- Falls | vor ! | |
| ''' | |
| test( | |
| title = "Nicht-Vor-Oder", | |
| expression = "!x0|!x1", | |
| arguments = [False, False ], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Negiertes verschateltes oder", | |
| expression = "!!!(!!!(x0|x1))", | |
| arguments = [True, True ], | |
| expectedResult = (True , 2), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Doppeltes Oder", | |
| expression = "!!!(!!!(x0||x1))", | |
| arguments = [True, True ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Doppeltes Und", | |
| expression = "!!!(!!!(x0&&x1))", | |
| arguments = [True, True ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Emoticon", | |
| expression = "x0d|^.^|bx1", | |
| arguments = [True, True ], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Nein", | |
| expression = "!", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "(Nein)", | |
| expression = "(!)", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Nichts", | |
| expression = "", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "(Nichts)", | |
| expression = "()", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "nicht(Nichts)", | |
| expression = "!()", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "nicht(Nein)", | |
| expression = "!(!)", | |
| arguments = [], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Falsche Klammern", | |
| expression = "{x0}", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Klammern Falsch", | |
| expression = "]x0[", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Klammern Falsch2", | |
| expression = ")x0(", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "AufZuZu", | |
| expression = "(x0))", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "AufZuZuAufAufZu", | |
| expression = "(x0))|((!x0)", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "1", | |
| expression = "1", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "nicht 1", | |
| expression = "!1", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "statement mit 1", | |
| expression = "x0&!1|!x0", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Leerzeichen um true", | |
| expression = " x0 ", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Leerzeichen im statement", | |
| expression = "x0 & x0", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Multitrue to single x", | |
| expression = "x0&x0|x0&x0", | |
| arguments = [True, True, True, True], | |
| expectedResult = (True , 0), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Multitrue to multi but smaller x", | |
| expression = "x0&(x1|x0)&x2", | |
| arguments = [True, True, True, True, True, True, True], | |
| expectedResult = (True , 1), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "x > 10, nicht genug argumente", | |
| expression = "(x0|x1|x2|x3|x4|x5|x6)&(x7&![x8|(x9&x10)|x11]&x12)|!x13", | |
| arguments = [True, True, True, True, True, True, True, True, True, True, True, True, True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "x > 10", | |
| expression = "(x0|x1|x2|x3|x4|x5|x6)&(x7&![x8|(x9&x10)|x11]&x12)|!x13", | |
| arguments = [True, True, True, True, True, True, True, True, True, True, True, True, True, True], | |
| expectedResult = (False , 3), | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Hello World in Brainfuck", | |
| expression = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.", | |
| arguments = [True, True, True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Hello World in Brain-Flak", | |
| expression = "(((((((((((()()()()){}){}){}()))){}{}())[][][][])[][])[[]]())[[][][][][]]())([([]([])[][]{})]()()()([[]](([()()()]([([][][])](((({}()){}))){}{})))))", | |
| arguments = [True, True, True, True, True, True, True, True, True, True, True, True, True, True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| test( | |
| title = "Jailbreak", | |
| expression = "return (True, 0)", | |
| arguments = [True], | |
| expectedException = True, | |
| hideOK = hidePassedTests | |
| ) | |
| debug(hidePassedTests = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment