zoukankan      html  css  js  c++  java
  • 软件测试作业四 —— 课后习题七及扩展

     1 /******************************************************* 
     2      * Finds and prints n prime integers 
     3      * Jeff Offutt, Spring 2003 
     4      ******************************************************/ 
     5     public static void printPrimes (int n) 
     6     { 
     7         int curPrime; // Value currently considered for primeness 
     8         int numPrimes; // Number of primes found so far. 
     9         boolean isPrime; // Is curPrime prime? 
    10         int [] primes = new int [MAXPRIMES]; // The list of prime numbers. 
    11         
    12         // Initialize 2 into the list of primes. 
    13         primes [0] = 2; 
    14         numPrimes = 1; 
    15         curPrime = 2; 
    16         while (numPrimes < n) 
    17         { 
    18             curPrime++; // next number to consider ... 
    19             isPrime = true; 
    20             for (int i = 0; i <= numPrimes-1; i++) 
    21             { // for each previous prime. 
    22                 if (curPrime%primes[i]==0) 
    23                 { // Found a divisor, curPrime is not prime. 
    24                     isPrime = false; 
    25                     break; // out of loop through primes. 
    26                 } 
    27             } 
    28             if (isPrime) 
    29             { // save it! 
    30                 primes[numPrimes] = curPrime; 
    31                 numPrimes++; 
    32             } 
    33         } // End while 
    34         
    35         // Print all the primes out. 
    36         for (int i = 0; i <= numPrimes-1; i++) 
    37         { 
    38             System.out.println ("Prime: " + primes[i]); 
    39         } 
    40     } // end printPrimes

    (a)Draw the control flow graph

    (b)Design a simple fault that t2 would be more likely to discover than t1 would.

    (c)Find a test case that connects the beginning of the while statement to for statement without going through the body of while loop.

    (d)Enumerate the test requirements for node coverage, edge coverage, and prime path coverage.

     PS: 实现一个主路径覆盖的例子在junit下;

    Solutions


    A).


    B). Consider that if the global variable MAXPRIMES is equal to 4;

    Case t1 (n = 3) will get 3 locations in array primes. Case t2 (n = 5) will get 5 locations in array primes, while the maximum locations of primes is 4 and primes is overflow.

     


     

    C). Consider that n is equal to 1.

     


     

    D). TR for NC: { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }

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

    TR for PPC:

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

    [1,2,3,5,6,10,7,11];

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

    [1,2,3,5,7,11];

    [1,2,3,5,7,8,11];

    [1,2,12,13,14];

    [1,2,12,13,15];

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

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

    [3,4,5,6,10,7,11,2,12,13,14];

    [3,4,5,6,10,7,11,2,12,13,15];

    [3,4,5,7,11,2,12,13,15];

    [3,4,5,7,11,2,12,13,14];

    [3,4,5,7,8,11,2,12,13,15];

    [3,4,5,7,8,11,2,12,13,14];

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

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

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

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

    [14,13,15];

    [2,3,4,5,6,10,7,11,2];   (All combinations)

    [2,3,4,5,6,10,7,8,11,2] ; (All combinations)

    [2,3,4,5,7,11,2]; (All combinations)

    [2,3,4,5,7,8,11,2]; (All combinations)

    [13,14,13]; (All combinations)

    [5,6,9,5]; (All combinations)

     


     

    PC题:如上次实验的三角形类型判断;

     

    函数judge()是一个三分支的判断结构,那么主路径测试需求也只有三个;即覆盖这三种情况即可;

  • 相关阅读:
    linux学习8 运维基本功-Linux获取命令使用帮助详解
    持续集成学习11 jenkins和gitlab集成自动触发
    持续集成学习10 Pipline初探
    持续集成学习9 jenkins执行脚本
    持续集成学习8 jenkins权限控制
    持续集成学习7 jenkins自动化代码构建
    持续集成学习6 jenkins自动化代码构建
    持续集成学习5 jenkins自动化测试与构建
    持续集成学习4 jenkins常见功能
    【Hadoop离线基础总结】MapReduce增强(下)
  • 原文地址:https://www.cnblogs.com/Elson8080/p/5328362.html
Copyright © 2011-2022 走看看