Software testing foundations homework2,

Source: Internet
Author: User

Software testing foundations homework2,
Homework 2

Below are two faulty programs. Each except des a test case that results in failure. Answer the following questions (in the next slide) about each program.

Public int findLast (int [] x, int y) {// Effects: If x = null throw

NullPointerException
// Else return the index of the last element // in x that equals y.
// If no such element exists, return-1
For (int I = x. length-1; I> 0; I --)
{

If (x [I] = y ){

Return I ;}

}
Return-1;

}
// Test: x = [2, 3, 5]; y = 2 // Expected = 0

Public static int lastZero (int [] x) {// Effects: if x = null throw

NullPointerException
// Else return the index of the LAST 0 in x. // Return-1 if 0 does not occur in x
For (int I = 0; I <x. length; I ++)
{

If (x [I] = 0 ){

Return I ;}

} Return-1 ;}

// Test: x = [0, 1, 0] // Expected = 2

56

Questions

Identify the fault.
If possible, identify a test case that does not execute

Fault. (Reachability)

If possible, identify a test case that executes the fault, butdoes not result in an error state.

If possible identify a test case that results in an error, butnot a failure.

Due Date: 23:59:59 March 15.

Please send your answer to tjuscsst@qq.com and post itto your blog.

Solution: 1.1) the condition in the for loop should be I> = 0, otherwise return-1 directly to 0. 2) test: x = []; y = 23) test: x = [2, 3, 5]; y = 54) test: x = [2, 3, 5]; y = 92.1) The for loop should be open from the last bit of the array; otherwise, the first 02 is found) test: x = [] 3) test: x = [1, 1, 1] 4) test: x = [0, 1, 1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.