Skip to content

Commit

Permalink
Merge branch 'dev' into stoopidj
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored Nov 7, 2023
2 parents e2354d9 + 3ea1346 commit 9d38482
Show file tree
Hide file tree
Showing 21 changed files with 974 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
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.DirectRuleConditionalElimination;
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 ConditionalEliminationTest {
private static final DirectRuleConditionalElimination RULE = new DirectRuleConditionalElimination();
private static ShortTruthTable stt;

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

/**
* Given one statement: A -> B where -> is false
*
* Asserts that the only valid combination of A and B that is a valid application
* of this rule is when A is true and B is false
*
* @throws InvalidFileFormatException
*/
@Test
public void FalseConditionalTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", 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 aubergine = board.getCell(0, 0);
ShortTruthTableCell boniato = board.getCell(2, 0);

aubergine.setData(cellType1);
boniato.setData(cellType2);

board.addModifiedData(aubergine);
board.addModifiedData(boniato);

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

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

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

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

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

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

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

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

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

/**
* Given one statement: A -> B where -> is true
*
* Asserts that you cannot set any combination of both A and B at the same time.
*
* @throws InvalidFileFormatException
*/
@Test
public void CannotSetBothAandBTrueConditionalTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional", 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 aubergine = board.getCell(0, 0);
ShortTruthTableCell boniato = board.getCell(2, 0);

aubergine.setData(cellType1);
boniato.setData(cellType2);

board.addModifiedData(aubergine);
board.addModifiedData(boniato);

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

/**
* Given one statement: A -> B where A and -> are true
*
* Asserts that this is a valid application of this rule if and only if B
* is set to true.
*
* @throws InvalidFileFormatException
*/
@Test
public void TrueAMeansTrueBTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

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

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

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

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

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

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

/**
* Given one statement: A -> B where B and -> are true
*
* Asserts that this is not a valid application of this rule no matter what
* A is set to.
*
* @throws InvalidFileFormatException
*/
@Test
public void TrueBCannotDetermineA() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

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

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

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

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

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

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

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/NotEliminationDirectRule/BlankNot", 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);
//
// System.out.println("TYPE1:" + cellType1);
// System.out.println("TYPE2:" + cellType2);
// Assert.assertNotNull(RULE.checkRule(transition));
// }
// }
// }
}
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="1" row_index="0" type="FALSE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-24 16:44:53"/>
</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="1" row_index="0" type="FALSE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-24 16:57:00"/>
</Legup>
Loading

0 comments on commit 9d38482

Please sign in to comment.