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