diff --git a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java index d1ca68d47..76367ace5 100644 --- a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java @@ -1,216 +1,216 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.puzzle.starbattle.rules.BlackoutDirectRule; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class BlackoutDirectRuleTest { -// private static final BlackoutDirectRule RULE = new BlackoutDirectRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// /* Blackout Direct Rule where star is in the corner */ -// @Test -// public void BlackoutDirectRuleTestCorner() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Corner", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(3,0); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(0,1); -// cell4.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell5 = board.getCell(1,1); -// cell5.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell6 = board.getCell(0,2); -// cell6.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell7 = board.getCell(0,3); -// cell7.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// board.addModifiedData(cell5); -// board.addModifiedData(cell6); -// board.addModifiedData(cell7); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || -// point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || -// point.equals(cell7.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /* Blackout Direct Rule where star is on the edge */ -// @Test -// public void BlackoutDirectRuleTestEdge() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Edge", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(3,0); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(0,1); -// cell4.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell5 = board.getCell(1,1); -// cell5.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell6 = board.getCell(1,2); -// cell6.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell7 = board.getCell(1,3); -// cell7.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// board.addModifiedData(cell5); -// board.addModifiedData(cell6); -// board.addModifiedData(cell7); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || -// point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || -// point.equals(cell7.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Blackout Direct Rule where star is on the edge */ -// @Test -// public void BlackoutDirectRuleTestMiddle() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(1,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(0,1); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(2,1); -// cell4.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell5 = board.getCell(3,1); -// cell5.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell6 = board.getCell(1,2); -// cell6.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell7 = board.getCell(1,3); -// cell7.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// board.addModifiedData(cell5); -// board.addModifiedData(cell6); -// board.addModifiedData(cell7); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || -// point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || -// point.equals(cell7.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /* Blackout Direct Rule where rule is called incorrectly */ -// @Test -// public void BlackoutDirectRuleTestFalse() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,2); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,3); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(3,2); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(3,3); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.puzzle.starbattle.rules.BlackoutDirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class BlackoutDirectRuleTest { + private static final BlackoutDirectRule RULE = new BlackoutDirectRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + /* Blackout Direct Rule where star is in the corner */ + @Test + public void BlackoutDirectRuleTestCorner() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Corner", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(3,0); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(0,1); + cell4.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell5 = board.getCell(1,1); + cell5.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell6 = board.getCell(0,2); + cell6.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell7 = board.getCell(0,3); + cell7.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + board.addModifiedData(cell5); + board.addModifiedData(cell6); + board.addModifiedData(cell7); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || + point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || + point.equals(cell7.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /* Blackout Direct Rule where star is on the edge */ + @Test + public void BlackoutDirectRuleTestEdge() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Edge", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(3,0); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(0,1); + cell4.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell5 = board.getCell(1,1); + cell5.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell6 = board.getCell(1,2); + cell6.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell7 = board.getCell(1,3); + cell7.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + board.addModifiedData(cell5); + board.addModifiedData(cell6); + board.addModifiedData(cell7); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || + point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || + point.equals(cell7.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Blackout Direct Rule where star is on the edge */ + @Test + public void BlackoutDirectRuleTestMiddle() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(1,0); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(0,1); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(2,1); + cell4.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell5 = board.getCell(3,1); + cell5.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell6 = board.getCell(1,2); + cell6.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell7 = board.getCell(1,3); + cell7.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + board.addModifiedData(cell5); + board.addModifiedData(cell6); + board.addModifiedData(cell7); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || + point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || + point.equals(cell7.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /* Blackout Direct Rule where rule is called incorrectly */ + @Test + public void BlackoutDirectRuleTestFalse() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,2); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,3); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(3,2); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(3,3); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + + +} diff --git a/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java b/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java index 193177138..ae8aaa08e 100644 --- a/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java @@ -1,137 +1,137 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.puzzle.starbattle.rules.ClashingOrbitContradictionRule; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class ClashingOrbitContradictionRuleTest { -// -// private static final ClashingOrbitContradictionRule RULE = new ClashingOrbitContradictionRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// /*Tests the Clashing Orbit contradiction rule for directly adjacent stars not at the -// edge of the board */ -// @Test -// public void ClashingOrbitContradictionRule_DirectlyAdjacentCenter() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DirectlyAdjacentCenter", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// StarBattleCell cell2 = board.getCell(2,1); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Tests the Clashing Orbit contradiction rule for diagonally adjacent stars */ -// @Test -// public void ClashingOrbitContradictionRule_DiagonallyAdjacent() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DiagonallyAdjacent", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// StarBattleCell cell2 = board.getCell(2,2); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /*Tests the Clashing Orbit contradiction rule for stars at the edge of the board */ -// @Test -// public void ClashingOrbitContradictionRule_DirectlyAdjacentEdge() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DirectlyAdjacentEdge", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(1,0); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /*Tests the Clashing Orbit contradiction rule for a false contradiction. */ -// @Test -// public void ClashingOrbitContradictionRule_FalseContradiction() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/FalseContradiction", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// -// Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.puzzle.starbattle.rules.ClashingOrbitContradictionRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ClashingOrbitContradictionRuleTest { + + private static final ClashingOrbitContradictionRule RULE = new ClashingOrbitContradictionRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + /*Tests the Clashing Orbit contradiction rule for directly adjacent stars not at the + edge of the board */ + @Test + public void ClashingOrbitContradictionRule_DirectlyAdjacentCenter() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DirectlyAdjacentCenter", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + StarBattleCell cell2 = board.getCell(2,1); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Tests the Clashing Orbit contradiction rule for diagonally adjacent stars */ + @Test + public void ClashingOrbitContradictionRule_DiagonallyAdjacent() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DiagonallyAdjacent", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + StarBattleCell cell2 = board.getCell(2,2); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /*Tests the Clashing Orbit contradiction rule for stars at the edge of the board */ + @Test + public void ClashingOrbitContradictionRule_DirectlyAdjacentEdge() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/DirectlyAdjacentEdge", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(1,0); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /*Tests the Clashing Orbit contradiction rule for a false contradiction. */ + @Test + public void ClashingOrbitContradictionRule_FalseContradiction() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ClashingOrbitContradictionRule/FalseContradiction", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } +} diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java index 3a11c6606..185d31f5c 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java @@ -1,324 +1,324 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.ColumnsWithinRegionsDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import java.awt.*; -// -//public class ColumnsWithinRegionsDirectRuleTest { -// -// private static final ColumnsWithinRegionsDirectRule RULE = new ColumnsWithinRegionsDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_OneColumnOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(1,0); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1, 0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_PartialColumnOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(1,2); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1, 2); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_PartialColumnTwoCells() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnTwoCells", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(0, 1); -// Point location2 = new Point(2,1); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_TwoColumns() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumns", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,2); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(2, 1); -// Point location2 = new Point(2,2); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// /* Wrote this to figure out the specifics of how the rule is functioning - might change -// * what the expected result is. */ -// @Test -// public void ColumnsWithinRegionsDirectRule_TwoColumnsWaitAMinute() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumns", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(2, 1); -// 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(location1)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_TwoColumnsStarOverlap() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumnsStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,3); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(2, 3); -// 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(location1)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions1() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(0,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(1, 0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions2() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(1, 0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_PartialRemoval() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnTwoCells", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(0, 1); -// 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(location1)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions4() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/FalseStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,2); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,3); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); i++) { -// for (int k = 0; k < board.getWidth(); k++) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.ColumnsWithinRegionsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class ColumnsWithinRegionsDirectRuleTest { + + private static final ColumnsWithinRegionsDirectRule RULE = new ColumnsWithinRegionsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void ColumnsWithinRegionsDirectRule_OneColumnOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1, 0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_PartialColumnOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1, 2); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_PartialColumnTwoCells() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0, 1); + Point location2 = new Point(2,1); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_TwoColumns() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumns", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(2, 1); + Point location2 = new Point(2,2); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /* Wrote this to figure out the specifics of how the rule is functioning - might change + * what the expected result is. */ + @Test + public void ColumnsWithinRegionsDirectRule_TwoColumnsWaitAMinute() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumns", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(2, 1); + 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(location1)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_TwoColumnsStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumnsStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,3); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(2, 3); + 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(location1)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(0,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(1, 0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(1, 0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_PartialRemoval() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0, 1); + 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(location1)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions4() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,2); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java index 80f15f0f8..8f9c938cb 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java @@ -1,244 +1,244 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.ColumnsWithinRowsDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import java.awt.*; -// -//public class ColumnsWithinRowsDirectRuleTest { -// -// private static final ColumnsWithinRowsDirectRule RULE = new ColumnsWithinRowsDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_OneColumn() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(1, 0); -// Point location2 = new Point(2,0); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_TwoColumns() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/TwoColumns", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(2, 1); -// Point location2 = new Point(2,0); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_NonAdjacentColumns() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/NonAdjacentColumns", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,2); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(1, 0); -// Point location2 = new Point(1,2); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_TwoColumnsStarOverlap() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/TwoColumnsStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(3,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(2, 1); -// Point location2 = new Point(3,0); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows1() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// StarBattleCell cell3 = board.getCell(1,1); -// cell3.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell3); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(1, 0); -// Point location2 = new Point(2,0); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_PartialCover() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1,0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows3() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/FalseStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); i++) { -// for (int k = 0; k < board.getWidth(); k++) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.ColumnsWithinRowsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class ColumnsWithinRowsDirectRuleTest { + + private static final ColumnsWithinRowsDirectRule RULE = new ColumnsWithinRowsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void ColumnsWithinRowsDirectRule_OneColumn() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1, 0); + Point location2 = new Point(2,0); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_TwoColumns() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/TwoColumns", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(2, 1); + Point location2 = new Point(2,0); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_NonAdjacentColumns() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/NonAdjacentColumns", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1, 0); + Point location2 = new Point(1,2); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_TwoColumnsStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/TwoColumnsStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(3,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(2, 1); + Point location2 = new Point(3,0); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + StarBattleCell cell3 = board.getCell(1,1); + cell3.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell3); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location1 = new Point(1, 0); + Point location2 = new Point(2,0); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_PartialCover() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1,0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows3() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java index 5ab05c86b..c81c74657 100644 --- a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java @@ -1,177 +1,177 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.EmptyAdjacentDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class EmptyAdjacentDirectRuleTest { -// -// private static final EmptyAdjacentDirectRule RULE = new EmptyAdjacentDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void EmptyAdjacentDirectRule_OneLeft() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/OneLeft", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(3,1); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(1,3); -// cell4.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell5 = board.getCell(2,3); -// cell5.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell6 = board.getCell(3,3); -// cell6.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// board.addModifiedData(cell5); -// board.addModifiedData(cell6); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || -// point.equals(cell5.getLocation()) || point.equals(cell6.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// @Test -// public void EmptyAdjacentDirectRule_TwoLeft() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/TwoLeft", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// /* -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(1,3); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(2,3); -// cell4.setData(StarBattleCellType.BLACK.value); -// */ -// -// board.addModifiedData(cell1); -// /* -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// */ -// -// Assert.assertNull(RULE.checkRule(transition)); -// System.out.println("General Case is done\n"); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } /* -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } */ -// } -// } -// } -// -// @Test -// public void EmptyAdjacentDirectRule_ThreeLeft() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/TwoLeft", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// @Test -// public void EmptyAdjacentDirectRule_ImproperUseFourLeft() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/ImproperUseFourLeft", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell3 = board.getCell(1,3); -// cell3.setData(StarBattleCellType.BLACK.value); -// StarBattleCell cell4 = board.getCell(2,3); -// cell4.setData(StarBattleCellType.BLACK.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// board.addModifiedData(cell3); -// board.addModifiedData(cell4); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.EmptyAdjacentDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class EmptyAdjacentDirectRuleTest { + + private static final EmptyAdjacentDirectRule RULE = new EmptyAdjacentDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void EmptyAdjacentDirectRule_OneLeft() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/OneLeft", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(3,1); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(1,3); + cell4.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell5 = board.getCell(2,3); + cell5.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell6 = board.getCell(3,3); + cell6.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + board.addModifiedData(cell5); + board.addModifiedData(cell6); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) || + point.equals(cell5.getLocation()) || point.equals(cell6.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + @Test + public void EmptyAdjacentDirectRule_TwoLeft() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/TwoLeft", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + /* + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(1,3); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(2,3); + cell4.setData(StarBattleCellType.BLACK.value); + */ + + board.addModifiedData(cell1); + /* + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + */ + + Assert.assertNull(RULE.checkRule(transition)); + System.out.println("General Case is done\n"); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } /* + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } */ + } + } + } + + @Test + public void EmptyAdjacentDirectRule_ThreeLeft() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/TwoLeft", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + @Test + public void EmptyAdjacentDirectRule_ImproperUseFourLeft() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/EmptyAdjacentDirectRule/ImproperUseFourLeft", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(1,3); + cell3.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell4 = board.getCell(2,3); + cell4.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + board.addModifiedData(cell4); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } +} diff --git a/src/test/java/puzzles/starbattle/rules/FinishWithStarsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/FinishWithStarsDirectRuleTest.java index c8c125d64..552e3703e 100644 --- a/src/test/java/puzzles/starbattle/rules/FinishWithStarsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/FinishWithStarsDirectRuleTest.java @@ -1,209 +1,209 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.puzzle.starbattle.rules.FinishWithStarsDirectRule; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class FinishWithStarsDirectRuleTest { -// private static final FinishWithStarsDirectRule RULE = new FinishWithStarsDirectRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// /* Finish With Stars Direct Rule where star is in the corner and only the row is blacked out */ -// @Test -// public void FinishWithStarsDirectRuleTestCornerRow() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerRow", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// cell1.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ -// @Test -// public void FinishWithStarsDirectRuleTestCornerColumn() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerColumn", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// cell1.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ -// @Test -// public void FinishWithStarsDirectRuleTestCornerRowColumn() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerRowColumn", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// cell1.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ -// @Test -// public void FinishWithStarsDirectRuleTestRegion() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/Region", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /* Finish With Stars Direct Rule where there are two stars in two different mostly blacked out regions */ -// @Test -// public void FinishWithStarsDirectRuleTestDoubleRegion() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/DoubleRegion", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.STAR.value); -// StarBattleCell cell2 = board.getCell(2,3); -// cell2.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Finish With Stars Direct Rule where there are two stars in two different mostly blacked out regions */ -// @Test -// public void FinishWithStarsDirectRuleTestFalse() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/False", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,0); -// cell1.setData(StarBattleCellType.STAR.value); -// -// board.addModifiedData(cell1); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.puzzle.starbattle.rules.FinishWithStarsDirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class FinishWithStarsDirectRuleTest { + private static final FinishWithStarsDirectRule RULE = new FinishWithStarsDirectRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + /* Finish With Stars Direct Rule where star is in the corner and only the row is blacked out */ + @Test + public void FinishWithStarsDirectRuleTestCornerRow() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerRow", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + cell1.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ + @Test + public void FinishWithStarsDirectRuleTestCornerColumn() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerColumn", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + cell1.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ + @Test + public void FinishWithStarsDirectRuleTestCornerRowColumn() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/CornerRowColumn", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + cell1.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /* Finish With Stars Direct Rule where star is in the corner and only the column is blacked out */ + @Test + public void FinishWithStarsDirectRuleTestRegion() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/Region", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /* Finish With Stars Direct Rule where there are two stars in two different mostly blacked out regions */ + @Test + public void FinishWithStarsDirectRuleTestDoubleRegion() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/DoubleRegion", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.STAR.value); + StarBattleCell cell2 = board.getCell(2,3); + cell2.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Finish With Stars Direct Rule where there are two stars in two different mostly blacked out regions */ + @Test + public void FinishWithStarsDirectRuleTestFalse() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/FinishWithStarsDirectRule/False", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,0); + cell1.setData(StarBattleCellType.STAR.value); + + board.addModifiedData(cell1); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java index a46e5514c..a45f7455f 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java @@ -1,353 +1,353 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinColumnsDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import java.awt.*; -// -//public class RegionsWithinColumnsDirectRuleTest { -// -// private static final RegionsWithinColumnsDirectRule RULE = new RegionsWithinColumnsDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_OneRegionOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,2); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(0,2); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_OneRegionTwoCells() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(0,2); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(0,1); -// Point location2 = new Point(0,2); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_PartialRegionOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,2); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(0,2); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_TwoRegionsOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(1,3); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1,3); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,3); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(1,1); -// Point location2 = new Point(1,3); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells2() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,3); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,3); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(0,3); -// Point location2 = new Point(1,3); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_TwoRegionsStarOverlap() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(1,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1,1); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns1() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,2); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// StarBattleCell cell2 = board.getCell(1,2); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(0,2); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns2() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,2); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// StarBattleCell cell2 = board.getCell(0,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(0,2); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns3() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(1,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// StarBattleCell cell2 = board.getCell(1,3); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); i++) { -// for (int k = 0; k < board.getWidth(); k++) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// -// @Test -// public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns4() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,3); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(0,3); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinColumnsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class RegionsWithinColumnsDirectRuleTest { + + private static final RegionsWithinColumnsDirectRule RULE = new RegionsWithinColumnsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void RegionsWithinColumnsDirectRule_OneRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_OneRegionTwoCells() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(0,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0,1); + Point location2 = new Point(0,2); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_PartialRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,3); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1,3); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1,1); + Point location2 = new Point(1,3); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,3); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0,3); + Point location2 = new Point(1,3); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1,1); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(1,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(0,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns3() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns4() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,3); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0,3); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java index 49496f18c..3ffaa82fd 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java @@ -1,258 +1,258 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinRowsDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import java.awt.*; -// -//public class RegionsWithinRowsDirectRuleTest { -// -// private static final RegionsWithinRowsDirectRule RULE = new RegionsWithinRowsDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_OneRegionOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(2,0); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(2,0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_PartialRegionOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(2,0); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(2,0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_PartialRegionTwo() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(1,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(1,0); -// Point location2 = new Point(2,0); -// 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(location1) || point.equals(location2)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_TwoRegionsOneCell() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(3,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(3,1); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_StarOverlap() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(3,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(3,1); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows1() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(2,1); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(2,0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows2() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,0); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// Point location = new Point(2,0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void RegionsWithinRowsDirectRule_FalseStarOverlap() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(3,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); i++) { -// for (int k = 0; k < board.getWidth(); k++) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinRowsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class RegionsWithinRowsDirectRuleTest { + + private static final RegionsWithinRowsDirectRule RULE = new RegionsWithinRowsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void RegionsWithinRowsDirectRule_OneRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(2,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_PartialRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(2,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_PartialRegionTwo() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1,0); + Point location2 = new Point(2,0); + 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(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_TwoRegionsOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(3,1); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_StarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(3,1); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_FalseStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java index dc4dc4f3e..e1f9cb990 100644 --- a/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java @@ -1,68 +1,68 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.gameboard.Board; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.StarOrEmptyCaseRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import java.util.ArrayList; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class StarOrEmptyCaseRuleTest { -// -// private static final StarOrEmptyCaseRule RULE = new StarOrEmptyCaseRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// @Test -// public void StarOrEmptyCaseRuleTest_SimpleStarOrEmpty() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,0); -// ArrayList cases = RULE.getCases(board, cell); -// -// StarBattleBoard caseBoard1 = (StarBattleBoard) cases.get(0); -// StarBattleBoard caseBoard2 = (StarBattleBoard) cases.get(1); -// StarBattleCellType board1Type = caseBoard1.getCell(0, 0).getType(); -// StarBattleCellType board2Type = caseBoard2.getCell(0, 0).getType(); -// -// Assert.assertTrue( -// (board1Type.equals(StarBattleCellType.BLACK) || board1Type.equals(StarBattleCellType.STAR)) -// && (board2Type.equals(StarBattleCellType.BLACK) -// || board2Type.equals(StarBattleCellType.STAR))); -// Assert.assertFalse(board1Type.equals(board2Type)); -// Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); -// Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); -// -// for (int i = 0; i < caseBoard1.getHeight(); i++) { -// for (int k = 0; k < caseBoard1.getWidth(); k++) { -// Point point = new Point(k, i); -// if (point.equals(caseBoard1.getCell(k, i).getLocation())) { -// continue; -// } -// Assert.assertTrue(caseBoard1.getCell(k, i).equals(caseBoard2.getCell(k, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.StarOrEmptyCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import java.util.ArrayList; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class StarOrEmptyCaseRuleTest { + + private static final StarOrEmptyCaseRule RULE = new StarOrEmptyCaseRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + @Test + public void StarOrEmptyCaseRuleTest_SimpleStarOrEmpty() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,0); + ArrayList cases = RULE.getCases(board, cell); + + StarBattleBoard caseBoard1 = (StarBattleBoard) cases.get(0); + StarBattleBoard caseBoard2 = (StarBattleBoard) cases.get(1); + StarBattleCellType board1Type = caseBoard1.getCell(0, 0).getType(); + StarBattleCellType board2Type = caseBoard2.getCell(0, 0).getType(); + + Assert.assertTrue( + (board1Type.equals(StarBattleCellType.BLACK) || board1Type.equals(StarBattleCellType.STAR)) + && (board2Type.equals(StarBattleCellType.BLACK) + || board2Type.equals(StarBattleCellType.STAR))); + Assert.assertFalse(board1Type.equals(board2Type)); + Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); + Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); + + for (int i = 0; i < caseBoard1.getHeight(); i++) { + for (int k = 0; k < caseBoard1.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(caseBoard1.getCell(k, i).getLocation())) { + continue; + } + Assert.assertTrue(caseBoard1.getCell(k, i).equals(caseBoard2.getCell(k, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java index 738794a3b..db55d0f65 100644 --- a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java @@ -1,173 +1,173 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.SurroundStarDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class SurroundStarDirectRuleTest { -// -// private static final SurroundStarDirectRule RULE = new SurroundStarDirectRule(); -// private static StarBattle starbattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starbattle = new StarBattle(); -// } -// -// @Test -// public void SurroundStarDirectRule_CenterStarOneTile() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,1); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(0, 1); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void SurroundStarDirectRule_CenterStarOneTileDiagonal() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(0,0); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(0, 0); -// 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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void SurroundStarDirectRule_CenterStarAllTiles() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// for (int i = 0; i < board.getWidth(); i++) { -// for (int j = 0; j < board.getHeight(); j++) { -// if (i != 1 || j != 1) { -// StarBattleCell cell = board.getCell(i,j); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// } -// } -// } -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(1, 1); -// 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(location)) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void SurroundStarDirectRule_CornerStar() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,1); -// cell1.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell1); -// StarBattleCell cell2 = board.getCell(1,0); -// cell2.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell2); -// StarBattleCell cell3 = board.getCell(1,1); -// cell3.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell3); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location1 = new Point(0, 1); -// Point location2 = new Point(1,0); -// Point location3 = new Point(1,1); -// 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(location1) || point.equals(location2) || point.equals(location3)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -// } -// -// @Test -// public void SurroundStarDirectRule_FalseSurroundStar() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", starbattle); -// TreeNode rootNode = starbattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell = board.getCell(2,0); -// cell.setData(StarBattleCellType.BLACK.value); -// board.addModifiedData(cell); -// -// Assert.assertNotNull(RULE.checkRule(transition)); -// -// for (int i = 0; i < board.getHeight(); i++) { -// for (int k = 0; k < board.getWidth(); k++) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.SurroundStarDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SurroundStarDirectRuleTest { + + private static final SurroundStarDirectRule RULE = new SurroundStarDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void SurroundStarDirectRule_CenterStarOneTile() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0, 1); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_CenterStarOneTileDiagonal() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0, 0); + 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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_CenterStarAllTiles() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + if (i != 1 || j != 1) { + StarBattleCell cell = board.getCell(i,j); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + } + } + } + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1, 1); + 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(location)) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_CornerStar() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + StarBattleCell cell3 = board.getCell(1,1); + cell3.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell3); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0, 1); + Point location2 = new Point(1,0); + Point location3 = new Point(1,1); + 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(location1) || point.equals(location2) || point.equals(location3)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_FalseSurroundStar() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(2,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } +} diff --git a/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java b/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java index 71d556603..2c90c6fb2 100644 --- a/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java @@ -1,205 +1,205 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.puzzle.starbattle.rules.ClashingOrbitContradictionRule; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.TooFewStarsContradictionRule; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class TooFewStarsContradictionRuleTest { -// private static final TooFewStarsContradictionRule RULE = new TooFewStarsContradictionRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// /*Too few stars in column */ -// @Test -// public void TooFewStarsContradictionRule_Column() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Column", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(0,1); -// StarBattleCell cell3 = board.getCell(0,2); -// StarBattleCell cell4 = board.getCell(0,3); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -// } -// -// /*Too few stars in row*/ -// @Test -// public void TooFewStarsContradictionRule_Row() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Row", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(1,0); -// StarBattleCell cell3 = board.getCell(2,0); -// StarBattleCell cell4 = board.getCell(3,0); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /*Too few stars in region*/ -// @Test -// public void TooFewStarsContradictionRule_Region() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Region", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(0,1); -// StarBattleCell cell3 = board.getCell(1,0); -// StarBattleCell cell4 = board.getCell(1,1); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /*False contradiction*/ -// @Test -// public void TooFewStarsContradictionRule_FalseContradiction() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// -// Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -// @Test -// public void TooFewStarsContradictionRule_NotEnoughSpace() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/NotEnoughSpace", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -// @Test -// public void TooFewStarsContradictionRule_TwoStarColumn() -// throws InvalidFileFormatException { -// -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarColumn", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(0,1); -// StarBattleCell cell3 = board.getCell(0,2); -// StarBattleCell cell4 = board.getCell(0,3); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || -// point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// @Test -// public void TooFewStarsContradictionRule_TwoStarFalseContradiction() -// throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarFalseContradiction", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// -// Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.puzzle.starbattle.rules.ClashingOrbitContradictionRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.TooFewStarsContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TooFewStarsContradictionRuleTest { + private static final TooFewStarsContradictionRule RULE = new TooFewStarsContradictionRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + /*Too few stars in column */ + @Test + public void TooFewStarsContradictionRule_Column() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Column", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(0,1); + StarBattleCell cell3 = board.getCell(0,2); + StarBattleCell cell4 = board.getCell(0,3); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + + } + + /*Too few stars in row*/ + @Test + public void TooFewStarsContradictionRule_Row() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Row", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(1,0); + StarBattleCell cell3 = board.getCell(2,0); + StarBattleCell cell4 = board.getCell(3,0); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /*Too few stars in region*/ + @Test + public void TooFewStarsContradictionRule_Region() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Region", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(0,1); + StarBattleCell cell3 = board.getCell(1,0); + StarBattleCell cell4 = board.getCell(1,1); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /*False contradiction*/ + @Test + public void TooFewStarsContradictionRule_FalseContradiction() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + + @Test + public void TooFewStarsContradictionRule_NotEnoughSpace() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/NotEnoughSpace", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + + @Test + public void TooFewStarsContradictionRule_TwoStarColumn() + throws InvalidFileFormatException { + + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarColumn", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(0,1); + StarBattleCell cell3 = board.getCell(0,2); + StarBattleCell cell4 = board.getCell(0,3); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + @Test + public void TooFewStarsContradictionRule_TwoStarFalseContradiction() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarFalseContradiction", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + +} diff --git a/src/test/java/puzzles/starbattle/rules/TooManyStarsContradictionRuleTests.java b/src/test/java/puzzles/starbattle/rules/TooManyStarsContradictionRuleTests.java index 385652fae..3424bbaac 100644 --- a/src/test/java/puzzles/starbattle/rules/TooManyStarsContradictionRuleTests.java +++ b/src/test/java/puzzles/starbattle/rules/TooManyStarsContradictionRuleTests.java @@ -1,137 +1,137 @@ -//package puzzles.starbattle.rules; -// -//import edu.rpi.legup.puzzle.starbattle.rules.TooManyStarsContradictionRule; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.save.InvalidFileFormatException; -//import java.awt.*; -//import legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//public class TooManyStarsContradictionRuleTests { -// private static final TooManyStarsContradictionRule RULE = new TooManyStarsContradictionRule(); -// private static StarBattle starBattle; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// starBattle = new StarBattle(); -// } -// -// /* Tests the Too Many Stars contradiction rule where a region has -// more stars than the puzzle number */ -// @Test -// public void TooManyStarsContradictionRule_RegionOverloaded() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RegionOverloaded", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(2,1); -// StarBattleCell cell2 = board.getCell(0,2); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// -// /* Tests the Too Many Stars contradiction rule where a column has -// more stars than the puzzle number */ -// @Test -// public void TooManyStarsContradictionRule_ColumnOverloaded() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/ColumnOverloaded", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(0,3); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /* Tests the Too Many Stars contradiction rule where a row has -// more stars than the puzzle number */ -// @Test -// public void TooManyStarsContradictionRule_RowOverloaded() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RowOverloaded", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// StarBattleCell cell1 = board.getCell(0,0); -// StarBattleCell cell2 = board.getCell(3,0); -// -// Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -// } -// /*Tests the Too Many Stars contradiction rule for a false contradiction. */ -// @Test -// public void TooManyStarsContradictionRule_FalseContradiction() -// throws InvalidFileFormatException -// { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/Correct", starBattle); -// TreeNode rootNode = starBattle.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// StarBattleBoard board = (StarBattleBoard) transition.getBoard(); -// -// Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); -// -// for (int i = 0; i < board.getHeight(); ++i) { -// for (int j = 0; j < board.getWidth(); ++j) { -// Point point = new Point(j,i); -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); -// } -// } -// } -//} +package puzzles.starbattle.rules; + +import edu.rpi.legup.puzzle.starbattle.rules.TooManyStarsContradictionRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TooManyStarsContradictionRuleTests { + private static final TooManyStarsContradictionRule RULE = new TooManyStarsContradictionRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + /* Tests the Too Many Stars contradiction rule where a region has + more stars than the puzzle number */ + @Test + public void TooManyStarsContradictionRule_RegionOverloaded() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RegionOverloaded", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,1); + StarBattleCell cell2 = board.getCell(0,2); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + + /* Tests the Too Many Stars contradiction rule where a column has + more stars than the puzzle number */ + @Test + public void TooManyStarsContradictionRule_ColumnOverloaded() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/ColumnOverloaded", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(0,3); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /* Tests the Too Many Stars contradiction rule where a row has + more stars than the puzzle number */ + @Test + public void TooManyStarsContradictionRule_RowOverloaded() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RowOverloaded", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,0); + StarBattleCell cell2 = board.getCell(3,0); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } + /*Tests the Too Many Stars contradiction rule for a false contradiction. */ + @Test + public void TooManyStarsContradictionRule_FalseContradiction() + throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/Correct", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } +}