Introduction to Software engineering---MAX unit testing

Source: Internet
Author: User

Title: A unit test to find the maximum value in list[]

Write a program to test the largest function and enumerate all the test cases.

Idea: First make sure that the array is not empty, and that the arrays are not 0 in length, otherwise the input is wrong. Write a main function according to the function given by the teacher and test it in the run. I write the main function input and output can be.

#include <iostream>using namespacestd;intLargest (intList[],intlength) {    inti,max=list[0]; if (length=0)
{
cout<<" Error! The array length cannot be empty! "<<Endl;
}
for(i=0;i< (length); i++) { if(list[i]>max) {Max=List[i]; } } returnMax;}voidMain () {intlist[ -],length; inti;cout<<"input Array Length:"<<Endl; CIN>>length; for(i =0; i < length; i++) {cout<<"input Array Members:"; CIN>>List[i]; } cout<<"the maximum value in the array is:"<< largest (list, length) <<Endl;}

Test scenario: Input in order of size (sequential or reverse), negative input, and two identical maximum values in the array;

As follows:

Summary: Test the results of a program correctly, to synthesize all possible results to run. Includes possible sequences of possible outcomes.

Be thoughtful, and then modify the program according to the aspects that cannot be achieved.

In the program implementation process, the teacher gives the function segment where the error is more like making max=list[], and the loop portion of itself (the parentheses loop content) does not deal with sloppy errors such as these errors accumulate.

Introduction to Software engineering---MAX unit testing

Related Article

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.