Question: 1. For the following code, consider the statement deletion mutation operator (SDL), which deletes a statement from a program. A mutant produced by this operator

1. For the following code, consider the statement deletion mutation operator (SDL), which deletes a statement from a program. A mutant produced by this operator is detected if there is a test that has different outputs on the original program and the mutated program. Find two instances of this operator:

An SDL mutant that causes the rep-invariant to fail. Demonstrate this with a call to repOk() from a (failing) JUnit test.

An SDL mutant that causes a method contract to be violated. Demonstrate this with a call to the relevant method from a (failing) JUnit test.

import java.util.*; // GrowList is a mutable list that only gets longer. public class GrowList  { private Map values; public GrowList() { values = new HashMap();} // add to the end of the list public void add(E o) { values.put(size(), o); } // number of values in list public int size() { return values.size(); } // get ith value in list public E get(int i) { if (! inRange(i)) throw new IndexOutOfBoundsException("GrowList.get"); return values.get(i); } // update ith value in list; return previous value or null if none public E set(int i, E o) { if (! inRange(i)) throw new IndexOutOfBoundsException("GrowList.set"); return values.put(i, o); } // private helper method private boolean inRange(int i) { return (i >= 0) && (i < size()); } public String toString() { if (size() == 0) return "[]"; String result = "["; for (int i = 0; i < size()-1; i++) { result += values.get(i) + ","; } return result + values.get(size() - 1) + "]"; } public static void main(String[] args) { GrowList list = new GrowList(); System.out.println("list is:" + list); list.add("cat"); System.out.println("list is:" + list); list.add("dog"); System.out.println("list is:" + list); list.set(1,"bat"); System.out.println("list is:" + list); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!