From 58c7790fe382cc9190618cf5f6e2ad1ce100bc7f Mon Sep 17 00:00:00 2001 From: Tim Vieira Date: Sat, 6 Jul 2013 13:44:56 -0400 Subject: [PATCH] update tests - new solution formatting. --- examples/expected/lists.py.out | 2 +- examples/expected/matrixops.py.out | 6 +++--- examples/expected/simple.py.out | 6 +++--- examples/matrixops.dyna | 14 +++++++------- src/Dyna/Backend/Python/chart.py | 9 +++++---- src/Dyna/Backend/Python/interpreter.py | 6 ++---- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/examples/expected/lists.py.out b/examples/expected/lists.py.out index 24c96b5..c678512 100644 --- a/examples/expected/lists.py.out +++ b/examples/expected/lists.py.out @@ -16,7 +16,7 @@ d(4) = true. f/1 === -f([1, 2]) = true. +f([1, 2]). foo/1 ===== diff --git a/examples/expected/matrixops.py.out b/examples/expected/matrixops.py.out index 83e757e..da4fd8e 100644 --- a/examples/expected/matrixops.py.out +++ b/examples/expected/matrixops.py.out @@ -39,9 +39,9 @@ rows(c) = 2. shape/3 ======= -shape(a,2,2) = true. -shape(b,2,3) = true. -shape(c,2,3) = true. +shape(a,2,2). +shape(b,2,3). +shape(c,2,3). times/4 ======= diff --git a/examples/expected/simple.py.out b/examples/expected/simple.py.out index 4217593..2b3666e 100644 --- a/examples/expected/simple.py.out +++ b/examples/expected/simple.py.out @@ -1,7 +1,7 @@ Solution ======== -a = true. -b = true. -c = true. +a. +b. +c. diff --git a/examples/matrixops.dyna b/examples/matrixops.dyna index 4dc21d5..5c08af5 100644 --- a/examples/matrixops.dyna +++ b/examples/matrixops.dyna @@ -19,19 +19,19 @@ cols(X) max= _ is m(X, _, C), C. % matrix "a" = [ 1 0 ; % 0 1 ] m(a, 1, 1) += 1. -m(a, 1, 2) += 0 . -m(a, 2, 1) += 0 . +m(a, 1, 2) += 0. +m(a, 2, 1) += 0. m(a, 2, 2) += 1. % matrix "b" = [ 3 0 1 ; % 0 2 0 ] m(b, 1, 1) += 3. -m(b, 1, 2) += 0 . -m(b, 1, 3) += 1 . -m(b, 2, 1) += 0 . +m(b, 1, 2) += 0. +m(b, 1, 3) += 1. +m(b, 2, 1) += 0. m(b, 2, 2) += 2. -m(b, 2, 3) += 0 . +m(b, 2, 3) += 0. % matrix "c" is the product of matricies "a" and "b" :-dispos product(&,&). -product(a,b) := &c . +product(a,b) := &c. diff --git a/src/Dyna/Backend/Python/chart.py b/src/Dyna/Backend/Python/chart.py index 0ef1c9a..a2b9c2b 100644 --- a/src/Dyna/Backend/Python/chart.py +++ b/src/Dyna/Backend/Python/chart.py @@ -21,6 +21,8 @@ class Chart(object): if not rows: return '' + heading = [self.name, '='*len(self.name)] + # special handing or-equals aggregators -- only list true facts (and errors) if self.agg_name == ':-' or self.agg_name == '|=': lines = [] @@ -30,7 +32,7 @@ class Chart(object): elif term.value: # e.g. $error lines.append('%s = %s.' % (_repr(term), _repr(term.value))) if self.arity != 0: - lines.append('') + lines = heading + lines # heading return '\n'.join(lines) if self.arity == 0: @@ -38,14 +40,13 @@ class Chart(object): return '%s = %s.' % (term, _repr(term.value)) p = [(_repr(term), _repr(term.value)) for term in sorted(rows)] - lines = [self.name, '='*len(self.name)] # heading + lines = [] terms, values = zip(*p) widths = map(len, terms) fmt = '%%-%ds = %%s.' % min(max(widths), 40) for term, value in zip(terms, values): lines.append(fmt % (term, value)) - lines.append('') - return '\n'.join(lines) + return '\n'.join(heading + lines) def __getitem__(self, s): assert len(s) == self.arity + 1, \ diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index 87dcbb1..fce690d 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -227,12 +227,10 @@ class Interpreter(object): if nullary: for line in nullary: print >> out, line - print >> out - else: - print >> out - + print >> out for line in charts: print >> out, line + print >> out self.dump_errors(out) -- 2.50.1