Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Short Truth Table Tests #672

Merged
merged 28 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
477dcef
Initial setup
charlestian23 Oct 13, 2023
c98c0f6
Working initial test
charlestian23 Oct 13, 2023
f037805
Added another test
charlestian23 Oct 13, 2023
918deb9
Added more tests
charlestian23 Oct 13, 2023
228698b
Added another test
charlestian23 Oct 13, 2023
79e131d
Added comments, removed useless imports, added 1 more test
charlestian23 Oct 13, 2023
c515259
Reformatting
charlestian23 Oct 13, 2023
38d25fd
Removed useless import
charlestian23 Oct 17, 2023
4cb21a0
Merge branch 'dev' into stt-test-suite
Corppet Oct 17, 2023
431ceb3
Added initial and elimination test
charlestian23 Oct 17, 2023
2fbf61e
Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG…
charlestian23 Oct 17, 2023
3581867
Comments and spacing
charlestian23 Oct 17, 2023
ecb1007
Another test
charlestian23 Oct 17, 2023
fe300f4
Updated comments and wrote new test
charlestian23 Oct 17, 2023
2785289
Created two new test files
charlestian23 Oct 17, 2023
f1f8fc4
Renamed test to be more descriptive
charlestian23 Oct 17, 2023
9fc175b
Added another test
charlestian23 Oct 17, 2023
301baeb
Rewrote test to be more comprehensive
charlestian23 Oct 17, 2023
71f87af
More tests :))))
charlestian23 Oct 17, 2023
767d968
Fixed test name and file
charlestian23 Oct 17, 2023
fbdc046
Fixed test
charlestian23 Oct 17, 2023
0c316c9
Fixed broken tests
charlestian23 Oct 17, 2023
93abdee
Merge branch 'dev' into stt-test-suite
charlestian23 Oct 17, 2023
f728447
Shouldn't have touched these files
charlestian23 Oct 17, 2023
a6096ad
Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG…
charlestian23 Oct 17, 2023
11821ce
CHECKSTYLE
charlestian23 Oct 17, 2023
8893406
Merge branch 'dev' into stt-test-suite
charlestian23 Oct 18, 2023
ca76fe6
Trying to make CheckStyle happy
charlestian23 Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
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.DirectRuleAndElimination;
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 AndEliminationDirectRuleTest {
private static final DirectRuleAndElimination RULE = new DirectRuleAndElimination();
private static ShortTruthTable stt;

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

/**
* Given one statement: B^C where ^ is true
*
* Checks all possible combinations of true, false, and unknown for B and C
* except for where both B and C are true and asserts that each one of them
* is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void trueAndTest1() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", 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) {
if (cellType1 == cellType2 && cellType1 == ShortTruthTableCellType.TRUE) {
continue;
}

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

if (cellType1 != ShortTruthTableCellType.UNKNOWN) {
bonnie.setData(cellType1);
board.addModifiedData(bonnie);
}

if (cellType2 != ShortTruthTableCellType.UNKNOWN) {
clyde.setData(cellType2);
board.addModifiedData(clyde);
}

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

/**
* Given one statement: B^C where ^ is true
*
* Checks all possible combinations of true and unknown for B and C
* except for where both B and C are unknown and asserts that each one
* of them is a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void trueAndTest2() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.UNKNOWN};

for (ShortTruthTableCellType cellType1 : cellTypes) {
for (ShortTruthTableCellType cellType2 : cellTypes) {
if (cellType1 == cellType2 && cellType1 == ShortTruthTableCellType.UNKNOWN) {
continue;
}

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

if (cellType1 != ShortTruthTableCellType.UNKNOWN) {
bonnie.setData(cellType1);
board.addModifiedData(bonnie);
}

if (cellType2 != ShortTruthTableCellType.UNKNOWN) {
clyde.setData(cellType2);
board.addModifiedData(clyde);
}

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

/**
* Given one statement: B^C where ^ is false
*
* Checks all possible combinations of true, false, and unknown for B and C
* and asserts that each one of them is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void falseAndWithUnknownsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd", 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 bonnie = board.getCell(0, 0);
ShortTruthTableCell clyde = board.getCell(2, 0);

if (cellType1 != ShortTruthTableCellType.UNKNOWN) {
bonnie.setData(cellType1);
board.addModifiedData(bonnie);
}

if (cellType2 != ShortTruthTableCellType.UNKNOWN) {
clyde.setData(cellType2);
board.addModifiedData(clyde);
}

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

/**
* Given one statement: B^C where both B and ^ are false
*
* Asserts that this is not a valid application of the rule if C is set to
* either true or false.
*
* @throws InvalidFileFormatException
*/
@Test
public void falseAndWithKnownFalseTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse", stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();

ShortTruthTableCell clyde = board.getCell(2, 0);
clyde.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(clyde);
Assert.assertNotNull(RULE.checkRule(transition));

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

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

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();

ShortTruthTableCell clyde = board.getCell(2, 0);
clyde.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(clyde);
Assert.assertNotNull(RULE.checkRule(transition));

clyde.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(clyde);
Assert.assertNull(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="B^C" row_index="0"/>
<cell char_index="1" row_index="0" type="FALSE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-17 16:17:56"/>
</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="B^C" 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-17 16:57:05"/>
</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="B^C" row_index="0"/>
<cell char_index="0" row_index="0" type="TRUE"/>
<cell char_index="1" row_index="0" type="FALSE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-17 16:57:05"/>
</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="B^C" row_index="0"/>
<cell char_index="1" row_index="0" type="TRUE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-17 16:17:56"/>
</Legup>
Loading