From 8813d24c04f7aa7ed7fe034b84f3a2ad6118e87b Mon Sep 17 00:00:00 2001 From: Tim Vieira Date: Sat, 13 Jul 2013 11:05:22 -0400 Subject: [PATCH] new tests for error handling. --- run-doctests.py | 3 +- test/app/ptb.dynadoc | 10 +-- test/error-handling/basics.dynadoc | 87 +++++++++++++++++++++++++++ test/error-handling/clearing.dynadoc | 59 ++++++++++++++++++ test/error-handling/clearing2.dynadoc | 37 ++++++++++++ 5 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 test/error-handling/basics.dynadoc create mode 100644 test/error-handling/clearing.dynadoc create mode 100644 test/error-handling/clearing2.dynadoc diff --git a/run-doctests.py b/run-doctests.py index 7b4ddc5..cb4f732 100755 --- a/run-doctests.py +++ b/run-doctests.py @@ -13,8 +13,9 @@ from dyna_doctest import run from utils import red, green failures = [] -for x in path('test/repl').glob("*.dynadoc"): +for x in path('test').glob("*/*.dynadoc"): print x, + sys.stdout.flush() with file(x) as f: g = StringIO() if run(f.read(), g): diff --git a/test/app/ptb.dynadoc b/test/app/ptb.dynadoc index 40d17a3..4581fc5 100644 --- a/test/app/ptb.dynadoc +++ b/test/app/ptb.dynadoc @@ -134,8 +134,8 @@ | tostring([X,Y,Z]) := "(" + tostring(X) + " " + tostring(Y) + " " + tostring(Z) + ")". % collect errors -> errors(S) = [tostring(parse(S)), tostring(b(tree(S)))] for parse(S) != b(tree(S)). - *ignore* +%> errors(S) = [tostring(parse(S)), tostring(b(tree(S)))] for parse(S) != b(tree(S)). +% *ignore* % report accuracy > correct += parse(S) == b(tree(S)), 1.0. @@ -149,8 +149,8 @@ correct = 21.0. ntrees = 23. % inspect errors -> query errors(S) -errors(12) = ["(ROOT (S (NP Laura) (VP (VP (V (V say) -s) (SBAR that (S (NP George) (VP (Modal might) (VP (V sleep)))))) (PP (P on) (NP (Det the) (N floor))))) !)", "(ROOT (S (NP Laura) (VP (V (V say) -s) (SBAR that (S (NP George) (VP (VP (Modal might) (VP (V sleep))) (PP (P on) (NP (Det the) (N floor)))))))) !)"]. -errors(21) = ["(ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) (@Adj and (Adj blue))) (N woman))) (@NP and (NP (Det every) (N man)))) (VP (VP (Modal must) (VP (V have) (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))))) (@VP and (VP (VP (V (V sleep) -ed)) (PP (P on) (NP (Det the) (N floor))))))) .)", "(ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) (@Adj and (Adj blue))) (N woman))) (@NP and (NP (Det every) (N man)))) (VP (VP (Modal must) (VP (V have) (VP (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))) (@VP and (VP (V (V sleep) -ed)))))) (PP (P on) (NP (Det the) (N floor))))) .)"]. +%> query errors(S) +%errors(12) = ["(ROOT (S (NP Laura) (VP (VP (V (V say) -s) (SBAR that (S (NP George) (VP (Modal might) (VP (V sleep)))))) (PP (P on) (NP (Det the) (N floor))))) !)", "(ROOT (S (NP Laura) (VP (V (V say) -s) (SBAR that (S (NP George) (VP (VP (Modal might) (VP (V sleep))) (PP (P on) (NP (Det the) (N floor)))))))) !)"]. +%errors(21) = ["(ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) (@Adj and (Adj blue))) (N woman))) (@NP and (NP (Det every) (N man)))) (VP (VP (Modal must) (VP (V have) (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))))) (@VP and (VP (VP (V (V sleep) -ed)) (PP (P on) (NP (Det the) (N floor))))))) .)", "(ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) (@Adj and (Adj blue))) (N woman))) (@NP and (NP (Det every) (N man)))) (VP (VP (Modal must) (VP (V have) (VP (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))) (@VP and (VP (V (V sleep) -ed)))))) (PP (P on) (NP (Det the) (N floor))))) .)"]. %> *resume* \ No newline at end of file diff --git a/test/error-handling/basics.dynadoc b/test/error-handling/basics.dynadoc new file mode 100644 index 0000000..202701a --- /dev/null +++ b/test/error-handling/basics.dynadoc @@ -0,0 +1,87 @@ + +> b := 0. +| a += 1/b. +| +| c += "" + b. +| +| e := 0. +| +| b := e/0. +| a += e/0. +| +| d += null. +| d += 1. +| +| a(X) := f(X,Y). +| +| f(1,1) := 1. +| f(1,2) := 2. +| +| f(2,1) := 1. +| f(2,2) := 2. + +Changes +======= +a(1) = $error. +a(2) = $error. +b = 0. +d = $error. +e = 0. +f(1,1) = 1. +f(1,2) = 2. +f(2,1) = 1. +f(2,2) = 2. + +> sol + +Solution +======== +b = 0. +d = $error. +e = 0. + +a/1 +=== +a(1) = $error. +a(2) = $error. + +f/2 +=== +f(1,1) = 1. +f(1,2) = 2. +f(2,1) = 1. +f(2,2) = 2. + +Errors +====== +Error(s) aggregating a/1: + AggregatorError: + `a(1)`: `:=` got conflicting values [1, 2] for rule index 8 + `a(2)`: `:=` got conflicting values [1, 2] for rule index 8 +Error(s) aggregating d/0: + TypeError: + `d`: unsupported operand type(s) for *: 'NoneType' and 'int' +Error(s) in rule: + a += 1/b. + ZeroDivisionError: + when `b` = 0 + division by zero + a += (1 / b=0)=?. +Error(s) in rule: + c += "" + b. + TypeError: + when `b` = 0 + cannot concatenate 'str' and 'int' objects + c += ("" + b=0)=?. +Error(s) in rule: + b := e/0. + ZeroDivisionError: + when `e` = 0 + division by zero + b := (e=0 / 0)=?. +Error(s) in rule: + a += e/0. + ZeroDivisionError: + when `e` = 0 + division by zero + a += (e=0 / 0)=?. diff --git a/test/error-handling/clearing.dynadoc b/test/error-handling/clearing.dynadoc new file mode 100644 index 0000000..1d7e82d --- /dev/null +++ b/test/error-handling/clearing.dynadoc @@ -0,0 +1,59 @@ +> d += 0. + +Changes +======= +d = 0. + +> a += 1. + +Changes +======= +a = 1. + +> b += a. + +Changes +======= +b = 1. + +% OK so far. Now if I + +> a += 1/d. + +> sol + +Solution +======== +a = 1. +b = 1. +d = 0. + +Errors +====== +Uninitialized rules +=================== +Failed to initialize rule: + a += 1/d. + due to `division by zero` + a += (1 / d=0)=?. + + +% That seems OK. But when I + +> d += 1. + +Changes +======= +a = 2. +b = 2. +d = 1. + +% Looks good. + +> sol + +Solution +======== +a = 2. +b = 2. +d = 1. diff --git a/test/error-handling/clearing2.dynadoc b/test/error-handling/clearing2.dynadoc new file mode 100644 index 0000000..5585f4a --- /dev/null +++ b/test/error-handling/clearing2.dynadoc @@ -0,0 +1,37 @@ +> d += 0. + +Changes +======= +d = 0. + +> a += 1 / d. + +> rules + +Rules +===== + 0: d += 0. + 1: a += 1 / d. + + +> sol + +Solution +======== +d = 0. + +Errors +====== +Uninitialized rules +=================== +Failed to initialize rule: + a += 1 / d. + due to `division by zero` + a += (1 / d=0)=?. + +> d += 1. + +Changes +======= +a = 1.0. +d = 1. -- 2.50.1