Skip to content

Commit

Permalink
test updateGame method
Browse files Browse the repository at this point in the history
  • Loading branch information
muktar1907 committed Apr 16, 2024
1 parent 5f5d5fa commit da0a4d4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void updateGame(ArrayList<UserEvent> 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);
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/uta/cse3310/gameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> wordList = new ArrayList<String>(){
{
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<UserEvent> attempt = new ArrayList<UserEvent>(){
{
add(U1);
add(U2);
add(U3);
add(U4);
}
};


game.updateGame(attempt);
assertTrue(wordList.size()==5);

}
}

0 comments on commit da0a4d4

Please sign in to comment.