【軟體測試】錯誤分析(homework2)

來源:互聯網
上載者:User

標籤:

1)瞭解錯誤類型:

Fault : A static defect in the software.【一個靜態在軟體中產生的錯誤。】 Failure : External, incorrect behavior with respect to the requirements or other description of the expected behavior.【外部的表現,不正確的行為,相對於預期的行為的要求或其他描述。】 Error : An incorrect internal state that is the manifestation of some fault.【不正確的內部狀態,是一種錯誤的表現形式。】  2)RIP模型:Reachability 可達性Infection 感染性Propagation 傳播性  3)Tarantula 公式:          4)程式用例分析: 要求:如下給出兩個程式,每個程式給出一個測試案例,並且這個用例出現錯誤的結果。分別回答四個問題:① 分辨錯誤(fault)。② 如果可能的話,識別出沒有執行錯誤的測試案例。③ 如果可能的話,識別出執行了錯誤但是沒有得出錯誤結論的測試案例。④ 如果可能的話,識別出一個得到error卻沒有得到failure結論的測試案例。 程式1:
 1 public int findLast (int[] x, int y) { 2  //Effects: If x==null throw NullPointerException 3  // else return the index of the last element  4  // in x that equals y. 5  // If no such element exists, return -1 6  for (int i=x.length-1; i > 0; i--) 7  { 8    if (x[i] == y) { 9      return i; }10  }11  return -1;12 }13 // test: x=[2, 3, 5]; y = 2 14 // Expected = 0

回答:

① for迴圈中的判斷條件應該是i>=0,不應該是i>0。

②  如果x=0,則不會經過for迴圈,所以不會執行錯誤的代碼位置。

③ 只要是x中和y相等大小的元素不是在x中的第一個位置,那麼就會運行了程式碼且不會報錯。

例如:x=[1,2,3,4,5] y=3,那麼就可以經過程式碼,且不會有錯誤出現。

④ 當x中元素個數只有一個時,會出現得到error卻沒有failure的情況。

 

程式2:

 1 public static int lastZero (int[] x) {  2   //Effects: if x==null throw NullPointerException 3   // else return the index of the LAST 0 in x.  4   // Return -1 if 0 does not occur in x 5   for (int i = 0; i < x.length; i++) 6   { 7     if (x[i] == 0)  8     { 9       return i; 10     }11   }12   return -1; 13 }14 15 // test: x=[0, 1, 0] 16 // Expected = 2

回答:

① for (int i = 0; i < x.length; i++) 有錯誤,應該是 for (int i = x.length-1; i >= 0; i --)

② 所有的測試案例都會經過錯誤的程式碼。

③ 當x中只有一個元素時,例如x=[1],這時會運行錯誤的程式碼卻沒有報錯。

④ 當x的數組中有0時,會出現得到error沒有failure的情況。

 

【軟體測試】錯誤分析(homework2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.