-
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.
- Loading branch information
Showing
21 changed files
with
974 additions
and
0 deletions.
There are no files selected for viewing
373 changes: 373 additions & 0 deletions
373
src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
233 changes: 233 additions & 0 deletions
233
src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.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,233 @@ | ||
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.elimination.DirectRuleConditionalElimination; | ||
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 ConditionalEliminationTest { | ||
private static final DirectRuleConditionalElimination RULE = new DirectRuleConditionalElimination(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where -> is false | ||
* | ||
* Asserts that the only valid combination of A and B that is a valid application | ||
* of this rule is when A is true and B is false | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseConditionalTest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; | ||
|
||
for (ShortTruthTableCellType cellType1 : cellTypes) { | ||
for (ShortTruthTableCellType cellType2 : cellTypes) { | ||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell aubergine = board.getCell(0, 0); | ||
ShortTruthTableCell boniato = board.getCell(2, 0); | ||
|
||
aubergine.setData(cellType1); | ||
boniato.setData(cellType2); | ||
|
||
board.addModifiedData(aubergine); | ||
board.addModifiedData(boniato); | ||
|
||
if (cellType1 == ShortTruthTableCellType.TRUE && cellType2 == ShortTruthTableCellType.FALSE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where -> is false | ||
* | ||
* Asserts that this is a valid application of the rule if and only if A | ||
* is set to true. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseConditionalTrueATest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell aubergine = board.getCell(0, 0); | ||
|
||
aubergine.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(aubergine); | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
aubergine.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(aubergine); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where -> is false | ||
* | ||
* Asserts that this is a valid application of the rule if and only if B is | ||
* set to false. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseConditionalFalseBTest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell boniato = board.getCell(2, 0); | ||
|
||
boniato.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
boniato.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where -> is true | ||
* | ||
* Asserts that you cannot set any combination of both A and B at the same time. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void CannotSetBothAandBTrueConditionalTest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; | ||
|
||
for (ShortTruthTableCellType cellType1 : cellTypes) { | ||
for (ShortTruthTableCellType cellType2 : cellTypes) { | ||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell aubergine = board.getCell(0, 0); | ||
ShortTruthTableCell boniato = board.getCell(2, 0); | ||
|
||
aubergine.setData(cellType1); | ||
boniato.setData(cellType2); | ||
|
||
board.addModifiedData(aubergine); | ||
board.addModifiedData(boniato); | ||
|
||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where A and -> are true | ||
* | ||
* Asserts that this is a valid application of this rule if and only if B | ||
* is set to true. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void TrueAMeansTrueBTest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell boniato = board.getCell(2, 0); | ||
|
||
boniato.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
boniato.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where B is false and -> is true | ||
* | ||
* Asserts that this is a valid application of this rule if and only if A | ||
* is set to false. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseBMeansFalseATest() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell aubergine = board.getCell(0, 0); | ||
|
||
aubergine.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(aubergine); | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
aubergine.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(aubergine); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
|
||
/** | ||
* Given one statement: A -> B where B and -> are true | ||
* | ||
* Asserts that this is not a valid application of this rule no matter what | ||
* A is set to. | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void TrueBCannotDetermineA() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell boniato = board.getCell(2, 0); | ||
|
||
boniato.setData(ShortTruthTableCellType.TRUE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
|
||
boniato.setData(ShortTruthTableCellType.FALSE); | ||
board.addModifiedData(boniato); | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.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,124 @@ | ||
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.elimination.DirectRuleNotElimination; | ||
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 NotEliminationTest { | ||
private static final DirectRuleNotElimination RULE = new DirectRuleNotElimination(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given one statement: ¬A where ¬ is false | ||
* | ||
* Asserts that this is a valid application of this rule if and only if A is true | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void FalseNot() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; | ||
|
||
for (ShortTruthTableCellType cellType : cellTypes) { | ||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell a = board.getCell(1, 0); | ||
a.setData(cellType); | ||
board.addModifiedData(a); | ||
|
||
if (cellType == ShortTruthTableCellType.TRUE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given one statement: ¬A where ¬ is true | ||
* | ||
* Asserts that this is a valid application of this rule if and only if A is false | ||
* | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void TrueNot() throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot", stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; | ||
|
||
for (ShortTruthTableCellType cellType : cellTypes) { | ||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell a = board.getCell(1, 0); | ||
a.setData(cellType); | ||
board.addModifiedData(a); | ||
|
||
if (cellType == ShortTruthTableCellType.FALSE) { | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRule(transition)); | ||
} | ||
} | ||
} | ||
|
||
// /** | ||
// * Given one statement: ¬A | ||
// * | ||
// * Asserts that setting both ¬ and A to any values would not be a valid | ||
// * application of this rule | ||
// * | ||
// * @throws InvalidFileFormatException | ||
// */ | ||
// @Test | ||
// public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { | ||
// TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot", stt); | ||
// TreeNode rootNode = stt.getTree().getRootNode(); | ||
// TreeTransition transition = rootNode.getChildren().get(0); | ||
// transition.setRule(RULE); | ||
// | ||
// ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; | ||
// | ||
// for (ShortTruthTableCellType cellType1 : cellTypes) { | ||
// for (ShortTruthTableCellType cellType2 : cellTypes) { | ||
// ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
// ShortTruthTableCell not = board.getCell(0, 0); | ||
// ShortTruthTableCell a = board.getCell(1, 0); | ||
// | ||
// not.setData(cellType1); | ||
// a.setData(cellType2); | ||
// | ||
// board.addModifiedData(not); | ||
// board.addModifiedData(a); | ||
// | ||
// System.out.println("TYPE1:" + cellType1); | ||
// System.out.println("TYPE2:" + cellType2); | ||
// Assert.assertNotNull(RULE.checkRule(transition)); | ||
// } | ||
// } | ||
// } | ||
} |
13 changes: 13 additions & 0 deletions
13
...urces/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditional
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<Legup version="3.0.0"> | ||
<saved/> | ||
<puzzle name="ShortTruthTable"> | ||
<board> | ||
<data> | ||
<statement representation="A-B" row_index="0"/> | ||
<cell char_index="1" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-10-24 16:44:53"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
...les/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<Legup version="3.0.0"> | ||
<saved/> | ||
<puzzle name="ShortTruthTable"> | ||
<board> | ||
<data> | ||
<statement representation="A-B" row_index="0"/> | ||
<cell char_index="0" row_index="0" type="FALSE"/> | ||
<cell char_index="1" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-10-24 16:57:00"/> | ||
</Legup> |
Oops, something went wrong.