此测试值是否会在系统中造成感染?

Does this test value create an infection in the system?

我的测试用例值为:

List<String> string = new LinkedList();
string.add("Hello"); string.add("hi"); string.add("bye");

正在测试以下方法:

// Will return longest length of a string within the list. 
public int maxLengthOfString(List<String> listOfStrings) {
    int maxLength - Integer.MIN_VALUE;
    int index = 0;
    if (listOfStrings != null) {
        while(index < strings.size()){
            if(strings.get(index).length() > maxLength){
                maxLengthOfString = listOfStrings.get(index).length();
                index++;
            }
            index++;
        }
    }
}
return maxLengthOfString;

我以为感染了R.I.P。模型意味着程序在执行期间的某个时刻被置于无效状态。上面的列表仍然会跳过索引 1,但它不会处于无效状态,因为该方法的目的是检查最长的 String,而索引 1 不是最长的。

我的教授说这是一种感染,因为索引 1 被跳过了。

关于以下网页,这是感染吗:http://www.ironiacorp.com/apps/wiki/testing/RIP_model

它现在坏了,因为它依赖于两个条目而不是一个。这是 for-each 循环不仅会更短,而且不会有错误的地方。

        if(strings.get(index).length() > maxLength){
            maxLengthOfString = listOfStrings.get(index).length();
            index++; // skip an entry.
        }
        index++;

你可以说第一行 index++; 是错误的,但是,系统在这一点上不能保证是不正确的,对代码的一个小改动表明它可以在不改变它的情况下得到纠正。

        if(strings.get(index).length() > maxLength){
            maxLengthOfString = listOfStrings.get(index).length();
            index++; // skip an entry.
        } else
            index++;

恕我直言,代码中没有任何内容表明后面的代码无法逆转 "damage" 造成的,因此我不同意 "after executing the location which has a fault, the state of the program must be incorrect"

你应该写

public int maxLengthOfString(List<String> listOfStrings) {
    int maxLength = Integer.MIN_VALUE;
    if (listOfStrings != null)
        for(String s : listOfStrings)
            if (maxLength < s.length())
                maxLength = s.length();
     return maxLength;
}