Tests to Kill Mutants Consider Mutant A and Mutant B given b

Tests to Kill Mutants.

Consider Mutant A and Mutant B given below.

(An implementation is available on the http://cs.gmu.edu/~offutt/softwaretest/edition2/java/PatternIndex.java)

while (isPat == false && isub + patternLen-1 < subjectLen) // Original

while (isPat == false && isub + patternLen-0 < subjectLen) // Mutant A

isPat = false; // Original (Inside the loops, not the declaration)

isPat = true; // Mutant B

Question:

(a) If possible, design test inputs that do not reach the mutants.

(b) If possible, design test inputs that satisfy reachability but not infection for the mutants.

(c) If possible, design test inputs that satisfy reachability and infection, but not propagation for the mutants.

(d) If possible, design test inputs that strongly kill the mutants

/**
* Find index of pattern in subject string
*
* @param subject String to search
* @param pattern String to find
* @return index (zero-based) of first occurrence of pattern in subject;
* -1 if not found
* @throws NullPointerException if subject or pattern is null
*/
public static int patternIndex (String subject, String pattern)
{
final int NOTFOUND = -1;
int iSub = 0, rtnIndex = NOTFOUND;
boolean isPat = false;
int subjectLen = subject.length();
int patternLen = pattern.length();
while (isPat == false && iSub + patternLen - 1 < subjectLen)
{
if (subject.charAt (iSub) == pattern.charAt (0))
{
rtnIndex = iSub; // Starting at zero
isPat = true;
for (int iPat = 1; iPat < patternLen; iPat ++)
{
if (subject.charAt (iSub + iPat) != pattern.charAt (iPat))
{
rtnIndex = NOTFOUND;
isPat = false;
break; // out of for loop
}
}
}
iSub ++;
}
return (rtnIndex);
}

Solution

PROGRAM to TEST:

package Simple;


   // Introduction to Software Testing
   // Authors: Paul Ammann & Jeff Offutt
   // Chapters 6, 7, and 9; pages ??, ??, and ??
   // Can be run from command line
   // See PatternIndexTest.java, DataDrivenPatternIndexTest.java for JUnit tests

   public class PatternIndex
   {

   public static void main (String[] argv)
   {
   if (argv.length != 2)
   {
   System.out.println
   (\"java PatternIndex Subject Pattern\");
   return;
   }
   String subject = argv[0];
   String pattern = argv[1];
   int n = 0;
   if ((n = patternIndex (subject, pattern)) == -1)
   System.out.println
   (\"Pattern string is not a substring of the subject string\");
   else
   System.out.println
   (\"Pattern string begins at character \" + n);
   }
     
   /**
   * Find index of pattern in subject string
   *
   * @param subject String to search
   * @param pattern String to find
   * @return index (zero-based) of first occurrence of pattern in subject; -1 if not found
   * @throws NullPointerException if subject or pattern is null
   */
   public static int patternIndex (String subject, String pattern)
   {
   final int NOTFOUND = -1;
   int iSub = 0, rtnIndex = NOTFOUND;
   boolean isPat = false;
   int subjectLen = subject.length();
   int patternLen = pattern.length();
     
   while (isPat == false && iSub + patternLen - 0 < subjectLen)//Mutant A
   {
   if (subject.charAt(iSub) == pattern.charAt(0))
   {
   rtnIndex = iSub; // Starting at zero
   isPat = false; // Mutant B
   for (int iPat = 1; iPat < patternLen; iPat ++)
   {
   if (subject.charAt(iSub + iPat) != pattern.charAt(iPat))
   {
   rtnIndex = NOTFOUND;
   isPat = false;
   break; // out of for loop
   }
   }
   }
   iSub ++;
   }
   return (rtnIndex);
   }
}


Testing:

Scenarios
a) If possible, design test inputs that do not reach the mutants.

Inputs: Maths
Testing Output: java PatternIndex Subject Pattern
Explanation: only one command line argument was provided. This input did not reach the mutants at all.

b)If possible, design test inputs that satisfy reachability but not infection for the mutants.

Inputs: Maths sth
Testing output: Pattern string is not a substring of the subject string
Explanation: The mutants were reached but the output is not affected by the mutants.

Inputs: Maths Ma
testing outputs: Pattern string begins at character 0
Explanation: The mutants were reached but the output is not affected by the mutants.

c) If possible, design test inputs that satisfy reachability and infection, but not propagation for the mutants.

Inputs: Maths M
Testing output:Pattern string begins at character 0
Explanation: The program gave the current result for the provided inputs. Mutants were reached, infected but did not propagate.

d) If possible, design test inputs that strongly kill the mutants

Inputs: Math t
Testing output: Pattern string begins at character 2
Explanation: This affected the output by giving the output as 2 whereas it should have been 3.

Tests to Kill Mutants. Consider Mutant A and Mutant B given below. (An implementation is available on the http://cs.gmu.edu/~offutt/softwaretest/edition2/java/P
Tests to Kill Mutants. Consider Mutant A and Mutant B given below. (An implementation is available on the http://cs.gmu.edu/~offutt/softwaretest/edition2/java/P
Tests to Kill Mutants. Consider Mutant A and Mutant B given below. (An implementation is available on the http://cs.gmu.edu/~offutt/softwaretest/edition2/java/P

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site