软件测试HW3
- 如图
![](http://i.imgur.com/r0290l3.jpg)
- 数组越界错误,从代码可以以看出数组是预先定义的,可能出现越界问题
- n=1
- 主路径:[[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());
}
}