白盒测试用例练习一、为以下所示的程序段设计一组测试用例,要求分别满足语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、组合覆盖和路径覆盖,并画出相应的程序流程图。voidDoWork(intx,inty,intz){intk=0,j=0;if((x3)&&(z10)){k=x*y-1;j=sqrt(k);//语句块1}if((x==4)||(y5)){j=x*y+10;}//语句块2j=j%3;//语句块3}aYcNbeYNdx3andz10x=4ory5j=j%3j=x*y+10k=x*y-1j=sqrt(k)k=0j=0由这个流程图可以看出,该程序模块有4条不同的路径:P1:(a-c-e)P2:(a-c-d)P3:(a-b-e)P4:(a-b-d)将里面的判定条件和过程记录如下:判定条件M={x3andz10}判定条件N={x=4ory5}1、语句覆盖测试用例输入输出判定M的取值判定N的取值覆盖路径x=4,z=5,y=8k=31,j=0TTP1(a-c-e)2、判定覆盖p1和p4可以作为测试用例,其中p1作为取真的路径,p4作为取反的路径。测试用例输入输出判定M的取值判定N的取值覆盖路径x=4,z=5,y=8k=31,j=0TTP1(a-c-e)x=2,z=11,y=5k=0,j=0FFP4(a-b-d)也可以让测试用例测试路径P2和P3。相应的两组输入数据如下:测试用例输入输出判定M的取值判定N的取值覆盖路径x=5,z=5,y=4k=19,j=sqrt(19)%3TFP2(a-c-d)x=4,z=11,y=6k=0,j=1FTP3(a-b-e)3、条件覆盖对于M:x3取真时T1,取假时F1;z10取真时T2,取假时F2;对于N:x=4取真时T3,取假时F3;y5取真时T4,取假时F4。条件:x3,z10,x=4,y5条件:x=3,z=10,x!=4,y=5根据条件覆盖的基本思路,和这8个条件取值,组合测试用例如表所示:测试用例输入输出取值条件具体取值条件覆盖路径x=4,z=5,y=8k=31,j=0T1,T2,T3,T4x3,z10,x=4,y5P1(a-c-e)x=3,z=11,y=5k=0,j=0F1,F2,F3,F4x=3,z=10,x!=4,y=5P4(a-b-d)4、判定/条件覆盖测试用例输入输出取值条件具体取值条件覆盖路径x=4,z=5,y=8k=31,j=0T1,T2,T3,T4x3,z10,x=4,y5P1(a-c-e)x=3,z=11,y=5k=0,j=0F1,F2,F3,F4x=3,z=10,x!=4,y=5P4(a-b-d)5、组合覆盖条件组合1)x3,z102)x3,z=103)x=3,z104)x=3,z=105)x=4,y56)x=4,y=57)x!=4,y58)x!=4,y=5测试用例输入输出覆盖条件取值覆盖条件组合覆盖路径x=4,z=5,y=6k=23,j=1T1,T2,T3,T41,5P1(a-c-e)x=4,z=10,y=5k=0,j=0T1,F2,T3,F42,6P2(a-c-d)x=3,z=5,y=6k=14j=1F1,T2,F3,T43,7P3(a-b-e)z=3,z=10,y=5k=0,j=2F1,F2,F3,F44,8P4(a-b-d)6、路径覆盖测试用例输入输出覆盖条件取值覆盖条件组合覆盖路径x=4,z=5,y=8k=31,j=0T1,T2,T3,T41,5P1(a-c-e)x=5,z=5,y=4k=19,j=sqrt(19)%3T1,T2,F3,F41,8P2(a-c-d)x=4,z=11,y=6k=0,j=1T1,F2,T3,T42,5P3(a-b-e)x=2,z=11,y=5k=0,j=0F1,F2,F3,F44,8P4(a-b-d)二、冒泡法排序:#includestdio.hmain(){inti,j,temp;inta[10];for(i=0;i10;i++)scanf(%d,,&a[i]);for(j=0;j=9;j++){for(i=0;i10-j;i++)if(a[i]a[i+1]){temp=a[i];a[i]=a[i+1];a[i+1]=temp;}}for(i=0;i10;i++)printf(%5d,,a[i]);printf(\n);}2、程序流程图定义变量i,j,temp,a[10]输入要排序的一组元素j9i10-jj=j+1i=i+1a[i]a[i+1]NYNtamp=a[i]a[i]=a[i+1]a[i+1]=temp结束YNYi=0,j=0123456789912345673白盒测试:3.1语句覆盖测试用例测试输入覆盖对象测试结果I=0,j=01,4,3,2,5,7,6,8,9,111,2,4,5,6,3,71,2,3,4,5,6,7,8,9,113.2判定覆盖测试用例测试输入覆盖对象测试结果I=0,j=01,4,3,2,5,7,6,8,9,111,2,6,7,8,9,4,5,31,2,3,4,5,6,7,8,9,113.3条件覆盖测试用例测试输入覆盖对象测试结果I=0,j=01,4,3,2,5,7,6,8,9,111,2,6,7,8,9,4,5,31,2,3,4,5,6,7,8,9,113.4路径覆盖测试用例测试输入覆盖对象测试结果I=0,j=01,4,3,2,5,7,6,8,9,111,2,6,7,8,9,4,5,31,2,3,4,5,6,7,8,9,11