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

Added more Short Truth Table tests #675

Merged
merged 51 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
e1b6aa4
Initial commit for more tests
charlestian23 Oct 24, 2023
c6ca5a1
Finished a test
charlestian23 Oct 24, 2023
1f5f426
Another test done
charlestian23 Oct 24, 2023
db43460
More tests
charlestian23 Oct 24, 2023
cb016f2
Added cannot set both at once test
charlestian23 Oct 27, 2023
1e8ee41
Conditional files
charlestian23 Oct 27, 2023
e8ce29f
Some tests done
charlestian23 Oct 27, 2023
fe2d1cb
More tests
charlestian23 Oct 27, 2023
2ea712e
Even more tests
charlestian23 Oct 27, 2023
d4f9715
Merge branch 'dev' into stt-test-suite
charlestian23 Oct 27, 2023
be30a30
Fixed comments to use biconditional symbol
charlestian23 Oct 27, 2023
8fccf2c
Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG…
charlestian23 Oct 27, 2023
305ebb6
Merge branch 'dev' into stt-test-suite
charlestian23 Oct 27, 2023
36556a8
Added tests for false conditional
charlestian23 Nov 3, 2023
16184e0
Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG…
charlestian23 Nov 3, 2023
37b401f
Fixed some broken biconditional files and added new ones
charlestian23 Nov 3, 2023
c4cf03b
Added more tests for B and fixed some descriptions
charlestian23 Nov 3, 2023
ceee626
Merge branch 'dev' into stt-test-suite
charlestian23 Nov 3, 2023
22a60ba
Checkstyle fix
charlestian23 Nov 7, 2023
042bf9d
Merge branch 'dev' into stt-test-suite
charlestian23 Nov 7, 2023
d38f8db
Added tests for Not Elimination
charlestian23 Nov 7, 2023
b24845a
Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG…
charlestian23 Nov 7, 2023
b2b00ec
Temporarily commenting out broken test
charlestian23 Nov 7, 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

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
Loading