zoukankan      html  css  js  c++  java
  • ST HW3

    7. Use the following method printPrimes() for questions a-f below.

    /******************************************************* 
         * Finds and prints n prime integers 
         * Jeff Offutt, Spring 2003 
         ******************************************************/ 
        public String 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 [MAXSIZE]; // 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 (isDivisible(primes[i],curPrime)) 
                    { // 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]); 
                result = result + primes[i] + " ";
            }
        } // end printPrimes
    }

    (a)     Draw the control flow graph for the printPrime() method.

    Node 15 is the ending node, but I can't make it a Concentric circle.

     

    (b)    Consider test cases t1=(n=3) and t2=(n=5). Although these tour the same prime paths in ptintPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t1 would.

     When MAXPRIME = 3 or 4, t2 will overflow but it is OK for t1.

    (c)     For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement withtout going through the body of the while loop.

                         t = (n=1)

    (d)

    Node Coverage:

    TR = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}

    Test Path:[1, 2, 3, 4, 5, 6, 7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14, 13, 15]

    Edge Coverage:

    TR = {(1,2), (2,3), (3,4), (4,5), (5,6), (5,9), (6,7), (7,5) , (6,8), (8,9), (9,10), (10,11), (9,11), (11,2), (2,12), (12,13), (13,14), (14,13), (13,15)}

    Test Path: [1, 2, 3, 4, 5, 6, 7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14, 13, 15]

    [1, 2, 3, 4, 5, 9, 11, 2, 12, 13, 14, 13, 15]

    Prime Path Coverage:

    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

    [1, 2, 3, 4, 5, 6, 7, 8, 9, 11]

    [1, 2, 3, 4, 5, 6, 7]

    [1, 2, 3, 4, 5, 9, 10, 11]

    [1, 2, 3, 4, 5, 9, 11]

    [1, 2, 12, 13, 14]

    [1, 2, 12, 15]

    [2, 3, 4, 5, 6, 8, 9, 10, 11, 2]

    [2, 3, 4, 5, 6, 8, 9, 11, 2]

    [2, 3, 4, 5, 9, 10, 11, 2]

    [2, 3, 4, 5, 9, 11, 2]

    [3, 4, 5, 6, 8, 9, 10, 11, 2, 3]

    [3, 4, 5, 6, 8, 9, 11, 2, 3]

    [3, 4, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14]

    [3, 4, 5, 6, 8, 9, 11, 2, 12, 13, 14]

    [3, 4, 5, 6, 8, 9, 10, 11, 2, 12, 13, 15]

    [3, 4, 5, 6, 8, 9, 11, 2, 12, 13, 15]

    [3, 4, 5, 9, 10, 11, 2, 12, 13, 14]

    [3, 4, 5, 9, 11, 2, 12, 13, 14]

    [3, 4, 5, 9, 11, 2, 12, 13, 15]

    [3, 4, 5, 9, 10, 11, 2, 12, 13, 15]

    [4, 5, 6, 8, 9, 10, 11, 2, 3, 4]

    [4, 5, 6, 8, 9, 11, 2, 3, 4]

    [4, 5, 9, 11, 2, 3, 4]

    [4, 5, 9, 10, 11, 2, 3, 4]

    [5, 6, 8, 9, 10, 11, 2, 3, 4, 5]

    [5, 6, 8, 9, 11, 2, 3, 4, 5]

    [5, 9, 10, 11, 2, 3, 4, 5]

    [5, 9, 11, 2, 3, 4, 5]

    [5, 6, 7, 5]

    [6, 8, 9, 10, 11, 2, 3, 4, 5, 6]

    [6, 8, 9, 11, 2, 3, 4, 5, 6]

    [6, 7, 5, 6]

    [7, 5, 6, 7]

    [7, 5, 6, 8, 9, 10, 11, 2, 3, 4]

    [7, 5, 6, 8, 9, 11, 2, 3, 4]

    [7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14]

    [7, 5, 6, 8, 9, 11, 2, 12, 13, 14]

    [7, 5, 6, 8, 9, 11, 2, 12, 13, 15]

    [7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 15]

    [7, 5, 9, 10, 11, 2, 3, 4]

    [7, 5, 9, 11, 2, 3, 4]

    [7, 5, 9, 10, 11, 2, 12, 13, 14]

    [7, 5, 9, 11, 2, 12, 13, 14]

    [7, 5, 9, 10, 11, 2, 12, 13, 15]

    [7, 5, 9, 11, 2, 12, 13, 15]

    [8, 9, 10, 11, 2, 3, 4, 5, 6, 7]

    [8, 9, 11, 2, 3, 4, 5, 6, 7]

    [8, 9, 10, 11, 2, 3, 4, 5, 6, 8]

    [8, 9, 11, 2, 3, 4, 5, 6, 8]

    [9, 10, 11, 2, 3, 4, 5, 6, 8, 9]

    [9, 11, 2, 3, 4, 5, 6, 8, 9]

    [9, 10, 11, 2, 3, 4, 5, 9]

    [9, 11, 2, 3, 4, 5, 9]

    [10, 11, 2, 3, 4, 5, 6, 8, 9, 10]

    [10, 11, 2, 3, 4, 5, 9, 10]

    [11, 2, 3, 4, 5, 6, 8, 9, 10, 11]

    [11, 2, 3, 4, 5, 6, 8, 9, 11]

    [11, 2, 3, 4, 5, 9, 10, 11]

    [11, 2, 3, 4, 5, 9, 11]

    [13, 14, 13]

    [14, 13, 14]

    [14, 13, 15]

    基于JunitEclemmajacoco)实现一个主路径覆盖的测试 

    My Codes:

    https://github.com/newff/st-lab1/tree/newff-hw-3

    /**
     * 
     */
    package printPrime;
    
    import static org.junit.Assert.*;
    
    import org.junit.Before;
    import org.junit.Test;
    
    /**
     * @author lonely
     *
     */
    public class printPrimeTest {
    
    	private printPrime printPrime;
    
    	/**
    	 * @throws java.lang.Exception
    	 */
    	@Before
    	public void setUp() throws Exception {
    		printPrime = new printPrime();
    	}
    
    	/**
    	 * Test method for {@link printPrime.printPrime#printPrimes(int)}.
    	 */
    	@Test
    	public void testPrintPrimes() {
    //		assertEquals("2 3 ",printPrime.printPrimes(2));
    //		assertEquals("2 3 5 ",printPrime.printPrimes(3));
    		assertEquals("2 3 5 7 ",printPrime.printPrimes(4));
    	}
    
    }
    

      when n = 2

    when n >= 3

    if MAXPRIME = 3, n = 4

  • 相关阅读:
    Data Base mysql备份与恢复
    java 乱码问题解决方案
    【知识强化】第二章 物理层 2.1 通信基础
    【知识强化】第二章 进程管理 2.2 处理机调度
    【知识强化】第二章 进程管理 2.1 进程与线程
    【知识强化】第一章 操作系统概述 1.3 操作系统的运行环境
    【知识强化】第一章 网络体系结构 1.1 数据结构的基本概念
    【知识强化】第一章 网络体系结构 1.2 计算机网络体系结构与参考模型
    【知识强化】第一章 网络体系结构 1.1 计算机网络概述
    【知识强化】第一章 操作系统概述 1.1 操作系统的基本概念
  • 原文地址:https://www.cnblogs.com/newff/p/6550140.html
Copyright © 2011-2022 走看看