From cd0301df3fc848e08678c11f42c2b1a3e2982fe0 Mon Sep 17 00:00:00 2001 From: alandau Date: Sun, 10 Nov 2013 15:42:17 -0800 Subject: [PATCH 1/2] Don't swallow validator stacktraces. This won't affect the Validator app output, just when it's run directly from main(). --- src/org/ggp/base/validator/OPNFValidator.java | 4 ++-- src/org/ggp/base/validator/ValidatorException.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/ggp/base/validator/OPNFValidator.java b/src/org/ggp/base/validator/OPNFValidator.java index 48d407733..ff33ed6f4 100644 --- a/src/org/ggp/base/validator/OPNFValidator.java +++ b/src/org/ggp/base/validator/OPNFValidator.java @@ -11,13 +11,13 @@ public final class OPNFValidator implements GameValidator @Override public void checkValidity(Game theGame) throws ValidatorException { PrintStream stdout = System.out; - System.setOut(new PrintStream(new ByteArrayOutputStream())); + System.setOut(new PrintStream(new ByteArrayOutputStream())); try { if (OptimizingPropNetFactory.create(theGame.getRules()) == null) { throw new ValidatorException("Got null result from OPNF"); } } catch (Exception e) { - throw new ValidatorException("OPNF Exception: " + e); + throw new ValidatorException("OPNF Exception: " + e, e); } finally { System.setOut(stdout); } diff --git a/src/org/ggp/base/validator/ValidatorException.java b/src/org/ggp/base/validator/ValidatorException.java index a8c409fa7..dad5da6a0 100644 --- a/src/org/ggp/base/validator/ValidatorException.java +++ b/src/org/ggp/base/validator/ValidatorException.java @@ -5,4 +5,8 @@ public class ValidatorException extends Exception { public ValidatorException(String explanation) { super("Validator: " + explanation); } + + public ValidatorException(String explanation, Throwable t) { + super("Validator: " + explanation, t); + } } From 5c4a574ddfe23d9536b0ac372200a44506167e04 Mon Sep 17 00:00:00 2001 From: alandau Date: Sun, 10 Nov 2013 15:43:17 -0800 Subject: [PATCH 2/2] Fix a couple of bugs in the SimpleSentenceForm. Add a regression test. --- src/org/ggp/base/test/AllTests.java | 14 ++++++---- .../ggp/base/test/SimpleSentenceFormTest.java | 28 +++++++++++++++++++ .../util/gdl/model/SimpleSentenceForm.java | 3 +- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/org/ggp/base/test/SimpleSentenceFormTest.java diff --git a/src/org/ggp/base/test/AllTests.java b/src/org/ggp/base/test/AllTests.java index de5c9a1cc..95c8493b1 100644 --- a/src/org/ggp/base/test/AllTests.java +++ b/src/org/ggp/base/test/AllTests.java @@ -4,12 +4,14 @@ import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({GdlCleanerTests.class, - NoTabsInRulesheetsTest.class, - ProverStateMachineTests.class, - StaticValidationTests.class, - GameParsingTests.class +@Suite.SuiteClasses({ + GameParsingTests.class, + GdlCleanerTests.class, + NoTabsInRulesheetsTest.class, + ProverStateMachineTests.class, + SimpleSentenceFormTest.class, + StaticValidationTests.class }) public class AllTests { - + } diff --git a/src/org/ggp/base/test/SimpleSentenceFormTest.java b/src/org/ggp/base/test/SimpleSentenceFormTest.java new file mode 100644 index 000000000..4a680e95d --- /dev/null +++ b/src/org/ggp/base/test/SimpleSentenceFormTest.java @@ -0,0 +1,28 @@ +package org.ggp.base.test; + +import java.util.List; + +import junit.framework.Assert; + +import org.ggp.base.util.gdl.GdlUtils; +import org.ggp.base.util.gdl.factory.GdlFactory; +import org.ggp.base.util.gdl.grammar.GdlPool; +import org.ggp.base.util.gdl.grammar.GdlSentence; +import org.ggp.base.util.gdl.grammar.GdlTerm; +import org.ggp.base.util.gdl.model.SimpleSentenceForm; +import org.junit.Test; + +public class SimpleSentenceFormTest { + @Test + public void testFunctionNesting() throws Exception { + GdlSentence sentence = (GdlSentence) GdlFactory.create("(does player (combine foo (bar b b)))"); + SimpleSentenceForm form = SimpleSentenceForm.create(sentence); + Assert.assertEquals(GdlPool.DOES, form.getName()); + Assert.assertEquals(4, form.getTupleSize()); + Assert.assertTrue(form.matches(sentence)); + + List tuple = GdlUtils.getTupleFromSentence(sentence); + Assert.assertEquals(sentence, + form.getSentenceFromTuple(tuple)); + } +} diff --git a/src/org/ggp/base/util/gdl/model/SimpleSentenceForm.java b/src/org/ggp/base/util/gdl/model/SimpleSentenceForm.java index 69ceeecc6..73e26024b 100644 --- a/src/org/ggp/base/util/gdl/model/SimpleSentenceForm.java +++ b/src/org/ggp/base/util/gdl/model/SimpleSentenceForm.java @@ -57,6 +57,7 @@ private static SimpleSentenceForm create(GdlFunction function) { if (term instanceof GdlFunction) { SimpleSentenceForm functionForm = create((GdlFunction) term); functions.put(i, functionForm); + tupleSize += functionForm.getTupleSize(); } else { tupleSize++; } @@ -185,7 +186,7 @@ private GdlFunction getFunctionFromTuple(List tuple, Preconditions.checkArgument(!(term instanceof GdlFunction)); if (functions.containsKey(i)) { SimpleSentenceForm functionForm = functions.get(i); - functionBody.add(getFunctionFromTuple(tuple, curIndex)); + functionBody.add(functionForm.getFunctionFromTuple(tuple, curIndex)); curIndex += functionForm.getTupleSize(); } else { functionBody.add(term);