]> hydra-www.ietfng.org Git - dyna2/commitdiff
new tests for error handling.
authorTim Vieira <tim.f.vieira@gmail.com>
Sat, 13 Jul 2013 15:05:22 +0000 (11:05 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Sat, 13 Jul 2013 15:05:22 +0000 (11:05 -0400)
run-doctests.py
test/app/ptb.dynadoc
test/error-handling/basics.dynadoc [new file with mode: 0644]
test/error-handling/clearing.dynadoc [new file with mode: 0644]
test/error-handling/clearing2.dynadoc [new file with mode: 0644]

index 7b4ddc567f1085ef5104e8af51c1e81568945028..cb4f732dc89924cc4a4f92c2d4267b37cd93099e 100755 (executable)
@@ -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):
index 40d17a3812ea04c22d7cf8b93644508e8de3818c..4581fc503f862fba5c4075f8c64b13189e538877 100644 (file)
 | 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 (file)
index 0000000..202701a
--- /dev/null
@@ -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: <repl>
+    a += 1/b.
+  ZeroDivisionError:
+    when `b` = 0
+      division by zero
+      a += (1 / b=0)=?.
+Error(s) in rule: <repl>
+    c += "" + b.
+  TypeError:
+    when `b` = 0
+      cannot concatenate 'str' and 'int' objects
+      c += ("" + b=0)=?.
+Error(s) in rule: <repl>
+    b := e/0.
+  ZeroDivisionError:
+    when `e` = 0
+      division by zero
+      b := (e=0 / 0)=?.
+Error(s) in rule: <repl>
+    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 (file)
index 0000000..1d7e82d
--- /dev/null
@@ -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 (file)
index 0000000..5585f4a
--- /dev/null
@@ -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.