/******************************************************************************* * This files was developed for CS4233: Object-Oriented Analysis & Design. * The course was taken at Worcester Polytechnic Institute. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Copyright ©2016 Gary F. Pollice *******************************************************************************/ package escape; import escape.initializers.EscapeGameBuilder; import escape.interfaces.Coordinate; import escape.interfaces.EscapePiece; import escape.util.EscapeObserver; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** * This is a simple test, not really a unit test, to make sure tht the * EscapeGameBuilder, in the starting code, is actually working. * * @version May 30, 2020 */ class EscapeGameBuilderTest { @Test void testExist() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); } @Test void testGameManagerCreation() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); Assertions.assertNotNull(egb.makeGameManager()); } @Test void testMakeCoordinate() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Assertions.assertNotNull(manager.makeCoordinate(1,1)); } @Test void testMoveInvalid() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(4,4); Assertions.assertFalse(manager.move(start,finish)); } @Test void testMoveValid() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(4,5); Assertions.assertTrue(manager.move(start,finish)); } @Test void testGetPiece() throws Exception{ EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate snailLoc = manager.makeCoordinate(4,4); EscapePiece snail = manager.getPieceAt(snailLoc); Assertions.assertNotNull(snail); Assertions.assertNotNull(snail.getName()); Assertions.assertNotNull(snail.getPlayer()); //System.out.println(snail.getName()); //System.out.println(snail.getPlayer()); } @Test void testGetPieceFail() throws Exception{ EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate snailLoc = manager.makeCoordinate(5,4); EscapePiece snail = manager.getPieceAt(snailLoc); Assertions.assertNull(snail); } @Test void testMoveNoPiece() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(1,1); Coordinate finish = manager.makeCoordinate(1,2); Assertions.assertFalse(manager.move(start,finish)); } @Test void testMoveAboveBounds() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(50,50); Assertions.assertFalse(manager.move(start,finish)); } @Test void testMoveBelowBounds() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(0,0); Assertions.assertFalse(manager.move(start,finish)); } @Test void testMoveTwicePickEmptySpace() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(4,5); Assertions.assertTrue(manager.move(start,finish)); Assertions.assertFalse(manager.move(start,finish)); } @Test void testInvalidMoveThenValidMove() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(4,5); Coordinate wrong = manager.makeCoordinate(50,50); Assertions.assertFalse(manager.move(start,wrong)); Assertions.assertTrue(manager.move(start,finish)); } @Test void testOutOfRange() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,4); Coordinate finish = manager.makeCoordinate(9,9); Assertions.assertFalse(manager.move(start,finish)); } @Test void testMoveAfterWin() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4,12); Coordinate finish = manager.makeCoordinate(5,12); Coordinate postStart = manager.makeCoordinate(4,4); Coordinate postFinish = manager.makeCoordinate(4,5); Assertions.assertTrue(manager.move(start,finish)); Assertions.assertFalse(manager.move(postStart,postFinish)); } @Test void testOutOfRangeBlocksInWay() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(7, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertFalse(manager.move(start, finish)); } @Test void testOutOfRangePiecesInWay() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(3, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertFalse(manager.move(start, finish)); } @Test void testHorseGoesAroundObstacles() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(9, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertTrue(manager.move(start, finish)); } @Test void testScoreLimit() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(9, 12); Coordinate finish = manager.makeCoordinate(5, 12); Coordinate start2 = manager.makeCoordinate(10, 12); Coordinate finish2 = manager.makeCoordinate(5, 12); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertFalse(manager.move(start2, finish2)); } @Test void testPieceOwnership() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(10, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertFalse(manager.move(start, finish)); } @Test void testTurnLimit() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4, 4); Coordinate finish = manager.makeCoordinate(4, 5); Coordinate start2 = manager.makeCoordinate(10, 12); Coordinate finish2 = manager.makeCoordinate(8, 12); Coordinate start3 = manager.makeCoordinate(4, 5); Coordinate finish3 = manager.makeCoordinate(4, 6); Coordinate start4 = manager.makeCoordinate(8, 12); Coordinate finish4 = manager.makeCoordinate(5, 11); Coordinate start5 = manager.makeCoordinate(4, 6); Coordinate finish5 = manager.makeCoordinate(4, 7); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertTrue(manager.move(start2, finish2)); Assertions.assertTrue(manager.move(start3, finish3)); Assertions.assertTrue(manager.move(start4, finish4)); Assertions.assertFalse(manager.move(start5, finish5)); } @Test void testOutOfRangeHex() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1Hex.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(1, 1); Coordinate finish = manager.makeCoordinate(2, 2); Assertions.assertFalse(manager.move(start, finish)); } @Test void testLandOnBlock() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(3, 4); Coordinate finish = manager.makeCoordinate(3, 5); Assertions.assertFalse(manager.move(start, finish)); } @Test void testLandOnPiece() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(7, 12); Coordinate finish = manager.makeCoordinate(9, 12); Assertions.assertFalse(manager.move(start, finish)); } @Test void testLandOnPieceRemove() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(4, 12); Coordinate finish = manager.makeCoordinate(4, 11); Coordinate start2 = manager.makeCoordinate(4, 11); Coordinate finish2 = manager.makeCoordinate(4, 10); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertFalse(manager.move(start2, finish2)); } @Test void testRemoveOwnPiece() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(3, 4); Coordinate finish = manager.makeCoordinate(4, 4); Assertions.assertFalse(manager.move(start, finish)); } @Test void testUnBlock() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(7, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertTrue(manager.move(start, finish)); } @Test void testFly() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(8, 12); Coordinate finish = manager.makeCoordinate(5, 12); Assertions.assertTrue(manager.move(start, finish)); } @Test void testLinearSquare() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(5, 9); Coordinate start2 = manager.makeCoordinate(3, 3); Coordinate start3 = manager.makeCoordinate(3, 2); Coordinate finish = manager.makeCoordinate(5, 12); Coordinate finish2 = manager.makeCoordinate(1, 1); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertTrue(manager.move(start2, finish2)); Assertions.assertFalse(manager.move(start3, finish2)); } @Test void testLinearHex() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2Hex.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(-3, 0); Coordinate start2 = manager.makeCoordinate(0, -3); Coordinate start3 = manager.makeCoordinate(-2, 1); Coordinate finish = manager.makeCoordinate(0, 0); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertTrue(manager.move(start2, finish)); Assertions.assertFalse(manager.move(start3, finish)); } @Test void testLinearHexBlock() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2Hex.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(-2, -2); Coordinate finish = manager.makeCoordinate(0, 0); Assertions.assertFalse(manager.move(start, finish)); } @Test void testValue() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2Hex.egc"); EscapeGameManager manager = egb.makeGameManager(); Coordinate start = manager.makeCoordinate(1, 0); Coordinate start2 = manager.makeCoordinate(0, -3); Coordinate finish = manager.makeCoordinate(0, 0); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertFalse(manager.move(start2, finish)); } @Test void testObserverInstance() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeObserver observer = new EscapeObserver(); Assertions.assertNotNull(observer); } //I tested this by reading the printout but that is now disabled in accordance with the requirements @Test void testObserverWin() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test2Hex.egc"); EscapeGameManager manager = egb.makeGameManager(); EscapeObserver observer = new EscapeObserver(); Assertions.assertNotNull(manager.addObserver(observer)); Coordinate start = manager.makeCoordinate(1, 0); Coordinate start2 = manager.makeCoordinate(0, -3); Coordinate finish = manager.makeCoordinate(0, 0); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertFalse(manager.move(start2, finish)); Assertions.assertNotNull(manager.removeObserver(observer)); } //I tested this by reading the printout but that is now disabled in accordance with the requirements @Test void testObserverError() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/test1.egc"); EscapeGameManager manager = egb.makeGameManager(); EscapeObserver observer = new EscapeObserver(); Assertions.assertNotNull(manager.addObserver(observer)); Coordinate start = manager.makeCoordinate(7, 12); Coordinate finish = manager.makeCoordinate(9, 12); Assertions.assertFalse(manager.move(start, finish)); Assertions.assertNotNull(manager.removeObserver(observer)); } @Test void testPlayer2NoPieces() throws Exception { EscapeGameBuilder egb = new EscapeGameBuilder("config/egc/testNoPieces.egc"); EscapeGameManager manager = egb.makeGameManager(); EscapeObserver observer = new EscapeObserver(); manager.addObserver(observer); Coordinate start = manager.makeCoordinate(10, 3); Coordinate finish = manager.makeCoordinate(10, 2); Coordinate start2 = manager.makeCoordinate(3, 4); Coordinate finish2 = manager.makeCoordinate(3, 3); Assertions.assertTrue(manager.move(start, finish)); Assertions.assertTrue(manager.move(start2, finish2)); } }