日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

test homework ~ coverage about method printPrimes

發布時間:2023/10/11 综合教程 96 老码农
生活随笔 收集整理的這篇文章主要介紹了 test homework ~ coverage about method printPrimes 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*******************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
******************************************************/
public static void printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far.
boolean isPrime; // Is curPrime prime?
int [] primes = new int [MAXPRIMES]; // The list of prime numbers. // Initialize 2 into the list of primes.
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes < n)
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i = 0; i <= numPrimes-1; i++)
{ // for each previous prime.
if (curPrime%primes[i]==0)
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if (isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while // Print all the primes out.
for (int i = 0; i <= numPrimes-1; i++)
{
System.out.println ("Prime: " + primes[i]);
}
} // end printPrimes

First:

a. first draw the control flow graph, and we use the online tool (processon) to draw it.
    here is the result:

b. there are two test case t1=(n=3) and t2=(n=5),if t2 is easier to find a error than t1, it can be the boundary question.

if the list size(MAXSIZE=4) is 4. then t1 cannot find this error. However t2 willl find it.

c.  t=(n=1) don't pass throught the while body and just pass while header and for loop.

d. point coverage {1,2,3,4,5,6,7,8,9,10,11,12,13}

  edge coverage {(1,2),(2,3),(3,4),(4,5),(4,6),(5,8),(5,9),(6,4),(6,7),(7,5),(8,9),(9,1),(1,10),(10,11),(11,12),(11,13),(12,11)}

prime path coverage {(1,10,11,12)

              (1,10,11,13)

              (11,12,11)

              (12,11,12)

              (1,2,3,4,5,8,9,1)

              (1,2,3,4,5,9,1)

              (1,2,3,4,6,7,5,8,9,1)

              (1,2,3,4,6,7,5,9,1) 

              (4,6,4)

             (6,4,6)}

Second: use junit to achieve the goal about prime path coverage for any program

code

package testHomework;

public class triangle {
public String typeOfTriangle (int a, int b,int c)
{
String type = "not";
if(a+b>c && a+c>b && c+a>b){
type = "scalene";
if(a==b || a==c || b==c){
type="isosceles";
if(a==b && b==c)
type="equilateral";
}
return type;
}
else{
return type;
}
}
}
package testHomework;
import static org.junit.Assert.assertEquals; import java.util.Arrays;
import java.util.Collection; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; import testHomework.triangle; @RunWith(Parameterized.class)
public class triangleTest {
private String type;
private int a;
private int b;
private int c; public triangleTest(String type, int a, int b, int c){
this.type = type;
this.a = a;
this.b = b;
this.c = c;
}
@Parameters
public static Collection prepareData(){
Object[][] object = {
{"not",1,1,2},{"equilateral",1,1,1},
{"isosceles",2,2,3},{"scalene",2,3,4}};
return Arrays.asList(object);
}
@Test
public void TestTypeOfTriangle()
{
triangle triangle = new triangle ();
assertEquals (type, triangle.typeOfTriangle(a,b,c)); } }

the test case set T={(1,1,2),(1,1,1),(2,2,3),(2,3,4)} can achieve it for prime path coverage

總結

以上是生活随笔為你收集整理的test homework ~ coverage about method printPrimes的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。