Skip to content

Commit

Permalink
Added Conditional Introduction and Biconditional Introduction tests (#…
Browse files Browse the repository at this point in the history
…693)

* Added Conditional Intro files

* Create ConditionalIntroductionTest.java

* Added Biconditional Introduction tests
  • Loading branch information
charlestian23 authored Nov 28, 2023
1 parent 9a61745 commit e858844
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 0 deletions.
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));
}
}
}
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));
}
}
}
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>
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>
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>
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>
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>
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>
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>
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>
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>
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&gt;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>
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&gt;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>
Loading

0 comments on commit e858844

Please sign in to comment.