-
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.
Short Truth Table remaining case rules (#737)
* Created conditional case rule test files * More test files * Created Conditional Case Rule tests * Added test files * Started creating tests Added true biconditional tests, false biconditional tests are not written yet * Finished False tests and changed variable names * Update BiconditionalCaseRuleTest.java Modified comments * Update OrCaseRuleTest.java Fixed inaccurate comments --------- Co-authored-by: Chase Grajeda <[email protected]>
- Loading branch information
1 parent
5452703
commit 3541a9b
Showing
13 changed files
with
479 additions
and
2 deletions.
There are no files selected for viewing
186 changes: 186 additions & 0 deletions
186
src/test/java/puzzles/shorttruthtable/rules/BiconditionalCaseRuleTest.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,186 @@ | ||
package puzzles.shorttruthtable.rules; | ||
|
||
import edu.rpi.legup.model.gameboard.Board; | ||
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.caserule.CaseRuleBiconditional; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class BiconditionalCaseRuleTest { | ||
|
||
private static final CaseRuleBiconditional RULE = new CaseRuleBiconditional(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
private void trueBiconditionalTest(String fileName, | ||
int biconditionalX, int biconditionalY, | ||
int aX, int aY, | ||
int bX, int bY) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell cell = board.getCell(biconditionalX, biconditionalY); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
// Make sure that the rule checks out | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
// Make sure there are two branches | ||
Assert.assertEquals(2, cases.size()); | ||
|
||
ShortTruthTableBoard caseBoard1 = (ShortTruthTableBoard) cases.get(0); | ||
ShortTruthTableCellType board1A = caseBoard1.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board1B = caseBoard1.getCell(bX, bY).getType(); | ||
|
||
ShortTruthTableBoard caseBoard2 = (ShortTruthTableBoard) cases.get(1); | ||
ShortTruthTableCellType board2A = caseBoard2.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board2B = caseBoard2.getCell(bX, bY).getType(); | ||
|
||
// Assert that the corresponding cells for the different case rules do not | ||
// match with each other | ||
Assert.assertNotEquals(board1A, board2A); | ||
Assert.assertNotEquals(board1B, board2B); | ||
|
||
// Assert that A and B are equal and either true or false in both branches | ||
Assert.assertEquals(board1A, board1B); | ||
Assert.assertTrue( | ||
(board1A.equals(ShortTruthTableCellType.TRUE) && board1B.equals(ShortTruthTableCellType.TRUE)) || (board1A.equals(ShortTruthTableCellType.FALSE) && board1B.equals(ShortTruthTableCellType.FALSE)) | ||
); | ||
|
||
Assert.assertNotEquals(board1B, board2B); | ||
Assert.assertTrue( | ||
(board2A.equals(ShortTruthTableCellType.TRUE) && board2B.equals(ShortTruthTableCellType.TRUE)) || (board2A.equals(ShortTruthTableCellType.FALSE) && board2B.equals(ShortTruthTableCellType.FALSE)) | ||
); | ||
|
||
// Verify the board dimensions are unchanged | ||
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); | ||
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); | ||
|
||
// Verify that everywhere else on the board is unchanged | ||
for (int i = 0; i< caseBoard1.getWidth(); i++) { | ||
for (int j = 0; j < caseBoard1.getHeight(); j++) { | ||
// Make sure not to check the two cells that should be different | ||
if (!((i == aX && j == aY) || (i == bX && j == bY))) { | ||
Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement A -> B where ^ is true, tests this case rule by ensuring that | ||
* two branches are created: one where A is false and one where B is true. | ||
*/ | ||
@Test | ||
public void SimpleStatement1TrueTest() throws InvalidFileFormatException { | ||
trueBiconditionalTest("TrueBiconditional", 1, 0, 0, 0, 2, 0); | ||
} | ||
|
||
/** | ||
* Given a statement ~(A|B) -> (C^D) where the -> is true, tests this case rule | ||
* by ensuring that two branches are created: one where ~ is false and one where | ||
* ^ is true. | ||
*/ | ||
@Test | ||
public void ComplexStatement1TrueTest() throws InvalidFileFormatException { | ||
trueBiconditionalTest("ComplexStatement1_True", 6, 0, 0, 0, | ||
9, 0); | ||
} | ||
|
||
private void falseBiconditionalTest(String fileName, | ||
int biconditionalX, int biconditionalY, | ||
int aX, int aY, | ||
int bX, int bY) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell cell = board.getCell(biconditionalX, biconditionalY); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
// Make sure that the rule checks out | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
// Make sure there are two branches | ||
Assert.assertEquals(2, cases.size()); | ||
|
||
ShortTruthTableBoard caseBoard1 = (ShortTruthTableBoard) cases.get(0); | ||
ShortTruthTableCellType board1A = caseBoard1.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board1B = caseBoard1.getCell(bX, bY).getType(); | ||
|
||
ShortTruthTableBoard caseBoard2 = (ShortTruthTableBoard) cases.get(1); | ||
ShortTruthTableCellType board2A = caseBoard2.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board2B = caseBoard2.getCell(bX, bY).getType(); | ||
|
||
// Assert that the corresponding cells for the different case rules do not | ||
// match with each other | ||
Assert.assertNotEquals(board1A, board2A); | ||
Assert.assertNotEquals(board1B, board2B); | ||
|
||
// Assert that A and B are not equal and are both either true or false in both branches | ||
Assert.assertNotEquals(board1A, board1B); | ||
Assert.assertTrue( | ||
(board1A.equals(ShortTruthTableCellType.TRUE) && board1B.equals(ShortTruthTableCellType.FALSE)) || (board1A.equals(ShortTruthTableCellType.FALSE) && board1B.equals(ShortTruthTableCellType.TRUE)) | ||
); | ||
|
||
Assert.assertNotEquals(board2A, board2B); | ||
Assert.assertTrue( | ||
(board2A.equals(ShortTruthTableCellType.TRUE) && board2B.equals(ShortTruthTableCellType.FALSE)) || (board2A.equals(ShortTruthTableCellType.FALSE) && board2B.equals(ShortTruthTableCellType.TRUE)) | ||
); | ||
|
||
// Verify the board dimensions are unchanged | ||
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); | ||
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); | ||
|
||
// Verify that everywhere else on the board is unchanged | ||
for (int i = 0; i< caseBoard1.getWidth(); i++) { | ||
for (int j = 0; j < caseBoard1.getHeight(); j++) { | ||
// Make sure not to check the two cells that should be different | ||
if (!((i == aX && j == aY) || (i == bX && j == bY))) { | ||
Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement A -> B where -> is false, tests this case rule by ensuring that | ||
* one branch is created where A is true and B is false. | ||
*/ | ||
@Test | ||
public void SimpleStatement1FalseTest() throws InvalidFileFormatException { | ||
falseBiconditionalTest("FalseBiconditional", 1, 0, 0, 0, | ||
2, 0); | ||
} | ||
|
||
/** | ||
* Given a statement ~(A|B) -> (C^D) where -> is true, tests this case rule | ||
* by ensuring that one branch is created where ~ is true and ^ is false. | ||
*/ | ||
@Test | ||
public void ComplexStatement1FalseTest() throws InvalidFileFormatException { | ||
falseBiconditionalTest("ComplexStatement1_False", 6, 0, 0, 0, | ||
9, 0); | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
src/test/java/puzzles/shorttruthtable/rules/ConditionalCaseRuleTest.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,163 @@ | ||
package puzzles.shorttruthtable.rules; | ||
|
||
import edu.rpi.legup.model.gameboard.Board; | ||
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.caserule.CaseRuleConditional; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ConditionalCaseRuleTest { | ||
|
||
private static final CaseRuleConditional RULE = new CaseRuleConditional(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
private void trueConditionalTest(String fileName, | ||
int conditionalX, int conditionalY, | ||
int aX, int aY, | ||
int bX, int bY) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalCaseRule/" + fileName, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell cell = board.getCell(conditionalX, conditionalY); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
// Make sure that the rule checks out | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
// Make sure there are two branches | ||
Assert.assertEquals(2, cases.size()); | ||
|
||
ShortTruthTableBoard caseBoard1 = (ShortTruthTableBoard) cases.get(0); | ||
ShortTruthTableCellType board1A = caseBoard1.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board1B = caseBoard1.getCell(bX, bY).getType(); | ||
|
||
ShortTruthTableBoard caseBoard2 = (ShortTruthTableBoard) cases.get(1); | ||
ShortTruthTableCellType board2A = caseBoard2.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType board2B = caseBoard2.getCell(bX, bY).getType(); | ||
|
||
// Assert that the corresponding cells for the different case rules do not | ||
// match with each other | ||
Assert.assertNotEquals(board1A, board2A); | ||
Assert.assertNotEquals(board1B, board2B); | ||
|
||
// Assert that A is unknown in one board and false in the other | ||
Assert.assertNotEquals(board1A, board2A); | ||
Assert.assertTrue( | ||
(board1A.equals(ShortTruthTableCellType.UNKNOWN) && board2A.equals(ShortTruthTableCellType.FALSE)) | ||
|| (board1A.equals(ShortTruthTableCellType.FALSE) && board2A.equals(ShortTruthTableCellType.UNKNOWN)) | ||
); | ||
|
||
// Assert that B is unknown in one board and true in the other | ||
Assert.assertNotEquals(board1B, board2B); | ||
Assert.assertTrue( | ||
(board1B.equals(ShortTruthTableCellType.UNKNOWN) && board2B.equals(ShortTruthTableCellType.TRUE)) | ||
|| (board1B.equals(ShortTruthTableCellType.TRUE) && board2B.equals(ShortTruthTableCellType.UNKNOWN)) | ||
); | ||
|
||
// Verify the board dimensions are unchanged | ||
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); | ||
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); | ||
|
||
// Verify that everywhere else on the board is unchanged | ||
for (int i = 0; i< caseBoard1.getWidth(); i++) { | ||
for (int j = 0; j < caseBoard1.getHeight(); j++) { | ||
// Make sure not to check the two cells that should be different | ||
if (!((i == aX && j == aY) || (i == bX && j == bY))) { | ||
Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement A -> B where ^ is true, tests this case rule by ensuring that | ||
* two branches are created: one where A is false and one where B is true. | ||
*/ | ||
@Test | ||
public void SimpleStatement1TrueTest() throws InvalidFileFormatException { | ||
trueConditionalTest("TrueConditional", 1, 0, 0, 0, | ||
2, 0); | ||
} | ||
|
||
/** | ||
* Given a statement ~(A|B) -> (C^D) where the -> is true, tests this case rule | ||
* by ensuring that two branches are created: one where ~ is false and one where | ||
* ^ is true. | ||
*/ | ||
@Test | ||
public void ComplexStatement1TrueTest() throws InvalidFileFormatException { | ||
trueConditionalTest("ComplexStatement1_True", 6, 0, 0, 0, | ||
9, 0); | ||
} | ||
|
||
private void falseConditionalTest(String fileName, | ||
int conditionalX, int conditionalY, | ||
int aX, int aY, | ||
int bX, int bY) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalCaseRule/" + fileName, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); | ||
ShortTruthTableCell cell = board.getCell(conditionalX, conditionalY); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
// Make sure that the rule checks out | ||
Assert.assertNull(RULE.checkRule(transition)); | ||
|
||
// There should only be 1 branch | ||
Assert.assertEquals(1, cases.size()); | ||
|
||
ShortTruthTableBoard caseBoard = (ShortTruthTableBoard) cases.get(0); | ||
ShortTruthTableCellType caseBoardAType = caseBoard.getCell(aX, aY).getType(); | ||
ShortTruthTableCellType caseBoardBType = caseBoard.getCell(bX, bY).getType(); | ||
|
||
// A should be true and B should be false | ||
Assert.assertEquals(caseBoardAType, ShortTruthTableCellType.TRUE); | ||
Assert.assertEquals(caseBoardBType, ShortTruthTableCellType.FALSE); | ||
|
||
// Verify the board dimensions are unchanged | ||
Assert.assertEquals(caseBoard.getHeight(), caseBoard.getHeight(), board.getHeight()); | ||
} | ||
|
||
/** | ||
* Given a statement A -> B where -> is false, tests this case rule by ensuring that | ||
* one branch is created where A is true and B is false. | ||
*/ | ||
@Test | ||
public void SimpleStatement1FalseTest() throws InvalidFileFormatException { | ||
falseConditionalTest("FalseConditional", 1, 0, 0, 0, | ||
2, 0); | ||
} | ||
|
||
/** | ||
* Given a statement ~(A|B) -> (C^D) where -> is true, tests this case rule | ||
* by ensuring that one branch is created where ~ is true and ^ is false. | ||
*/ | ||
@Test | ||
public void ComplexStatement1FalseTest() throws InvalidFileFormatException { | ||
falseConditionalTest("ComplexStatement1_False", 6, 0, 0, 0, | ||
9, 0); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...est/resources/puzzles/shorttruthtable/rules/BiconditionalCaseRule/ComplexStatement1_False
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)-(C^D)" row_index="0"/> | ||
<cell char_index="6" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-28 13:39:00"/> | ||
</Legup> |
13 changes: 13 additions & 0 deletions
13
...test/resources/puzzles/shorttruthtable/rules/BiconditionalCaseRule/ComplexStatement1_True
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)-(C^D)" row_index="0"/> | ||
<cell char_index="6" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-28 13:39:00"/> | ||
</Legup> |
Oops, something went wrong.