Skip to content

Commit

Permalink
added FinishWithGrassTest (#650)
Browse files Browse the repository at this point in the history
* October Merge (#636)

* Region Based Changes (#559)

Co-authored-by: Hanson Gu <[email protected]>

* Short Truth Table Puzzle Editor (#451)

* Created files for STT elements

* Renamed Tiles classes to Elements to match package name

Also added an elements reference sheet and renamed rules reference sheet accordingly

* More progress made

This won't compile, just saving progress made

* More progress being made

* Fixed file name typo and added placeholder tiles

* Added image paths

* Created element classes and added placeholder tile images (#452)

* Renamed Tiles classes to Elements to match package name

Also added an elements reference sheet and renamed rules reference sheet accordingly

* More progress made

This won't compile, just saving progress made

* More progress being made

* Fixed file name typo and added placeholder tiles

* Added image paths

* Set the current board on boardView

* Fixed typo and turned on STT puzzle editor for testing

* Added preliminary valid dimensions checker

This will most definitely change in the future, hopefully can change to accept a number of statements

* Fixed image file paths

* Added ActionListener

Allows us to determine what puzzle is selected by the user

* Hide rows and columns input for Short Truth Table

* Added text area for Short Truth Table

* Added scrollbars to show up as needed

* Reformatted code

* More code reformatting

* Even more reformatting

* Separate the data from the TextArea into different lines

* Did some researching/testing

Tested certain variable values with a STT file with no true/false values

* Made more progress

Added new methods to handle creating Short Truth Table boards from an array of strings

* Added a bunch of TODOs

- Implemented a couple functions to be used later
- Added a bunch of TODO comments for future work

* Made some more progress

* Implemented abstract methods from PuzzleImporter

* Added abstract methods to Fillapix and added other exception reporting

* CheckStyle formatting

* Removed a TODO comment

* Statements show up in puzzle editor

Fixed a bug where the importer was not properly being initialized. Statements now show up in the puzzle editor.

* Removed empty statements

* Changed InvalidFormatException to IllegalArgumentException

* Remove argument that has already been caught

* Removed elements that will not be used

* Added puzzle editor cell clicking functionality

* Added ability to toggle certain logical elements

* New icons and more functionality implemented

* Fixed a bug where spacer rows could be modified

* Added statement error checking

* Fixed formatting

* Only one logic symbol element needed

* Changed InputMismatchException to UnsupportedOperationException

* Renamed variables to not be STT specific

* Finding initial issue and starting fix

* Issue is statement copying and modifying

* STT exporter now working. Overrode setCell for STTBoard.

* Added code documentation

* removed testing println()

* Gradle fixes

* Revert "Merge pull request #545 from MMosley502/puzzle_editor-short_truth_table-file_saving"

This reverts commit 2e82547, reversing
changes made to beb60a2.

* Saving files now works

* Fixed the blank element to be categorized as a placeable element

* Fixed a bug where file wouldn't save due to batch grader updates

* Reformatted code in STT

* Reformatted code again

* MORE REFORMATTING

Pls like my code CheckStyle

---------

Co-authored-by: Matthew Mosley <[email protected]>
Co-authored-by: MMosley502 <[email protected]>

* Have null changes be valid and fix IsolatedBlackContradicitonRule error message (#561)

* Get Tests to be called

Revert "Create first cypress test template"

This reverts commit 3e50909.

First commit

Finish Lightup tests

* Add more tests

Update TestRunner.java

* Somehow ended up in the wrong spot

Fix Import

* Please let this be the fix

Update TreeTransition.java

Update TreeTransition.java

Update DirectRule.java

Check to see which is not correct

Update ElementController.java

Revert "maybe the null is making it think that it's not valid"

This reverts commit 7bf1de0d66ced6749ee37fbb9c252636b2fcdc79.

Just trying to change color

Revert "Just trying to change color"

This reverts commit ec44695ee578d664055d135a668927a0fd900f5d.

Revert "maybe the null is making it think that it's not valid"

This reverts commit 3f162fbdc32e6fbd23da321a14a6af96f0ff520d.

Check to see which is not correct

Revert "Check to see which is not correct"

This reverts commit 136b0a41b9d103e6f3e9a7f8cd5d970bf76b050b.

Update TreeTransition.java

Update TreeTransition.java

Revert "Update TreeTransition.java"

This reverts commit cde45bb9001cfbfa4f6e2a49b4e9990d2fa7ad33.

* Fix error with isolated Black

Fix error message with isolated black

* Removed excess whitespace and imports. Added short JavaDoc for `TestRunner.java`

---------

Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Bram van Heuveln <[email protected]>
Co-authored-by: Corppet <[email protected]>

* Fixed a bug

* Update BlackTile.java

Black tile should not be placeable

* Added unknown tile stuff

* ID error

* Some Fixes to Recently Discussed UX Bugs (#563)

* frame and panels default sizes, default pos on screen

* hardcoded version number

* homepanel default size

* set panels' own sizes

* some changes

* Removed unused import

---------

Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Corppet <[email protected]>

* Oops pushed the wrong file

Yeah some tiles work now but this is the ID error

* Number Tile working

* Update Exporter (#627)

* Update Exporter

* Delete Test_Save

---------

Co-authored-by: Charles Tian <[email protected]>

* Create run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Windows things

* Added print messages

* More Windows things

* Debugging

* Update run-tests.yml

* Update run-tests.yml

* Maybe this will work now?

* Didn't work

* Update run-tests.yml

* Update run-tests.yml

* Create DummyTest.java

For debugging purposes

* Added another dummy test

* Update run-tests.yml

* Update run-tests.yml

Get rid of all this info

* Deleted the dummy tests

---------

Co-authored-by: Antonio Orta <[email protected]>
Co-authored-by: Hanson Gu <[email protected]>
Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Matthew Mosley <[email protected]>
Co-authored-by: MMosley502 <[email protected]>
Co-authored-by: Viane Matsibekker <[email protected]>
Co-authored-by: Bram van Heuveln <[email protected]>
Co-authored-by: Corppet <[email protected]>
Co-authored-by: charlestian23 <[email protected]>
Co-authored-by: ThisMatt <[email protected]>

* fixed error on puzzle

* added some tests

* added test on empty puzzle

* fixed error on puzzle

* added test with tent in the middle

* added test where rule should not work

* added space behind bracket

* updated to be inline with dev

* added SpacedOutTentTest

added a test with the tents spread out

* added some comments to tests

* added comments to tests

* removed isolationg code

* reverted TestRunner.java

---------

Co-authored-by: Chase Grajeda <[email protected]>
Co-authored-by: Antonio Orta <[email protected]>
Co-authored-by: Hanson Gu <[email protected]>
Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Matthew Mosley <[email protected]>
Co-authored-by: MMosley502 <[email protected]>
Co-authored-by: Viane Matsibekker <[email protected]>
Co-authored-by: Bram van Heuveln <[email protected]>
Co-authored-by: Corppet <[email protected]>
Co-authored-by: charlestian23 <[email protected]>
Co-authored-by: ThisMatt <[email protected]>
  • Loading branch information
12 people authored Oct 24, 2023
1 parent 7e2b0c4 commit ab59072
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.Test;

import java.awt.*;
import java.util.List;
import java.util.ArrayList;

public class FinishWithGrassDirectRuleTest {

Expand All @@ -27,15 +29,24 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* 3x3 TreeTent puzzle with a tent at (0,0)
* Tests FinishWithGrassDirectRule on GRASS tiles horizontal of the tent
* at (1,0) and (2,0)
*
* @throws InvalidFileFormatException
*/
@Test
public void EmptyFieldTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrass", treetent);
public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
TreeTentCell cell1 = board.getCell(1, 0);
cell1.setData(TreeTentType.GRASS);
TreeTentCell cell2 = board.getCell(2, 0);
Expand All @@ -44,21 +55,316 @@ public void EmptyFieldTest() throws InvalidFileFormatException {
board.addModifiedData(cell1);
board.addModifiedData(cell2);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Point point = new Point(k, i);
if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation()) || c.getLocation().equals(cell2.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}
}

/**
* 3x3 TreeTent puzzle with a tent at (0,0)
* Tests FinishWithGrassDirectRule on GRASS tiles vertical of the tent
* at (0,1) and (0,2)
*
* @throws InvalidFileFormatException
*/
@Test
public void FinishWithGrassVerticalTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
TreeTentCell cell1 = board.getCell(0, 1);
cell1.setData(TreeTentType.GRASS);
TreeTentCell cell2 = board.getCell(0, 2);
cell2.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);
board.addModifiedData(cell2);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation()) || c.getLocation().equals(cell2.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with a tent at (0,0)
* Tests FinishWithGrassDirectRule on GRASS tiles
* at (1,0), (2,0), (0,1), and (0,2)
*
* @throws InvalidFileFormatException
*/
@Test
public void FinishWithGrassTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
TreeTentCell cell1 = board.getCell(1, 0);
cell1.setData(TreeTentType.GRASS);
TreeTentCell cell2 = board.getCell(2, 0);
cell2.setData(TreeTentType.GRASS);
TreeTentCell cell3 = board.getCell(0, 1);
cell3.setData(TreeTentType.GRASS);
TreeTentCell cell4 = board.getCell(0, 2);
cell4.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation()) ||
c.getLocation().equals(cell2.getLocation()) ||
c.getLocation().equals(cell3.getLocation()) ||
c.getLocation().equals(cell4.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with no tents
* Tests FinishWithGrassDirectRule on GRASS tiles
* GRASS tiles fill entire board
*
* @throws InvalidFileFormatException
*/
@Test
public void NoTentTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/NoTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
List<TreeTentCell> cells = new ArrayList<TreeTentCell>();
for (int i = 0; i < board.getWidth(); i++) {
for (int k = 0; k < board.getHeight(); k++) {
TreeTentCell c = board.getCell(i, k);
c.setData(TreeTentType.GRASS);
cells.add(c);
}
}

for (TreeTentCell c : cells) {
board.addModifiedData(c);
}

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// all cells should change following the rule
for (TreeTentCell c : cells) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
}
/**
* 3x3 TreeTent puzzle with a tent at (1,1)
* Tests FinishWithGrassDirectRule on GRASS tiles surrounding the tent
* at (1,0), (0,1), (2,1), and (1,2)
*
* @throws InvalidFileFormatException
*/
@Test
public void MiddleTentTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/MiddleTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
TreeTentCell cell1 = board.getCell(1, 0);
TreeTentCell cell2 = board.getCell(0, 1);
TreeTentCell cell3 = board.getCell(2, 1);
TreeTentCell cell4 = board.getCell(1, 2);

cell1.setData(TreeTentType.GRASS);
cell2.setData(TreeTentType.GRASS);
cell3.setData(TreeTentType.GRASS);
cell4.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation()) ||
c.getLocation().equals(cell2.getLocation()) ||
c.getLocation().equals(cell3.getLocation()) ||
c.getLocation().equals(cell4.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with missing tents
* Tests FinishWithGrassDirectRule on GRASS tiles filling the puzzle
* all GRASS tiles should fail the FinishWithGrassDirectRule
*
* @throws InvalidFileFormatException
*/
@Test
public void FailTentTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/FailTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells not following the FinishWithGrass rule
List<TreeTentCell> cells = new ArrayList<TreeTentCell>();
for (int i = 0; i < board.getWidth(); i++) {
for (int k = 0; k < board.getHeight(); k++) {
TreeTentCell c = board.getCell(i, k);
c.setData(TreeTentType.GRASS);
cells.add(c);
}
}

for (TreeTentCell c : cells) {
board.addModifiedData(c);
}

// confirm there is a logical following of the EmptyField rule
Assert.assertNotNull(RULE.checkRule(transition));

// all cells should fail the rule test
for (TreeTentCell c : cells) {
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
/**
* 7x7 TreeTent puzzle with multiple tents spaced out
* Tests FinishWithGrassDirectRule on GRASS tiles between the tents
* at (0,3), (2,3), (4,3), and (6,3)
*
* @throws InvalidFileFormatException
*/
@Test
public void SpacedOutTentTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/SpacedOutTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the FinishWithGrass rule
TreeTentCell cell1 = board.getCell(0, 3);
TreeTentCell cell2 = board.getCell(2, 3);
TreeTentCell cell3 = board.getCell(4, 3);
TreeTentCell cell4 = board.getCell(6, 3);

cell1.setData(TreeTentType.GRASS);
cell2.setData(TreeTentType.GRASS);
cell3.setData(TreeTentType.GRASS);
cell4.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation()) ||
c.getLocation().equals(cell2.getLocation()) ||
c.getLocation().equals(cell3.getLocation()) ||
c.getLocation().equals(cell4.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="1" value="1"/>
<clue index="2" value="0"/>
<clue index="3" value="0"/>
</axis>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="1"/>
<clue index="B" value="1"/>
<clue index="C" value="1"/>
</axis>
<axis side="south">
<clue index="1" value="1"/>
<clue index="2" value="1"/>
<clue index="3" value="1"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Loading

0 comments on commit ab59072

Please sign in to comment.