• 软件测试(四)——图覆盖


    图覆盖

    1. 综述

      图覆盖

    2. 练习题

    已知程序:

    /******************************************************* 
         * 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 (isDivisable(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]); } } // end printPrimes

    (a). printPrimes方法的控制流图为:

    (b). 对于测试用例t1=(n=3)和t2=(n=5),MAXPRIMES = 4时,t1不能检查出错误,而t2则会发生数组越界错。

    (c). 对于测试用例t3=(n=1),测试路径不经过while的循环体。

    (d). 针对printPrimes()的图列举每个节点覆盖、边覆盖和主路径覆盖的测试需求。

    节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14}

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

    主路径覆盖:TR={

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

    (1,2,3,4,5,6,8,9,10,11),

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

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

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

    (1,2,12,13,14,15),

    (1,2,12,16),

    (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,12,13,14,15),

    (3,4,5,6,8,9,11,2,12,13,14,15),

    (3,4,5,6,8,9,10,11,2,12,13,16),

    (3,4,5,6,8,9,11,2,12,13,16),

    (3,4,5,9,10,11,2,12,13,14,15),

    (3,4,5,9,11,2,12,13,14,15),

    (3,4,5,9,10,11,2,12,13,16),

    (3,4,5,9,11,2,12,13,16),

    (5,6,7,5),

    (6,7,5,9,10,11,2,12,13,14,15),

    (6,7,5,9,11,2,12,13,14,15),

    (6,7,5,9,10,11,2,12,13,16),

    (6,7,5,9,11,2,12,13,16),

    (13,14,15,13),

    (14,15,13,16)

    }

  • 相关阅读:
    「APIO2017」商旅
    【CQOI2017】小Q的表格
    【HNOI2016】树
    【NOI2018模拟】Yja
    测试
    Loj #6073.「2017 山东一轮集训 Day5」距离
    「AHOI / HNOI2017」影魔
    Loj 6068. 「2017 山东一轮集训 Day4」棋盘
    【SDOI2014】向量集
    远程服务器安装nginx
  • 原文地址:https://www.cnblogs.com/yongheng20/p/5335163.html
Copyright © 2020-2023  润新知