-
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.
Added Conditional Introduction and Biconditional Introduction tests (#…
…693) * Added Conditional Intro files * Create ConditionalIntroductionTest.java * Added Biconditional Introduction tests
- Loading branch information
1 parent
9a61745
commit e858844
Showing
20 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
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)); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUF
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="2" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUT
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="2" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
13 changes: 13 additions & 0 deletions
13
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUU
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="0" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUF
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="TRUE"/> | ||
<cell char_index="2" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUT
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="TRUE"/> | ||
<cell char_index="2" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
13 changes: 13 additions & 0 deletions
13
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUU
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="0" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
13 changes: 13 additions & 0 deletions
13
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUF
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="2" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
13 changes: 13 additions & 0 deletions
13
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUT
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="2" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
12 changes: 12 additions & 0 deletions
12
src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUU
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,12 @@ | ||
<?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"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-21 00:25:37"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUF
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="2" row_index="0" type="FALSE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
14 changes: 14 additions & 0 deletions
14
src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUT
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="2" row_index="0" type="TRUE"/> | ||
</data> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="2023-11-20 13:40:20"/> | ||
</Legup> |
Oops, something went wrong.