Skip to content

Commit

Permalink
Merge pull request ggp-org#33 from ggp-org/simple-sentence-form-fixes
Browse files Browse the repository at this point in the history
Simple sentence form fixes
  • Loading branch information
AlexLandau committed Nov 10, 2013
2 parents 17f0107 + 9ff4e55 commit d0a32e0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/org/ggp/base/test/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

}
28 changes: 28 additions & 0 deletions src/org/ggp/base/test/SimpleSentenceFormTest.java
Original file line number Diff line number Diff line change
@@ -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<GdlTerm> tuple = GdlUtils.getTupleFromSentence(sentence);
Assert.assertEquals(sentence,
form.getSentenceFromTuple(tuple));
}
}
3 changes: 2 additions & 1 deletion src/org/ggp/base/util/gdl/model/SimpleSentenceForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -185,7 +186,7 @@ private GdlFunction getFunctionFromTuple(List<? extends GdlTerm> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/org/ggp/base/validator/OPNFValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/ggp/base/validator/ValidatorException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d0a32e0

Please sign in to comment.