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

Atomic Direct Rule Test #651

Merged
merged 9 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
188 changes: 188 additions & 0 deletions src/test/java/puzzles/shorttruthtable/rules/AtomicDirectRuleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
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.DirectRuleAtomic;
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 AtomicDirectRuleTest {
private static final DirectRuleAtomic RULE = new DirectRuleAtomic();
private static ShortTruthTable stt;

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

/**
* Given two statements:
* A
* A
* where the first A is set to false.
*
* This test sets the second A to false and then asserts that this
* is a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void MatchingFalseTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/FalseA", 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, 2);
cell.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(cell);

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

/**
* Given two statements:
* A
* A
* where the first A is set to false.
*
* This test sets the second A to true and then asserts that this
* is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void MismatchingFalseTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/FalseA", 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, 2);
cell.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(cell);

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

/**
* Given two statements:
* B
* B
* where the first B is set to true.
*
* This test sets the second B to true and then asserts that this
* is a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void MatchingTrueTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/TrueB", 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, 2);
cell.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(cell);

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

/**
* Given two statements:
* B
* B
* where the first B is set to true.
*
* This test sets the second B to false and then asserts that this
* is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void MismatchingTrueTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/TrueB", 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, 2);
cell.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(cell);

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

/**
* Given two statements:
* C
* C
* where neither statement is set to anything.
*
* This test sets the second C to false and then asserts that this
* is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void NothingPreviouslyMarkedTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/Empty", 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, 2);
cell.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(cell);

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

/**
* Given two statements:
* C
* C
* where neither statement is set to anything.
*
* This test sets the second C to true and then asserts that this
* is not a valid application of the rule.
*
* @throws InvalidFileFormatException
*/
@Test
public void NothingPreviouslyMarkedTest2() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AtomicDirectRule/Empty", 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, 2);
cell.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(cell);

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

This file was deleted.

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="C" row_index="0"/>
<statement representation="C" row_index="1"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-13 16:47:40"/>
</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" row_index="0"/>
<statement representation="A" row_index="1"/>
<cell char_index="0" row_index="0" type="FALSE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-13 16:47:40"/>
</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" row_index="0"/>
<statement representation="B" row_index="1"/>
<cell char_index="0" row_index="0" type="TRUE"/>
</data>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2023-10-13 16:47:40"/>
</Legup>
Loading