From da0a4d4120821afafcdba6c76f30939b1ee41899 Mon Sep 17 00:00:00 2001 From: muktar1907 Date: Tue, 16 Apr 2024 00:14:00 -0500 Subject: [PATCH] test updateGame method --- src/main/java/uta/cse3310/Game.java | 2 +- src/test/java/uta/cse3310/gameTest.java | 65 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/java/uta/cse3310/Game.java b/src/main/java/uta/cse3310/Game.java index 293d87e..a7ddabb 100644 --- a/src/main/java/uta/cse3310/Game.java +++ b/src/main/java/uta/cse3310/Game.java @@ -106,7 +106,7 @@ public void updateGame(ArrayList attempt) int row = index/50; int column= index%50; - word=word+grid[index][column]; + word=word+grid[row][column]; System.out.println(word); } wordChosen(word,player); diff --git a/src/test/java/uta/cse3310/gameTest.java b/src/test/java/uta/cse3310/gameTest.java index 67699de..a407e6b 100644 --- a/src/test/java/uta/cse3310/gameTest.java +++ b/src/test/java/uta/cse3310/gameTest.java @@ -104,4 +104,69 @@ public void testExit() } + + public void testUpdate() + { + //initialize game + Game game= new Game(); + //create players + Player player1= new Player("tom"); + + //add players to the game + game.addPlayers(player1); + + ArrayList wordList = new ArrayList(){ + { + add("hello"); + add("goodbye"); + add("testing"); + add("computer"); + add("code"); + } + }; + GridField gridField=new GridField(wordList); + game.setGridField(gridField); + game.startGame(); + game.setGridField(gridField); + game.startGame(); + char[][] grid =gridField.getGrid(); + //test word + String word=""; + for(int i=0;i<4;i++) + { + word=word+ String.valueOf(grid[1][i]); + } + gridField.getWordList().add(word); + //user event array + UserEvent U1= new UserEvent(); + UserEvent U2= new UserEvent(); + UserEvent U3= new UserEvent(); + UserEvent U4= new UserEvent(); + UserEvent U5= new UserEvent(); + U1.player=player1; + U1.cell=50; + U1.action=0; + U2.player=player1; + U2.cell=51; + U2.action=1; + U3.player=player1; + U3.cell=52; + U3.action=1; + U4.player=player1; + U4.cell=53; + U4.action=2; + ArrayList attempt = new ArrayList(){ + { + add(U1); + add(U2); + add(U3); + add(U4); + } + }; + + + game.updateGame(attempt); + assertTrue(wordList.size()==5); + + } } \ No newline at end of file