test harness for smallest element in array - main class method

82 views Asked by At

I'm new to test harness writing so I'd like some tips on how to get started. I have some code for finding the smallest element in an array and I'm not sure what I need to change to the method so I can begin writing my test harness around the method. I know that I shouldn't have the method in a main class, but I'm not sure how to define the same method so it's not in the main class.

I just need to know what would be the first thing I would do to start writing my test harness for this program.

import java.util.Scanner;

public class Fross_Charles_PA4
{
    public static void main(String args[])
   {
       int small, size, i;
       int arr[] = new int[50];
       Scanner scan = new Scanner(System.in);
       
       System.out.print("Enter Array Size : ");
       size = scan.nextInt();
       
       System.out.print("Enter Array Elements : ");
       for(i=0; i<size; i++)
       {
           arr[i] = scan.nextInt();
       }
       
       System.out.print("Searching for the Smallest Element....\n\n");
       
       small = arr[0];
       
       for(i=0; i<size; i++)
       {
           if(small > arr[i])
           {
               small = arr[i];
           }
           
       }
       
       System.out.print("Smallest Element = " + small); 
   }
}
0

There are 0 answers