1. Engineering
  2. Computer Science
  3. need j unit test case to test against this code...

Question: need j unit test case to test against this code...

Question details

//Java program for consecutive four equal numbers /fHeader file section import java.util.Scanner; //class declartion class ConsecutiveFour [ //main function public static void main(String[] args) /fcreate a scanner Scanner scnew Scanner (System.in); int[]t] array; int row, col; System.out.print(Enter number of row:); rowSc.nextInt); System.out.print(Enter number of column:); colsc.nextInt); array new int [row] [col]; / fetching data into array System.out.println(Enter the elements in array.); System.out.println(Enter elements in line: (1+1)); for(int j e; j < col; j +) array[i]j]sc.nextInt); if(ConsecutiveFour.isconsecutiveFour(array)) System.out.println(This array has four consecutive same numbers); else System.out.println(This array doesnt have four consecutive same numbers); public static boolean isConsecutiveFour(int[][] values) boolean status -false; / check for a horizontal win for (int row-e; row<valueslength; rowtt) for (int column-0; column<(values [row].length-3); column++) 6 if (values [row][column] !- 0 &t& values [row] [column] == values [row][column+1] && values [row] [column] status -true; values [row] [column+3]) 6

/f check for a vertical win for (int row-e; row< (values.length-3); rowtt) for (int column-0; column<values[row].length; column) t if (values [row][column] e &8 values [rowl[columnvalues [row+11[columnl && values [row] [column] values [row+2] [column] && values [row] [column]- values row+3] [column]) status-true; // check for a diagonal win (positive slope) for (int row-e; row<(values.length-3); rowtt) for (int column-0; column< (values [row].length-3); column++) if (values [row] [column]e && values [row] [column]values [row+1] [column+1] && values [row] [column] == values [row+2][column+2] && values[row][colun]v statustrue; = values [row+3][column+3)) { // check for a diagonal win (negative slope) for (int row-3; row<values.length; row+t) i for (int column-0; column< (values [row].length-3); column++) if (values [row] [column] != 0 && values[row][column] value values [row] [column] values [row-2][column+2] && values [row] [column]values [row-3] [column+3]) t statustrue; s[rou-1] [column+1]8 return status; OUTPUT Enter Number of Row:4 Enter Number of Column:4 Enter the elements in the array Enter elements in line 1:1 1 1 1 Enter elements in line 2:3 3 33 Enter elements in line 3:4 4 4 4 Enter elements in line 4:7 7 7 7 This array has four consecutive same number

Need J unit test case to test against this code to make sure everything is working fine

Just an example of JUnit test On the left the code and you can see the test case on the right. Homeworko.java | DỊ HomeworkOTest.java33 ії in..in packagehomeworks. homeworke; 1 package e 3 public class Homeworke 5 public static void main(Stringll args) f homeworks. homeworke; 3+ import org. junit.Test: public class HomeworkeTest extends TestCase t System.out.print n(Helto wortd) @Test public void test) f String expected:,Hello, world! ; Homeworke.main nulu) String actual systemout.getHistory); assertEquals (expected, actua): 10 12 h 16

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution