Problems with triangle design test cases are frequently encountered during interviews.
Assume that three integers A, B, and C are input as the sides of the three sides to form a triangle. The program determines the type of the triangle formed. When this triangle is a normal triangle, an isosceles triangle, or an equedge triangle! It is required to draw the flowchart and sequence diagram of the program and implement this function in a language that you are familiar! It can also be implemented in Java, and the flowchart is free.
The procedure is as follows:
Package
Sanj;
/**
*
* @ Author jxtrg
*/
Import java. Io .*;
Class sanj {
Public static int A, B, C;
Public static void
Main (string Arg []) throws ioexception {
Try {
Bufferedreader stdin = new
Bufferedreader (New inputstreamreader (system. In); // receives the key value
System. Out. println ("Enter the three sides, and press enter after each value ");
System. Out. println ("Enter :");
A = integer. valueof (stdin. Readline ());
B = integer. valueof (stdin. Readline ());
C = integer. valueof (stdin. Readline ());
} Catch (ioexception e ){
System. Out. println ("exception! ");
System. Exit (0 );
}
If (a + B <c | A + C <B |
B + C <){
System. Out. println ("You cannot input a triangle ");
}
If (A = B | A = c | B = C)
{
If (A = B & B = C)
System. Out. println ("equilateral triangle ");
Else
System. Out. println ("isosceles triangle ");
}
Else
System. Out. println ("normal triangle ");
}
}
[Solution]
Step 1: Determine the test policy. In this example, there are clear requirements for the functions of the program under test, namely:
(1) determine whether a triangle can be formed;
(2) Identifying equi-edge triangles;
(3) Recognize isosceles triangles;
(4) recognize any triangle. Therefore, you can first use the black box method to design test cases, and then use the white box method to verify the integrity of the test cases. If necessary, supplement the test cases.
Step 2: based on the actual situation in this example, in the black box method, the equivalence classes of input can be divided by the equivalence classification method, and then supplemented by the Boundary Value Analysis Method and the guess error method.
Equivalent classification:
Valid equivalence class
Enter three positive integers:
(1) Three equal numbers
(2) Two of the three numbers are equal, for example, AB is equal.
(3) Two of the three numbers are equal, for example, BC is equal.
(4) Two of the three numbers are equal, for example, the AC is equal.
(5) Numbers 3 are not equal
(6) the sum of 2 numbers is not greater than 3rd. For example, the maximum number is.
(7) the sum of 2 numbers is not greater than 3rd. For example, the maximum number is B.
(8) The sum of 2 numbers is not greater than 3rd. For example, the maximum number is C.
Invalid equivalence class:
(9) contains zero data
(10) contains a negative integer.
(11) less than 3 Integers
(12) contains non-Integers
(13) contains non-digit characters
Boundary Value Method:
(14) The sum of 2 equals 3rd.
Incorrect guess:
(15) Enter 3 zeros.
(16) enter three negative numbers.
Step 3: propose a set of preliminary test cases, as shown in the following table:
Step 4: Use the white box method to verify the adequacy of the test case generated in step 3. The results show that the first eight test cases in the Table above can fully cover the tested program diagram, and no additional test cases are required.