HW3 printPrimes函数主路径测试

软件测试HW3


  1. 如图
  2. 数组越界错误,从代码可以以看出数组是预先定义的,可能出现越界问题
  3. n=1
  4. 主路径:[[11, 12, 11], [12, 11, 12], [12, 11, 13], [1, 2, 11, 13], [5, 6, 9, 5], [6, 9, 5, 6], [9, 5, 6, 9], [2, 3, 4, 5, 8, 10, 14, 2], [3, 4, 5, 8, 10, 14, 2, 3], [4, 5, 8, 10, 14, 2, 3, 4], [5, 8, 10, 14, 2, 3, 4, 5], [8, 10, 14, 2, 3, 4, 5, 8], [10, 14, 2, 3, 4, 5, 8, 10], [14, 2, 3, 4, 5, 8, 10, 14], [3, 4, 5, 8, 10, 14, 2, 11, 13], [6, 9, 5, 8, 10, 14, 2, 11, 13], [2, 3, 4, 5, 6, 7, 8, 10, 14, 2], [3, 4, 5, 6, 7, 8, 10, 14, 2, 3], [4, 5, 6, 7, 8, 10, 14, 2, 3, 4], [5, 6, 7, 8, 10, 14, 2, 3, 4, 5], [6, 7, 8, 10, 14, 2, 3, 4, 5, 6], [9, 5, 6, 7, 8, 10, 14, 2, 11, 13], [7, 8, 10, 14, 2, 3, 4, 5, 6, 7], [8, 10, 14, 2, 3, 4, 5, 6, 7, 8], [10, 14, 2, 3, 4, 5, 6, 7, 8, 10], [14, 2, 3, 4, 5, 6, 7, 8, 10, 14], [3, 4, 5, 6, 7, 8, 10, 14, 2, 11, 13]]。

计算主路径python代码(有错误请指出):


start={}
result=[]
#输入两个节点组成的路径
start[2]=[[1,2],[2,3],[2,11],[3,4],[4,5],[5,6],[5,8],[6,7],[6,9],[9,5],[7,8],[8,10],[8,15],[10,14],[14,2],[11,12],[12,11],[11,13]]
#start[2]=[[0,1],[0,2],[1,2],[2,3],[2,4],[3,6],[4,6],[4,5],[5,4]]
for i in range(3,15):
    start[i]=[];
    for j in start[i-1]:
        for k in start[2]:
            if j[-1] == k[0]:
                temp = j+[k[-1]]
                if(13 in temp): #终止节点判断
                    result.append(temp)
                elif(len(temp)!=len(set(temp))):
                    result.append(temp)
                else:
                    start[i].append(temp)


#删除内部成环的节点,不是头尾连接的
temp = result.copy();
for list in result:
    for index in range(1,len(list)-1):
        if(list[-1] != list[0] and [list[-1],list[index]] in start[2]):
            temp.remove(list)
            break
#从备选集求得主路径
final = temp.copy()
for list1 in temp:
    for list2 in temp:
        isDelete = 0
        if(len(list1) < len(list2)):
            for index in range(0,len(list2)-len(list1)+1):
                templist = list2[index:index+len(list1)]
                if(list1 == templist):
                    final.remove(list1)
                    isDelete = 1
        if(isDelete):
            break
print(final)

主路径覆盖测试代码


package com.prime;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class testNumPrime {
    PrintStream console = null;
    ByteArrayOutputStream bytes = null;
    numPrime np;

    @Before
    public void setUp() throws Exception {
        np = new numPrime();
        bytes = new ByteArrayOutputStream();
        console = System.out;

        System.setOut(new PrintStream(bytes));
    }

    @After
    public void tearDown() throws Exception {
        System.setOut(console);
    }

    @Test
    public void test1() {
        np.printPrimes(1);
        assertEquals("2 ", bytes.toString());
    }
    @Test
    public void test2() {
        np.printPrimes(3);
        assertEquals("2 3 5 ", bytes.toString());
    }
    @Test
    public void test3() {
        np.printPrimes(5);
        assertEquals("2 3 5 7 11 ", bytes.toString());
    }
}

转载于:https://www.cnblogs.com/faith30/p/6547336.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值