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

Automated Java code formatting changes #783

Merged
merged 3 commits into from
Mar 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void setUp() {
/**
* Given a statement: A ^ B where ^ is true
*
* Asserts that this is a valid application of the rule if
* and only if A or B are set to false.
* <p>Asserts that this is a valid application of the rule if and only if A or B are set to
* false.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand All @@ -55,19 +55,19 @@ private void trueAndTestHelper(String filePath) throws InvalidFileFormatExceptio
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

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

/**
* Given a statement: A ^ B where ^ is false
*
* Asserts that this is a valid application of the rule if
* and only if A or B (or both) are set to true.
* <p>Asserts that this is a valid application of the rule if and only if A or B (or both) are
* set to true.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand All @@ -93,18 +93,18 @@ private void falseAndTestHelper(String filePath) throws InvalidFileFormatExcepti
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

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

/**
* Given a statement: A ^ B where ^ is unknown
*
* Asserts that this is not a valid application of this rule.
* <p>Asserts that this is not a valid application of this rule.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void setUp() {
/**
* Given two statements: A, A
*
* Asserts that this is a valid application of the rule if
* and only if both A and B are not unknown and different.
* <p>Asserts that this is a valid application of the rule if and only if both A and B are not
* unknown and different.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand All @@ -55,10 +55,11 @@ private void mismatchHelper(String filePath) throws InvalidFileFormatException {
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(0, 2);

if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() != b.getType()) {
if (a.getType() != ShortTruthTableCellType.UNKNOWN
&& b.getType() != ShortTruthTableCellType.UNKNOWN
&& a.getType() != b.getType()) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
} else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.caserule.CaseRuleBiconditional;
import edu.rpi.legup.save.InvalidFileFormatException;
import java.util.ArrayList;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;

public class BiconditionalCaseRuleTest {

private static final CaseRuleBiconditional RULE = new CaseRuleBiconditional();
Expand All @@ -28,11 +27,11 @@ public static void setUp() {
stt = new ShortTruthTable();
}

private void trueBiconditionalTest(String fileName,
int biconditionalX, int biconditionalY,
int aX, int aY,
int bX, int bY) throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt);
private void trueBiconditionalTest(
String fileName, int biconditionalX, int biconditionalY, int aX, int aY, int bX, int bY)
throws InvalidFileFormatException {
TestUtilities.importTestBoard(
"puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand Down Expand Up @@ -63,54 +62,57 @@ private void trueBiconditionalTest(String fileName,
// Assert that A and B are equal and either true or false in both branches
Assert.assertEquals(board1A, board1B);
Assert.assertTrue(
(board1A.equals(ShortTruthTableCellType.TRUE) && board1B.equals(ShortTruthTableCellType.TRUE)) || (board1A.equals(ShortTruthTableCellType.FALSE) && board1B.equals(ShortTruthTableCellType.FALSE))
);
(board1A.equals(ShortTruthTableCellType.TRUE)
&& board1B.equals(ShortTruthTableCellType.TRUE))
|| (board1A.equals(ShortTruthTableCellType.FALSE)
&& board1B.equals(ShortTruthTableCellType.FALSE)));

Assert.assertNotEquals(board1B, board2B);
Assert.assertTrue(
(board2A.equals(ShortTruthTableCellType.TRUE) && board2B.equals(ShortTruthTableCellType.TRUE)) || (board2A.equals(ShortTruthTableCellType.FALSE) && board2B.equals(ShortTruthTableCellType.FALSE))
);
(board2A.equals(ShortTruthTableCellType.TRUE)
&& board2B.equals(ShortTruthTableCellType.TRUE))
|| (board2A.equals(ShortTruthTableCellType.FALSE)
&& board2B.equals(ShortTruthTableCellType.FALSE)));

// Verify the board dimensions are unchanged
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight());
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth());

// Verify that everywhere else on the board is unchanged
for (int i = 0; i< caseBoard1.getWidth(); i++) {
for (int i = 0; i < caseBoard1.getWidth(); i++) {
for (int j = 0; j < caseBoard1.getHeight(); j++) {
// Make sure not to check the two cells that should be different
if (!((i == aX && j == aY) || (i == bX && j == bY))) {
Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType());
Assert.assertEquals(
caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType());
}
}
}
}

/**
* Given a statement A -> B where ^ is true, tests this case rule by ensuring that
* two branches are created: one where A is false and one where B is true.
* Given a statement A -> B where ^ is true, tests this case rule by ensuring that two branches
* are created: one where A is false and one where B is true.
*/
@Test
public void SimpleStatement1TrueTest() throws InvalidFileFormatException {
trueBiconditionalTest("TrueBiconditional", 1, 0, 0, 0, 2, 0);
}

/**
* Given a statement ~(A|B) -> (C^D) where the -> is true, tests this case rule
* by ensuring that two branches are created: one where ~ is false and one where
* ^ is true.
* Given a statement ~(A|B) -> (C^D) where the -> is true, tests this case rule by ensuring that
* two branches are created: one where ~ is false and one where ^ is true.
*/
@Test
public void ComplexStatement1TrueTest() throws InvalidFileFormatException {
trueBiconditionalTest("ComplexStatement1_True", 6, 0, 0, 0,
9, 0);
trueBiconditionalTest("ComplexStatement1_True", 6, 0, 0, 0, 9, 0);
}

private void falseBiconditionalTest(String fileName,
int biconditionalX, int biconditionalY,
int aX, int aY,
int bX, int bY) throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt);
private void falseBiconditionalTest(
String fileName, int biconditionalX, int biconditionalY, int aX, int aY, int bX, int bY)
throws InvalidFileFormatException {
TestUtilities.importTestBoard(
"puzzles/shorttruthtable/rules/BiconditionalCaseRule/" + fileName, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand Down Expand Up @@ -141,46 +143,49 @@ private void falseBiconditionalTest(String fileName,
// Assert that A and B are not equal and are both either true or false in both branches
Assert.assertNotEquals(board1A, board1B);
Assert.assertTrue(
(board1A.equals(ShortTruthTableCellType.TRUE) && board1B.equals(ShortTruthTableCellType.FALSE)) || (board1A.equals(ShortTruthTableCellType.FALSE) && board1B.equals(ShortTruthTableCellType.TRUE))
);
(board1A.equals(ShortTruthTableCellType.TRUE)
&& board1B.equals(ShortTruthTableCellType.FALSE))
|| (board1A.equals(ShortTruthTableCellType.FALSE)
&& board1B.equals(ShortTruthTableCellType.TRUE)));

Assert.assertNotEquals(board2A, board2B);
Assert.assertTrue(
(board2A.equals(ShortTruthTableCellType.TRUE) && board2B.equals(ShortTruthTableCellType.FALSE)) || (board2A.equals(ShortTruthTableCellType.FALSE) && board2B.equals(ShortTruthTableCellType.TRUE))
);
(board2A.equals(ShortTruthTableCellType.TRUE)
&& board2B.equals(ShortTruthTableCellType.FALSE))
|| (board2A.equals(ShortTruthTableCellType.FALSE)
&& board2B.equals(ShortTruthTableCellType.TRUE)));

// Verify the board dimensions are unchanged
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight());
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth());

