For this program, you will write a series of tests for a linear search function.
ID: 3827111 • Letter: F
Question
For this program, you will write a series of tests for a linear search function. The search function, some data, and a basic test suite are provided for you, so you will only need to create the code that uses the existing test suite functions to ensure that the recursive factorial function is correct. You should generate at least 10 test cases that cover various possible correct and incorrect inputs for the function. Consider testing cases that the algorithm might have trouble with, such as the first and last elements in the array. The test suite can then be used to ensure that the output of the function matches the expected result.
IN MIPS
Explanation / Answer
package com.java2novice.algos;
public class MyLinearSearch
{
public static int linerSearch(int[] arr, int key)
{
int size = arr.length;
for(int i=0;i<size;i++){
if(arr[i] == key){
return i;
}
}
return -1;
}
public static void main(String a[]){
int[] arr1= {20,35,19,45,227,1,27};
int searchKey = 34;
System.out.println("Key "+searchKey+" found at index: "+linerSearch(arr1, searchKey));
int[] arr2= {113,436,430,555,2014,36,314,170};
searchKey = 430;
System.out.println("Key "+searchKey+" found at index: "+linerSearch(arr2, searchKey));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.