Skip to content

Commit

Permalink
Merge branch 'dev' into LightUp-Test-Suite-Additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase-Grajeda authored Mar 29, 2024
2 parents f376817 + 80280db commit 0200a26
Show file tree
Hide file tree
Showing 113 changed files with 2,554 additions and 85 deletions.
63 changes: 58 additions & 5 deletions .github/workflows/java-autoformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Java Code Auto Format
on: pull_request

jobs:
format:
if: github.event.pull_request.head.repo.full_name == github.repository
format_dev:
if: |
github.event.pull_request.head.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -15,7 +17,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 21
distribution: temurin

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -28,7 +29,58 @@ jobs:

- name: Check for modified files
id: git-check
run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT

- name: Create temporary branch and pull request
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Bram van Heuveln'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
branch_name="auto-format-code-$(date +%s)"
git checkout -b $branch_name
./gradlew :spotlessApply
git add .
git commit -am "Automated Java code formatting changes"
git push --set-upstream origin $branch_name
gh pr create -B dev -H $branch_name --title 'Automated Java code formatting changes' --body 'This pull request contains automated code formatting changes.' --reviewer ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Must approve auto-format pull request
if: steps.git-check.outputs.modified == 'true'
run: |
echo "Please review and approve the appropriate auto-format-code pull request."
exit 1
format_pull_request_to_dev:
if: |
github.event.pull_request.base.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}

- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Run spotless
run: ./gradlew :spotlessApply

- name: Check for modified files
id: git-check
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT

- name: Push changes
if: steps.git-check.outputs.modified == 'true'
Expand All @@ -37,4 +89,5 @@ jobs:
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
git diff --cached --exit-code || git commit -am "Automated Java code formatting changes" && git push
git commit -am "Automated Java code formatting changes"
git push
108 changes: 55 additions & 53 deletions src/main/java/edu/rpi/legup/model/gameboard/GridRegion.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
package edu.rpi.legup.model.gameboard;

import java.util.ArrayList;
import java.util.List;

public abstract class GridRegion<T> {

protected List<T> regionCells;

/**
* Region Constructor
*/
public GridRegion() {
this.regionCells = new ArrayList<>();
}

/**
* Adds the cell to the region
* @param cell cell to be added to the region
*/
public void addCell(T cell) {
regionCells.add(cell);
}

/**
* Removes the cell from the region
* @param cell cell to be remove from the region
*/
public void removeCell(T cell) {
regionCells.remove(cell);
}

/**
* Returns the list of cells in the region
* @return list of cells in region
*/
public List<T> getCells() {
return regionCells;
}

/**
* Returns the number of cells in the region
* @return number of cells in the region
*/
public int getSize(){
return regionCells.size();
}

/*
public void colorRegion(){}
*/

}
package edu.rpi.legup.model.gameboard;

import java.util.ArrayList;
import java.util.List;

public abstract class GridRegion<T> {

protected List<T> regionCells;

/** Region Constructor */
public GridRegion() {
this.regionCells = new ArrayList<>();
}

/**
* Adds the cell to the region
*
* @param cell cell to be added to the region
*/
public void addCell(T cell) {
regionCells.add(cell);
}

/**
* Removes the cell from the region
*
* @param cell cell to be remove from the region
*/
public void removeCell(T cell) {
regionCells.remove(cell);
}

/**
* Returns the list of cells in the region
*
* @return list of cells in region
*/
public List<T> getCells() {
return regionCells;
}

/**
* Returns the number of cells in the region
*
* @return number of cells in the region
*/
public int getSize() {
return regionCells.size();
}

/*
public void colorRegion(){}
*/

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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.contradiction.ContradictionRuleAnd;
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 AndContradictionRuleTest {

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

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

/**
* Given a statement: A ^ B where ^ is true
*
* <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
*/
@Test
public void trueAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
trueAndTestHelper(path + first + "T" + second);
}
}
}

private void trueAndTestHelper(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);

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

/**
* Given a statement: A ^ B where ^ is false
*
* <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
*/
@Test
public void falseAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
falseAndTestHelper(path + first + "F" + second);
}
}
}

private void falseAndTestHelper(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);

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

/**
* Given a statement: A ^ B where ^ is unknown
*
* <p>Asserts that this is not a valid application of this rule.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void unknownAndTest() throws InvalidFileFormatException {
// Getting the files that have or set to unknown from And Introduction
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
unknownAndTestHelper(path + first + "U" + second);
}
}
}

private void unknownAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
Loading

0 comments on commit 0200a26

Please sign in to comment.