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

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

# search # Linear Search Algorithm # # Determines if the requested value is present in an array. # # Parameters: # $a0: the address of an array. # $a1: the length of the array. # $a2: the data to search for. # # Results: # $v0: 0+ the index where the data was found. # -2 if an error occurs. # -1 if the data is not found. ##################################################################################### search: # Testing for bad parameters. lui $t0, 0x1000 blt $a0, $t0, search_OutOfMemoryRange sll $t1, $a1, 2 addu $t1, $a0, $t1 blt $t1, $t0, search_ArrayTooLarge sll $t0, $a0, 30 bne $t0, $zero, search_NotWordAligned blez $a1, search_ArrayTooSmall # Initializing loop parameters. move $t0, $a0 # Address of current element to search sll $t1, $a1, 2 add $t1, $t0, $t1 # End of the array # Iteratively searching through the array by incrementing the address. search_loop: beq $t0, $t1, search_NotFound lw $t2, 0 ($t0) beq $t2, $a2, search_Found addi $t0, $t0, 4 j search_loop # Return -1 if the data is not found. search_NotFound: li $v0, -1 jr $ra # Return the index if the data is found. search_Found: # Convert the address into an index. sub $v0, $t0, $a0 srl $v0, $v0, 2 jr $ra # We could provide separate error codes for each of these conditions if we wanted. search_OutOfMemoryRange: # The array is not in a valid part of memory. search_ArrayTooLarge: # The array ends outside of a valid part of memory. search_ArrayTooSmall: # The array length is less than 1. search_NotWordAligned: # The array is not word aligned. li $v0, -2 jr $ra 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!