软件测试 homework2
代碼段1
public int findLast (int[] x, int y) { //Effects: If x==null throw NullPointerException // else return the index of the last element // in x that equals y. // If no such element exists, return -1 for (int i=x.length-1; i > 0; i--) { if (x[i] == y) { return i; } } return -1; } // test: x=[2, 3, 5]; y = 2 // Expected = 0q1: Identify the fault
a1: 循環(huán)條件中i>0應(yīng)該改為i>=0, 如果不更改會忽略數(shù)組第一個數(shù)字
q2: If possible, identify a test case that does not execute the fault. (Reachability)
a2: test:x=[],y = 5
q3:f possible, identify a test case that executes the fault, but does not result in an error state.
a3: test: x=[2,3,5],y = 3;
q4:If possible identify a test case that results in an error, but not a failure.
a4: test: x=[2,3,5],y = 1;
代碼段2
q1: Identify the fault
a1: 循環(huán)應(yīng)該從數(shù)組末位開始,而原代碼中循環(huán)從數(shù)組首位開始,這樣找到的不是最后一個0而是第一個0
q2: If possible, identify a test case that does not execute the fault. (Reachability)
a2: x = []
q3:f possible, identify a test case that executes the fault, but does not result in an error state.
a3: x = [0]
q4:If possible identify a test case that results in an error, but not a failure.
a4: x = [1]
轉(zhuǎn)載于:https://www.cnblogs.com/IzayoiNamida/p/8570500.html
總結(jié)
以上是生活随笔為你收集整理的软件测试 homework2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA 入门(一)
- 下一篇: stm32的dma缓冲区长度,,存放数据