软件测试homework3的主路径覆盖

package test;

public class test {
    void printPrimes(int n){
        int curPrime;
        int numPrimes;
        boolean isPrime;
        int [] primes = new int [43];
        primes[0]=2;
        numPrimes = 1;
        curPrime = 2;
        while ( numPrimes < n)
        {
            curPrime ++ ;
            isPrime = true;
            for ( int i = 0 ; i <= numPrimes-1 ;i++){
                if (isDivisible(primes[i],curPrime))
                {
                    isPrime = false;
                    break ;
                }
            }
            if (isPrime){
                primes[numPrimes] = curPrime ;
                numPrimes ++ ;

            }
        }

        for (int i = 0 ; i <= numPrimes -1 ; i++ )
        {
            System.out.println("Prime: " + primes[i]);
        }

    }

    boolean isDivisible(int i, int curPrime) {
        if ( curPrime % i == 0 )
            return true;
        return false;
    }
}
package test;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class testTest {
    private test t= null;
    @Before
    public void setUp() throws Exception {
        t = new test ();
    }

    @Test
    public void test() {
        t.printPrimes(0);
        t.printPrimes(3);
        t.printPrimes(5);
    }

}
时间: 2024-10-07 01:42:17

软件测试homework3的主路径覆盖的相关文章

软件测试:主路径覆盖

1.控制流图 2.使MAXPRIMES == 4时,n=5会引发越界 3.令n= 1,不满足numPrimes<n,所以不通过while的循环 4. 点覆盖{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} 5. 边覆盖{(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(5,9),(6,7),(6,8),(7,5), (8,9),(9,10),(9,11),(10,11),(11,2),(12,13),(13,14),(13,16),(14

软件测试点覆盖,边覆盖,主路径覆盖及其练习题

点覆盖:即对程序的控制流图节点进行全面覆盖. 边覆盖:设计一条路径,使程序的控制流图中所有边被覆盖. 主路径覆盖:就是对程序设计测试用例,使测试用例尽可能多的经过控制流图中的边同时不形成环. 习题: 对以下代码进行分析: package com.prime; public class Prime { public static Boolean isDivisable(int prime, int curPrime) { if (curPrime % prime == 0) { return tr

软件测试(四)主路径覆盖hw3

原题中代码 /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrime; // Value curr

实现一个主路径覆盖的测试

1.源代码: /** * Finds and prints n prime integers * Jeff Offutt, Spring 2003 */ private static void printPrimes(int n) { int curPrime; //Value currently considered for primeness int numPrimes; // Number of primes found so far; boolean isPrime; //Is curP

软件测试homework3

题目:课本49页7题a)b)c)d) 解答如下: a)PrintPrimes()方法的控制流图如下: b)例如MAXPRIMES=4时,t2=(n=5)会出现数组越界的问题. c)n=1时会出现. d)节点覆盖:{0,1,2,3,4,5,6,7,8,9,10,11,12,13} 边覆盖:{(0,1),(1,2),(1,10),(2,3),(3,4),(3,7),(4,5),(4,6),(5,7),(6,3),(7,8),(7,9),(8,9),(9,1),(10,11),            

软件测试,Homework3

软件测试,Homework3 题目 private 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

软件测试学习笔记:主路径测试

(a) (b)当将MAXPRIMES设置2到5直接时.t2=(n=5)会出现越界错误而t1=(n=3)不会 (c)当n=0或1时,程序不会经过while循环. (d) 节点覆盖 TR= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} 边覆盖 TR= {(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,5),(6,8),(8,9),(5,9),  (9,10),(9,11),(10,11),(11,12),(2,12),(12,13),

软件测试(第三次作业)——图覆盖

(a) (b) 对于测试用例t1=(n=3)和t2=(n=5),MAXPRIMES = 4时,t1不能检查出错误,而t2则会发生数组越界错. (c) 对于测试用例t3=(n=1),测试路径不经过while的循环体. (d) 节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18} 边覆盖:TR={(1,2), (2,3), (2,4), (3,5), (4,14), (5,6), (5,7), (6,8), (7,11), (7,12), (8

软件测试图覆盖

public static void printPrimes (int n) { int curPrime; int numPrimes; boolean isPrime; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (int i = 0; i <= numPrim