-
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.
Finishing Short Truth Table Contradiction Rule tests (#713)
* Created Or Contradiction test files * Added false or test * Fixed false or test and added unknown or test * Methods should start with lowercase * Added true or test and removed useless lines * Added Not Contradiction test * Remove useless print statement * Added And Contradiction tests * Removed useless imports * Fixed bug with test * Added conditional test cases * Create ConditionalContradictionRuleTest.java Added Conditional Contradiction Rule tests * Added biconditional test files * Fixed typo * Create BiconditionalContradictionRuleTest.java Added biconditional contradiction rule tests * Added single test file * Added remaining test files * Added JUnit test * Removed unused tests Removed deprecated importer and statement tests --------- Co-authored-by: Chase Grajeda <[email protected]> Co-authored-by: Chase-Grajeda <[email protected]>
- Loading branch information
1 parent
6054db7
commit 5452703
Showing
98 changed files
with
1,956 additions
and
25 deletions.
There are no files selected for viewing
10 changes: 0 additions & 10 deletions
10
src/test/java/puzzles/shorttruthtable/ShortTruthTableImporterTest.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/test/java/puzzles/shorttruthtable/ShortTruthTableStatementTest.java
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
src/test/java/puzzles/shorttruthtable/rules/AndContradictionRuleTest.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,132 @@ | ||
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.contradiction.ContradictionRuleAnd; | ||
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 AndContradictionRuleTest { | ||
|
||
private static final ContradictionRuleAnd RULE = new ContradictionRuleAnd(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given a statement: A ^ B where ^ is true | ||
* | ||
* Asserts that this is a valid application of the rule if | ||
* and only if A or B are set to false. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void trueAndTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
trueAndTestHelper(path + first + "T" + 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); | ||
|
||
if (a.getType() == ShortTruthTableCellType.FALSE || b.getType() == ShortTruthTableCellType.FALSE) { | ||
Assert.assertNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A ^ B where ^ is false | ||
* | ||
* Asserts that this is a valid application of the rule if | ||
* and only if A or B (or both) are set to true. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void falseAndTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
falseAndTestHelper(path + first + "F" + second); | ||
} | ||
} | ||
} | ||
|
||
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 a = board.getCell(0, 0); | ||
ShortTruthTableCell b = board.getCell(2, 0); | ||
|
||
if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) { | ||
Assert.assertNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A ^ B where ^ is unknown | ||
* | ||
* Asserts that this is not a valid application of this rule. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void unknownAndTest() throws InvalidFileFormatException { | ||
// Getting the files that have or set to unknown from And Introduction | ||
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
unknownAndTestHelper(path + first + "U" + second); | ||
} | ||
} | ||
} | ||
|
||
private void unknownAndTestHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/puzzles/shorttruthtable/rules/AtomicContradictionRuleTest.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,65 @@ | ||
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.contradiction.ContradictionRuleAtomic; | ||
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 AtomicContradictionRuleTest { | ||
|
||
private static final ContradictionRuleAtomic RULE = new ContradictionRuleAtomic(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given two statements: A, A | ||
* | ||
* Asserts that this is a valid application of the rule if | ||
* and only if both A and B are not unknown and different. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void mismatchTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/AtomicContradictionRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
mismatchHelper(path + first + second); | ||
} | ||
} | ||
} | ||
|
||
private void mismatchHelper(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(0, 2); | ||
|
||
if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() != b.getType()) { | ||
Assert.assertNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
src/test/java/puzzles/shorttruthtable/rules/BiconditionalContradictionRuleTest.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,132 @@ | ||
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.contradiction.ContradictionRuleBiconditional; | ||
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 BiconditionalContradictionRuleTest { | ||
|
||
private static final ContradictionRuleBiconditional RULE = new ContradictionRuleBiconditional(); | ||
private static ShortTruthTable stt; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
stt = new ShortTruthTable(); | ||
} | ||
|
||
/** | ||
* Given a statement: A <-> B where <-> is true | ||
* | ||
* Asserts that this is a valid application of the rule if | ||
* and only if A and B are not unknown and A does not equal B | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void trueBiconditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/BiconditionalContradictionRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
trueBiconditionalTestHelper(path + first + "T" + second); | ||
} | ||
} | ||
} | ||
|
||
private void trueBiconditionalTestHelper(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); | ||
|
||
if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() != b.getType()) { | ||
Assert.assertNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A <-> B where <-> is false | ||
* | ||
* Asserts that this is a valid application of the rule if | ||
* and only if A and B are not unknown and A equals B | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void falseConditionalTest() throws InvalidFileFormatException { | ||
String path = "puzzles/shorttruthtable/rules/BiconditionalContradictionRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
falseBiconditionalTestHelper(path + first + "F" + second); | ||
} | ||
} | ||
} | ||
|
||
private void falseBiconditionalTestHelper(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); | ||
|
||
if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() == b.getType()) { | ||
Assert.assertNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} | ||
|
||
/** | ||
* Given a statement: A <-> B where <-> is unknown | ||
* | ||
* Asserts that this is not a valid application of this rule. | ||
* | ||
* @param filePath The file path for test board setup. | ||
* @throws InvalidFileFormatException | ||
*/ | ||
@Test | ||
public void unknownBiconditionalTest() throws InvalidFileFormatException { | ||
// Getting the files that have or set to unknown from Biconditional Introduction | ||
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/"; | ||
String[] letters = {"T", "F", "U"}; | ||
for (String first : letters) { | ||
for (String second : letters) { | ||
unknownBiconditionalTestHelper(path + first + "U" + second); | ||
} | ||
} | ||
} | ||
|
||
private void unknownBiconditionalTestHelper(String filePath) throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard(filePath, stt); | ||
TreeNode rootNode = stt.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard())); | ||
} | ||
} |
Oops, something went wrong.