Skip to content

Commit

Permalink
Fix a couple of bugs in the SimpleSentenceForm. Add a regression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexLandau committed Nov 10, 2013
1 parent cd0301d commit 5c4a574
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 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

0 comments on commit 5c4a574

Please sign in to comment.