Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help me please using junit and create test case (exception- rules ) code is area

ID: 3555609 • Letter: H

Question

help me please using junit and create test case (exception- rules ) code is aready given. keep getting error

package select;

public class selectionSort2 {

       public static void main(String[] args)
       {
       int n = 20;
       int[] numArray = unsortedArray(n); // re-initialize
       printArray(numArray,n);
       selectSort2(numArray, n);
       printArray(numArray, n);
       }
         
         
       //Generate data for the selection sort array
       public static int[] unsortedArray(int n) {
       int[] a = new int[n];
       for (int index = 0; index < n; index++) {
       a[index] = (n - index);
       }
       return a;
       }
       //print the array
       public static void printArray(int[] data, int n)
       {
       for (int index = 0; index < n; index++) {
       System.out.print(data[index] + " ");
       }
       System.out.println();
       } public static void selectSort2(int[] data, int n)
       {
       for (int numUnsorted = n; numUnsorted > 0; numUnsorted--) {
       int maxIndex = 0;
       for (int index = 1; index < numUnsorted; index++) {
       if (data[maxIndex] < data[index])
       maxIndex = index;
       //swap the element
       int temp = data[numUnsorted-1];
       data[numUnsorted-1] = data[maxIndex];
       data[maxIndex] = temp;
         
       }
       }
       }

   }

Test

/**
*
*/
package select;

import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author secc
*
*/
public class exceptionTest {

   /**
   * @throws java.lang.Exception
   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
  
   }

   /**
   * @throws java.lang.Exception
   */
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
  
  
   }

   /**
   *
   */
@Test
public void testExceptionIsThrown()
{
   selectionSort2 test = new selectionSort2();
   int []data= {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1};
   int n=20;
   test.selectSort2(data, n);
  
}
  
   @Test
   public void testSelectSort2() {
      
       selectionSort2 test = new selectionSort2();
       int []data= {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1};
       int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20 };
   int n=20;
   selectionSort2.selectSort2(data,n);
       assertArrayEquals(expected, n);
      
   }

}

Explanation / Answer

JUST CHANGED TEST CLASS : It works now