// Verify that everywhere else on the board is unchanged
for (int i = 0; i< caseBoard1.getWidth(); i++) {
for (int i = 0; i < caseBoard1.getWidth(); i++) {
for (int j = 0; j < caseBoard1.getHeight(); j++) {
// Make sure not to check the two cells that should be different
if (!((i == aX && j == aY) || (i == bX && j == bY))) {
Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType());
Assert.assertEquals(
caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType());
}
}
}
}

/**
* Given a statement A -> B where -> is false, tests this case rule by ensuring that
* one branch is created where A is true and B is false.
* Given a statement A -> B where -> is false, tests this case rule by ensuring that one branch
* is created where A is true and B is false.
*/
@Test
public void SimpleStatement1FalseTest() throws InvalidFileFormatException {
falseBiconditionalTest("FalseBiconditional", 1, 0, 0, 0,
2, 0);
falseBiconditionalTest("FalseBiconditional", 1, 0, 0, 0, 2, 0);
}

/**
* Given a statement ~(A|B) -> (C^D) where -> is true, tests this case rule
* by ensuring that one branch is created where ~ is true and ^ is false.
* Given a statement ~(A|B) -> (C^D) where -> is true, tests this case rule by ensuring that one
* branch is created where ~ is true and ^ is false.
*/
@Test
public void ComplexStatement1FalseTest() throws InvalidFileFormatException {
falseBiconditionalTest("ComplexStatement1_False", 6, 0, 0, 0,
9, 0);
falseBiconditionalTest("ComplexStatement1_False", 6, 0, 0, 0, 9, 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void setUp() {
/**
* Given a statement: A <-> B where <-> is true
*
* Asserts that this is a valid application of the rule if
* and only if A and B are not unknown and A does not equal B
* <p>Asserts that this is a valid application of the rule if and only if A and B are not
* unknown and A does not equal B
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand All @@ -55,19 +55,20 @@ private void trueBiconditionalTestHelper(String filePath) throws InvalidFileForm
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

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

/**
* Given a statement: A <-> B where <-> is false
*
* Asserts that this is a valid application of the rule if
* and only if A and B are not unknown and A equals B
* <p>Asserts that this is a valid application of the rule if and only if A and B are not
* unknown and A equals B
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand All @@ -93,18 +94,19 @@ private void falseBiconditionalTestHelper(String filePath) throws InvalidFileFor
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

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

/**
* Given a statement: A <-> B where <-> is unknown
*
* Asserts that this is not a valid application of this rule.
* <p>Asserts that this is not a valid application of this rule.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
Expand Down
Loading