三角形白盒测试
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一.三角形问题:
1.import java.util.Scanner;
2. public class test
3.{
4. public static void main(String[] args)
5. {
6. Scanner input=new Scanner(System.in);
7. System.out.print("Enter 3 integers which are sides of a triangle:");
8. double a=input.nextDouble();
9. double b=input.nextDouble();
10. double c=input.nextDouble();
11 int sign1=0,sign2=0;
12 if(a>0&&b>0&&c>0&&a<200&&b<200&&c<200)
{
13 if(a+b>c&&a+c>b&&b+c>a)
{
14 if(a==b&&a==c) //F11
15. System.out.print("是等边三角形");
16. else
{
17 if(a==b||b==c||a==c) //14
18 sign1=1;
19 if(a*a+b*b==c*c||a*a==b*b+c*c||b*b==c*c+a*a) //17
20 sign2=1;
21 if(sign1==1&&sign2==1)
22 System.out.print("是等腰直角三角形");
23 else if(sign1==0&&sign2==1)
24 System.out.print("是直角三角形");
25 else if(sign1==1&&sign2==0)
26 System.out.print("是等腰三角形");
27 else System.out.print("是一般三角形");
}
}
28 else System.out.print("not a Triangle");
}
29 else System.out.print("input is error!");
}
30.}
1.语句覆盖:
条件
1:a>0 2:b>0 3:c>0
4: a< 200 5: b<200 6:c<200
7:a+b>c 8:a+c>b 9:b+c>a
10:a=b 11:a=c 12:a=b
13:b=c 14:a=c 15: a*a+b*b==c*c 16:a*a==b*b+c*c 17:b*b==c*c+a*a 18: sign1=1 19:sign2=1 20:sign1=0 21:sign2=1
22:sign1=1 23:sign2=0
2.判定覆盖:
3.条件覆盖:
4.路径覆盖:
5.条件判定覆盖:
6.条件组合覆盖:数据流测试
基路径:
ABD
ABCF
ABCEH ABCEIJKLMN ABCEIJKLMOP ABCEIJKLMOQR ABCEIJKLMOQS
圈复杂度:6+1=7
下一天问题:
package z;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class NextDate
{
public static void main(String[] args)
{
int tomDay ,tomMonth ,tomYear ;
int day,month,year;
System.out.println("Enter today's date in the form MM DD YYYY");
Scanner input=new Scanner(System.in);
1 month=input.nextInt();
2 day=input.nextInt();
3 year=input.nextInt();
4 if(day<1||day>31||month<1||month>12||year<1812||year>2012)
{
5 System.out.println("输入错误");
}
6 else
{
7 switch(month)
{
8 case 1:
9 case 3:
10 case 5:
11 case 7:
12 case 8:
13 case 10:
14 if(day<31)
{
15 tomDay=day+1;
16 tomMonth=month;
17 tomYear=year;
18 System.out.println(month+":"+day+":"+year+"的下一天是
"+tomMonth+":"+tomDay+":"+tomYear);
}
19 else
{
20 tomDay=1;
21 tomMonth=month+1;
22 tomYear=year;
23 System.out.println(month+":"+day+":"+year+"的下一天是
"+tomMonth+":"+tomDay+":"+tomYear);
}
24 break;
25 case 4:
26 case 6:
27 case 9:
28 case 11:
29 if(day<30)
{
30 tomDay=day+1;
31 tomMonth=month;
32 tomYear=year;
33 System.out.println(month+":"+day+":"+year+"的下一天是
"+tomMonth+":"+tomDay+":"+tomYear);
}
34 else if(day==30)
{
35 tomDay=1;
36 tomMonth=month+1;
37 tomYear=year;
38 System.out.println(month+":"+day+":"+year+"的下一天是
"+tomMonth+":"+tomDay+":"+tomYear);
}
39 else
{
40 System.out.println("输入错误");
}
41 break;
42 case 12:
43 if(day<31)
{