Skip to content

Commit

Permalink
Or Elimination, Or Introduction, Not Introduction, and And Introducti…
Browse files Browse the repository at this point in the history
…on Test Cases (#689)

* Initial setup

* Working initial test

* Added another test

* Added more tests

* Added another test

* Added comments, removed useless imports, added 1 more test

* Reformatting

* Removed useless import

* Added initial and elimination test

* Comments and spacing

* Another test

* Updated comments and wrote new test

* Created two new test files

* Renamed test to be more descriptive

* Added another test

* Rewrote test to be more comprehensive

* More tests :))))

* Fixed test name and file

* Fixed test

* Fixed broken tests

* Shouldn't have touched these files

* CHECKSTYLE

* Trying to make CheckStyle happy

* Initial commit for more tests

* Finished a test

* Another test done

* More tests

* Added cannot set both at once test

* Conditional files

* Some tests done

* More tests

* Even more tests

* Fixed comments to use biconditional symbol

* Added tests for false conditional

Now tests only setting the A value and only setting the B value

* Fixed some broken biconditional files and added new ones

* Added more tests for B and fixed some descriptions

* Checkstyle fix

* Added tests for Not Elimination

One of the tests failed, but I tested that and that seems to be the case. It should be failing.

* Temporarily commenting out broken test

* Added or elimination puzzle files

* Renamed directory

These should be for Or Introduction, not Or Elimination

* Added Or Elimination files

* Added FTU and UTF tests

* More tests

* Add Or Intro tests

* Checkstyle fix

* Spacing fix

* Added not introduction test

* Added And Introduction tests and modified Or Introduction tests

---------

Co-authored-by: Ivan Ho <[email protected]>
  • Loading branch information
charlestian23 and Corppet authored Nov 28, 2023
1 parent deadd83 commit 9a61745
Show file tree
Hide file tree
Showing 29 changed files with 814 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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.DirectRuleAndIntroduction;
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 AndIntroductionDirectRuleTest {
private static final DirectRuleAndIntroduction RULE = new DirectRuleAndIntroduction();
private static ShortTruthTable stt;

@BeforeClass
public static void setup() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A ^ B
*
* Asserts that if at least 1 of A or B is false, then this is a valid application
* of the rule if and only if ^ is false.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void FalseAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
falseAndTestHelper(path + "FUF");
falseAndTestHelper(path + "FUU");
falseAndTestHelper(path + "UUF");
falseAndTestHelper(path + "FUT");
falseAndTestHelper(path + "TUF");
}

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 and = board.getCell(1, 0);

and.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(and);
Assert.assertNotNull(RULE.checkRule(transition));

and.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(and);
Assert.assertNull(RULE.checkRule(transition));
}

/**
* Given a statement: A ^ B
*
* Asserts that setting ^ to true is a valid application of the rule if
* and only if both A and B are true.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void FalseOrTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
trueAndTestHelper(path + first + "U" + 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);
ShortTruthTableCell and = board.getCell(1, 0);

and.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(and);

if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) {
Assert.assertNull(RULE.checkRule(transition));
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
122 changes: 122 additions & 0 deletions src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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.DirectRuleNotIntroduction;
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 NotIntroductionTest {
private static final DirectRuleNotIntroduction RULE = new DirectRuleNotIntroduction();
private static ShortTruthTable stt;

@BeforeClass
public static void setup() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given one statement: ¬A where A is false
*
* Asserts that this is a valid application of this rule if and only if ¬ is true
*
* @throws InvalidFileFormatException
*/
@Test
public void FalseNot() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA", 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 not = board.getCell(0, 0);
not.setData(cellType);
board.addModifiedData(not);

if (cellType == ShortTruthTableCellType.TRUE) {
Assert.assertNull(RULE.checkRule(transition));
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}
}

/**
* Given one statement: ¬A where A is true
*
* Asserts that this is a valid application of this rule if and only if ¬ is false
*
* @throws InvalidFileFormatException
*/
@Test
public void TrueNot() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA", 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 not = board.getCell(0, 0);
not.setData(cellType);
board.addModifiedData(not);

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/NotIntroductionDirectRule/BlankA", 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);

Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
}
150 changes: 150 additions & 0 deletions src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
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.DirectRuleOrElimination;
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 OrEliminationTest {
private static final DirectRuleOrElimination RULE = new DirectRuleOrElimination();
private static ShortTruthTable stt;

@BeforeClass
public static void setup() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A V B, where A is false and V is true
*
* Asserts that this is a valid application of the rule if and only if B is true.
*
* @throws InvalidFileFormatException
*/
@Test
public void FTUTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell cell = board.getCell(2, 0);

cell.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(cell);
Assert.assertNull(RULE.checkRule(transition));

cell.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(cell);
Assert.assertNotNull(RULE.checkRule(transition));
}

/**
* Given a statement: A V B, where B is false and V is true
*
* Asserts that this is a valid application of the rule if and only if B is true.
*
* @throws InvalidFileFormatException
*/
@Test
public void UTFTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell cell = board.getCell(0, 0);

cell.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(cell);
Assert.assertNull(RULE.checkRule(transition));

cell.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(cell);
Assert.assertNotNull(RULE.checkRule(transition));
}

/**
* Given a statement: A V B, where V is false
*
* Asserts that this is a valid application of the rule if and only if both A
* and B are false.
*
* @throws InvalidFileFormatException
*/
@Test
public void UFUTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU", 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 a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

a.setData(cellType1);
b.setData(cellType2);

board.addModifiedData(a);
board.addModifiedData(b);

if (cellType1 == ShortTruthTableCellType.FALSE && cellType2 == ShortTruthTableCellType.FALSE) {
Assert.assertNull(RULE.checkRule(transition));
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
}

/**
* Given a statement: A V B, where V is true
*
* Asserts that setting both A and B is not a valid application of this rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void UTUTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU", 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 a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

a.setData(cellType1);
b.setData(cellType2);

board.addModifiedData(a);
board.addModifiedData(b);

Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
}
Loading

0 comments on commit 9a61745

Please sign in to comment.