package lab5; /** * SearchArray implements a linear search in an array, searching * for a user provided value. * * Class Invariants: * 'maxVal' must be greater than 'minVal' * All elements of the array must lie in the range defined by * 'minVal' and 'maxVal' variables * @author * @version Mar 3, 2012 * @project CMSC 202 - Spring 2012 - Project # * @section # * */ public class SearchArray { private int array[],minVal,maxVal; boolean constructed=false; /** * Assigns the instance variable array reference to * point to the incoming array reference. Also assigns the * range values. * Precondition: The input array to the constructor cannot be null. * @param array The input array to be searched on. * @param minVal The minimum allowed value in the array. * @param maxVal The maximum allowed value in the array. */ public SearchArray(int[] array, int minVal, int maxVal) { //Precondition checking code if(array==null){ throw new NullPointerException("Constructor precondition " + "not met: Input array cannot be null"); } //class invariant #1 checking code if(maxValmaxVal. Expecting error statement."); int[] testArray1={1,2,3,4,5}; s=new SearchArray(testArray1, 10, 9); */ //test case to check constructor precondition /* System.out.println("Passing null array. Expecting error statement."); int[] testArray2=null; s=new SearchArray(testArray2, 0, 100); */ //test case to check edge values of the constructor System.out.println("Edge case for constructor. Array values " + "exactly on range limits"); int[] testArray3={-5,-9,0,-1,3,6,7,-2,2}; s=new SearchArray(testArray3, -9, 7); //test case to check general values of the constructor System.out.println("General test case for constructor"); int[] testArray4={-5,-6,0,-1,3,6,7,-2,2,3,4,7,-8}; s=new SearchArray(testArray4, -9, 10); /* * General test case(s) for search() */ /* * Precondition checking test case for search() */ /* * Edge test case for search() */ } }