From 4305a5a4442da34111993595f3040d32a0ce7c91 Mon Sep 17 00:00:00 2001 From: changlmasaki <59718659+changlmasaki@users.noreply.github.com> Date: Wed, 11 Mar 2020 20:10:34 -0400 Subject: [PATCH 1/3] add TestGameController --- tests/kakuro/TestGameController.java | 130 +++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 tests/kakuro/TestGameController.java diff --git a/tests/kakuro/TestGameController.java b/tests/kakuro/TestGameController.java new file mode 100644 index 0000000..c0364c1 --- /dev/null +++ b/tests/kakuro/TestGameController.java @@ -0,0 +1,130 @@ +// @author Brian Gamboc-Javiniar +// @author Nalveer Moocheet +// @author Vsevolod Ivanov +// @author Chang Liu +// @brief Test for the GameController class + +package kakuro; + +import static org.junit.Assert.*; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; + +import org.junit.Test; + +import kakuro.game.dao.GameDao; +import kakuro.game.dao.GameDaoImpl; +import kakuro.gameprogress.dao.GameProgressDaoImpl; +import kakuro.utils.DatabaseConnection; + +public class TestGameController { + + @Test + public void testGameController() { + //Arrange + int rows = 3; + int columns = 5; + //Act + GameController gameController = new GameController(columns,rows, false); + //Set GUI to false + //Assert + assertEquals(columns, gameController.model.columns); + assertEquals(rows, gameController.model.rows); + + } + + @Test + public void testGetDatabaseConnection() { + DatabaseConnection db = new DatabaseConnection(); + db.getConnection(); + } + + @Test + public void testConnectDatabase() { + //Arrange + DatabaseConnection db = new DatabaseConnection(); + db.connect(); + //Act + Connection conn = db.getConnection(); + //Assert + assertEquals(conn!=null, true); + db.disconnect(); + } + + @Test + public void testDisconnectDatabase() { + //Arrange + DatabaseConnection db = new DatabaseConnection(); + db.connect(); + db.disconnect(); + //Act + Connection conn = db.getConnection(); + //Assert + try { + assertEquals(conn.isClosed(), true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testSolveBoard() { + Boolean GUI = false; + Boolean solved = false; + // Arrange + int columns = 10; + int rows = 10; + // Act + GameModel model = new GameModel(columns, rows); + // Assert + assertEquals(model.columns, columns); + assertEquals(model.rows, rows); + // Arrange + GameController controller1 = new GameController(10,10, GUI); + GameModel model1 = new GameModel(10,10); + model1.initBoard(); //initialize board + model1.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model1.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); + model1.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model1.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model1.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); + controller1.model = model1; + // Act + solved = controller1.solveBoard(); + // Assert + assertEquals(solved, true); + // Arrange + GameController controller2 = new GameController(10,10, GUI); + GameModel model2 = new GameModel(10,10); + model2.initBoard(); + model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); + model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,5,-1); + controller2.model = model2; + // Act + solved = controller2.solveBoard(); + // Assert + assertEquals(solved, false); + // Arrange + GameController controller3 = new GameController(10,10, GUI); + GameModel model3 = new GameModel(10,10); + model3.initBoard(); + model3.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model3.board[1][0] = new BoardCell(BoardCell.CellType.FILLED11,-1,4); + model3.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model3.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model3.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + controller3.model = model3; + // Act + solved = controller3.solveBoard(); + // Assert + assertEquals(solved, false); + } + +} + From 1c5ed1fda74da1cee5c2ac1a6958f56db74a6481 Mon Sep 17 00:00:00 2001 From: changlmasaki <59718659+changlmasaki@users.noreply.github.com> Date: Wed, 11 Mar 2020 23:58:09 -0400 Subject: [PATCH 2/3] Update TestGameController.java --- tests/kakuro/TestGameController.java | 162 ++++++++++++++++++--------- 1 file changed, 106 insertions(+), 56 deletions(-) diff --git a/tests/kakuro/TestGameController.java b/tests/kakuro/TestGameController.java index c0364c1..3b0fca2 100644 --- a/tests/kakuro/TestGameController.java +++ b/tests/kakuro/TestGameController.java @@ -20,7 +20,9 @@ import kakuro.utils.DatabaseConnection; public class TestGameController { - + Boolean GUI = false; + Boolean solved = false; + @Test public void testGameController() { //Arrange @@ -32,7 +34,6 @@ public void testGameController() { //Assert assertEquals(columns, gameController.model.columns); assertEquals(rows, gameController.model.rows); - } @Test @@ -71,60 +72,109 @@ public void testDisconnectDatabase() { } @Test - public void testSolveBoard() { - Boolean GUI = false; - Boolean solved = false; - // Arrange - int columns = 10; - int rows = 10; - // Act - GameModel model = new GameModel(columns, rows); - // Assert - assertEquals(model.columns, columns); - assertEquals(model.rows, rows); - // Arrange - GameController controller1 = new GameController(10,10, GUI); - GameModel model1 = new GameModel(10,10); - model1.initBoard(); //initialize board - model1.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model1.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model1.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model1.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model1.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); - controller1.model = model1; - // Act - solved = controller1.solveBoard(); - // Assert - assertEquals(solved, true); - // Arrange - GameController controller2 = new GameController(10,10, GUI); - GameModel model2 = new GameModel(10,10); - model2.initBoard(); - model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,5,-1); - controller2.model = model2; - // Act - solved = controller2.solveBoard(); - // Assert - assertEquals(solved, false); - // Arrange - GameController controller3 = new GameController(10,10, GUI); - GameModel model3 = new GameModel(10,10); - model3.initBoard(); - model3.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model3.board[1][0] = new BoardCell(BoardCell.CellType.FILLED11,-1,4); - model3.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model3.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model3.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - controller3.model = model3; - // Act - solved = controller3.solveBoard(); - // Assert - assertEquals(solved, false); +// @brief Test Valid Board + public void testSolveBoard1() { + // Arrange + int columns = 10; + int rows = 10; + // Act + GameModel model = new GameModel(columns, rows); + // Assert + assertEquals(model.columns, columns); + assertEquals(model.rows, rows); + // Arrange + GameController controller1 = new GameController(10,10, GUI); + GameModel model1 = new GameModel(10,10); + model1.initBoard(); //initialize board + model1.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model1.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); + model1.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model1.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model1.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); + controller1.model = model1; + // Act + solved = controller1.solveBoard(); + // Assert + assertEquals(solved, true); + } + + @Test +// @brief Test Invalid Board with one wrong vertical sum + public void testSolveBoard2() { + // Arrange + int columns = 10; + int rows = 10; + // Act + GameModel model = new GameModel(columns, rows); + // Assert + assertEquals(model.columns, columns); + assertEquals(model.rows, rows); + GameController controller2 = new GameController(10,10, GUI); + GameModel model2 = new GameModel(10,10); + model2.initBoard(); + model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); + model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,6,-1); + model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); + controller2.model = model2; + // Act + solved = controller2.solveBoard(); + // Assert + assertEquals(solved, false); + } + + @Test +// @brief Test Invalid Board with one wrong horizontal sum + public void testSolveBoard3() { + // Arrange + int columns = 10; + int rows = 10; + // Act + GameModel model = new GameModel(columns, rows); + // Assert + assertEquals(model.columns, columns); + assertEquals(model.rows, rows); + GameController controller2 = new GameController(10,10, GUI); + GameModel model2 = new GameModel(10,10); + model2.initBoard(); + model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,8); + model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); + controller2.model = model2; + // Act + solved = controller2.solveBoard(); + // Assert + assertEquals(solved, false); + } + + @Test +// @brief Test Invalid Board with correct sum but duplicate entries + public void testSolveBoard4() { + // Arrange + int columns = 10; + int rows = 10; + // Act + GameModel model = new GameModel(columns, rows); + // Assert + assertEquals(model.columns, columns); + assertEquals(model.rows, rows); + // Arrange + GameController controller3 = new GameController(10,10, GUI); + GameModel model3 = new GameModel(10,10); + model3.initBoard(); + model3.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); + model3.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); + model3.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model3.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); + model3.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + controller3.model = model3; + // Act + solved = controller3.solveBoard(); + // Assert + assertEquals(solved, false); } - } From 623d2e687d7735a86f2f9378b10ccb223d5a8893 Mon Sep 17 00:00:00 2001 From: changlmasaki <59718659+changlmasaki@users.noreply.github.com> Date: Thu, 12 Mar 2020 00:28:28 -0400 Subject: [PATCH 3/3] Update TestGameController.java --- tests/kakuro/TestGameController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/kakuro/TestGameController.java b/tests/kakuro/TestGameController.java index 3b0fca2..d06d975 100644 --- a/tests/kakuro/TestGameController.java +++ b/tests/kakuro/TestGameController.java @@ -73,7 +73,7 @@ public void testDisconnectDatabase() { @Test // @brief Test Valid Board - public void testSolveBoard1() { + public void testBoardSolveValidBoard() { // Arrange int columns = 10; int rows = 10; @@ -100,7 +100,7 @@ public void testSolveBoard1() { @Test // @brief Test Invalid Board with one wrong vertical sum - public void testSolveBoard2() { + public void testBoardSolveInvalidBoardWithOneWrongVerticalSum() { // Arrange int columns = 10; int rows = 10; @@ -126,7 +126,7 @@ public void testSolveBoard2() { @Test // @brief Test Invalid Board with one wrong horizontal sum - public void testSolveBoard3() { + public void testBoardSolveInvalidBoardWithOneWrongHorizontalSum() { // Arrange int columns = 10; int rows = 10; @@ -152,7 +152,7 @@ public void testSolveBoard3() { @Test // @brief Test Invalid Board with correct sum but duplicate entries - public void testSolveBoard4() { + public void testBoardSolveInvalidBoardWithDuplicateEntries() { // Arrange int columns = 10; int rows = 10;