-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into new-fix-treetent-puzzle-editor
- Loading branch information
Showing
49 changed files
with
1,282 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package puzzles.shorttruthtable.rules; | ||
|
||
import edu.rpi.legup.model.tree.TreeNode; | ||
import edu.rpi.legup.model.tree.TreeTransition; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; | ||
import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction.DirectRuleAndIntroduction; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class AndIntroductionDirectRuleTest { | ||
private static final DirectRuleAndIntroduction RULE = new DirectRuleAndIntroduction(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given a statement: A ^ B | ||
* | ||
* Asserts that if at least 1 of A or B is false, then this is a valid application | ||
* of the rule if and only if ^ is false. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseAndTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/"; | ||
falseAndTestHelper(path + "FUF"); | ||
falseAndTestHelper(path + "FUU"); | ||
falseAndTestHelper(path + "UUF"); | ||
falseAndTestHelper(path + "FUT"); | ||
falseAndTestHelper(path + "TUF"); | ||
} | ||
|
||
private void falseAndTestHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell and = board.getCell(1, 0); | ||
|
||
and.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(and); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
|
||
and.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(and); | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
|
||
/** | ||
* Given a statement: A ^ B | ||
* | ||
* Asserts that setting ^ to true is a valid application of the rule if | ||
* and only if both A and B are true. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseOrTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
trueAndTestHelper(path + first + "U" + second); | ||
} | ||
} | ||
} | ||
|
||
private void trueAndTestHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
ShortTruthTableCell and = board.getCell(1, 0); | ||
|
||
and.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(and); | ||
|
||
if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package puzzles.shorttruthtable.rules; | ||
|
||
import edu.rpi.legup.model.tree.TreeNode; | ||
import edu.rpi.legup.model.tree.TreeTransition; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; | ||
import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction.DirectRuleBiconditionalIntroduction; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class BiconditionalIntroductionTest { | ||
private static final DirectRuleBiconditionalIntroduction RULE = new DirectRuleBiconditionalIntroduction(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given a statement: A <-> B | ||
* | ||
* Asserts that if setting <-> to false is a valid application of this rule if and | ||
* only if A and B do not match. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseConditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/"; | ||
|
||
String[] letters = {"T", "F", "U"}; | ||
for (String a : letters) { | ||
for (String b : letters) { | ||
System.out.println(a + b); | ||
falseConditionalHelper(path + a + "U" + b); | ||
} | ||
} | ||
} | ||
|
||
private void falseConditionalHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell conditional = board.getCell(1, 0); | ||
|
||
conditional.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(conditional); | ||
|
||
ShortTruthTableCell a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
if (a.getType() != b.getType()) { | ||
// Not valid if they don't match but at least one of the values of A or B is unknown | ||
if (a.getType() == ShortTruthTableCellType.UNKNOWN || b.getType() == ShortTruthTableCellType.UNKNOWN) { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A <-> B | ||
* | ||
* Asserts that if setting <-> to true is a valid application of this rule if and | ||
* only if A and B match. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void TrueConditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/"; | ||
|
||
String[] letters = {"T", "F", "U"}; | ||
for (String a : letters) { | ||
for (String b : letters) { | ||
System.out.println(a + b); | ||
trueConditionalHelper(path + a + "U" + b); | ||
} | ||
} | ||
} | ||
|
||
private void trueConditionalHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell conditional = board.getCell(1, 0); | ||
|
||
conditional.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(conditional); | ||
|
||
ShortTruthTableCell a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
if (a.getType() == b.getType() && a.getType() != ShortTruthTableCellType.UNKNOWN) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package puzzles.shorttruthtable.rules; | ||
|
||
import edu.rpi.legup.model.tree.TreeNode; | ||
import edu.rpi.legup.model.tree.TreeTransition; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; | ||
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; | ||
import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction.DirectRuleConditionalIntroduction; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class ConditionalIntroductionTest { | ||
private static final DirectRuleConditionalIntroduction RULE = new DirectRuleConditionalIntroduction(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given a statement: A -> B | ||
* | ||
* Asserts that if setting -> to false is a valid application of this rule if and | ||
* only if A is true and B is false. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseConditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/"; | ||
|
||
String[] letters = {"T", "F", "U"}; | ||
for (String a : letters) { | ||
for (String b : letters) { | ||
falseConditionalHelper(path + a + "U" + b); | ||
} | ||
} | ||
} | ||
|
||
private void falseConditionalHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell conditional = board.getCell(1, 0); | ||
|
||
conditional.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(conditional); | ||
|
||
ShortTruthTableCell a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.FALSE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A -> B | ||
* | ||
* Asserts that if setting -> to true is a valid application of this rule if and | ||
* only if A is false or B is true. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void TrueConditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/"; | ||
|
||
String[] letters = {"T", "F", "U"}; | ||
for (String a : letters) { | ||
for (String b : letters) { | ||
trueConditionalTestHelper(path + a + "U" + b); | ||
} | ||
} | ||
} | ||
|
||
private void trueConditionalTestHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell conditional = board.getCell(1, 0); | ||
|
||
conditional.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(conditional); | ||
|
||
ShortTruthTableCell a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
if (a.getType() == ShortTruthTableCellType.FALSE || b.getType() == ShortTruthTableCellType.TRUE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} |
Oops, something went wrong.