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

Finishing Short Truth Table Contradiction Rule tests #713

Merged
merged 22 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift click to select a range
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
Prev Previous commit
Next Next commit
Added false or test
  • Loading branch information
charlestian23 committed Jan 31, 2024
commit 360495951afef98d86f4d078dbcf6a3e6f23b270
Original file line number Diff line number Diff line change
@@ -0,0 1,71 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.ContradictionRule;
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.contradiction.ContradictionRuleOr;
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 OrContradictionRuleTest {

private static final ContradictionRuleOr RULE = new ContradictionRuleOr();
private static ShortTruthTable stt;

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

/**
* Given a statement: A V B where V is false
*
* Asserts that setting is a valid application of the rule if
* A or B is set to true or both A and B are set to true.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void FalseOrTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/OrContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
falseOrTestHelper(path first "F" second);
}
}
}

private void falseOrTestHelper(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 or = board.getCell(1, 0);

or.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(or);

if (a.getType() == ShortTruthTableCellType.TRUE || b.getType() == ShortTruthTableCellType.TRUE) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
}