Conduct Unit testing for Game Logic class(es) and Computer Player class in the core package using JUnit for this deliverable. Create a separate package called test for the test class(es). Provide test methods for all important methods of the game logic and computer player module with different possible test cases using equivalence partitioning. You should have both success and failure cases. Use a code coverage tool such as EclEmma to generate a code coverage report for classes (only those classes where you provided unit tests) in the core package. You must achieve at least 90% code coverage (only Game Logic and Computer Player classes) through various test cases. Include the code coverage report in your submission.
ConnectFour class
package core;
public class ConnectFour {
public static void display(char[][] grid) {
System.out.println(" 1 2 3 4 5 6 7");
System.out.println("---------------");
for(int row = 0; row= grid[0].length) {
return false;
}
if(grid[0][col] != ' ') {
return false;
}
return true;
}
public static boolean win(char player, char[][] grid) {
//4 across
for(int row = 0; row for(int col = 0; col< grid[0].length - 3; col++) {
if(grid[row][col]==player &&
grid[row][col+1]==player &&
grid[row][col+2] == player&&
grid[row][col+3]==player) {
return true;
}
}
}
//4 up and down
for(int row = 0; row for(int col = 0; col if(grid[row][col] == player &&
grid[row+1][col] ==player &&
grid[row +2][col] == player &&
grid[row+3][col]==player) {
return true;
}
}
}
//Upward diagonal
for(int row = 3; row for(int col = 0; col< grid[0].length - 3; col++) {
if(grid[row][col] == player &&
grid[row-1][col+1]== player &&
grid[row-2][col+2]== player &&
grid[row-3][col+3]== player) {
return true;
}
}
}
//Downward diagonal
for(int row = 0; row < grid.length - 3; row++){
for(int col = 0; col < grid[0].length - 3; col++){
if (grid[row][col] == player &&
grid[row+1][col+1] == player &&
grid[row+2][col+2] == player &&
grid[row+3][col+3] == player){
return true;
}
}
}
return false;
}
}
Connect4ComputerPlayer class
package core;
import java.util.Random;
public class Connect4ComputerPlayer {
public int turn() {
Random randNum = new Random();
int rand = randNum.nextInt((7-1)+1)+1;
return rand;
}
}