WIP task 2

This commit is contained in:
Michael Chen 2022-07-04 19:43:35 +02:00
parent 606ecf8fb1
commit b10388b9b1
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB
3 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,17 @@
import org.junit.Assert;
import org.junit.Test;
public class DurationTest {
@Test
public void testToStringCORMutation() {
// Killed 4,5
Assert.assertEquals("PT-0.999999999S",
new Duration(-1, 1).toString());
// Killed 1,3,4,6,7
Assert.assertEquals("PT-1S",
new Duration(-1, 0).toString());
// Killed 1,3,4,6,8
Assert.assertEquals("PT0.000000001S",
new Duration(0, 1).toString());
}
}

View File

@ -4,7 +4,7 @@ name = MichaelChen
solutionname = Solution_Phase$(phase)_$(name) solutionname = Solution_Phase$(phase)_$(name)
target = $(solutionname)_V$(version).zip target = $(solutionname)_V$(version).zip
package = $(solutionname).pdf Duration.java Mutation_Testing_Sample_Model.xml package = $(solutionname).pdf Duration.java DurationTest.java Mutation_Testing_Sample_Model.xml
latexmkflags = latexmkflags =
.PHONY : all dev .PHONY : all dev

View File

@ -152,22 +152,46 @@
\item Select \textit{one} mutation operator from Table~\ref{table:operators} (the operators are taken from \textit{Introduction to Software Testing} by Ammann and Offutt), and apply it \textit{once} to every occurrence of a target expression, statement or instruction inside the given \texttt{toString()} method (e.g., choose the \textit{SOR} operator, and for each \verb|<<|, \verb|>>|, or \verb|>>>| that occurs in the method, replace it with \textit{one} other shift operator). The operator has to be applicable to at least two parts of the code. For each mutation, document the line, original epression, and mutated expression. \item Select \textit{one} mutation operator from Table~\ref{table:operators} (the operators are taken from \textit{Introduction to Software Testing} by Ammann and Offutt), and apply it \textit{once} to every occurrence of a target expression, statement or instruction inside the given \texttt{toString()} method (e.g., choose the \textit{SOR} operator, and for each \verb|<<|, \verb|>>|, or \verb|>>>| that occurs in the method, replace it with \textit{one} other shift operator). The operator has to be applicable to at least two parts of the code. For each mutation, document the line, original epression, and mutated expression.
\begin{answer} \begin{answer}
[TODO: Add answer here] Here are the applications of the mutation operator ROR. All the mutation rules you have provided in Table~\ref{table:operators} differ from the definitions in \textit{Introduction to Software Testing} by Ammann and Offutt. The textbook definition requires all operators to be replaced by all other operators (and \textit{trueOp} and \textit{falseOp}), whereas your formal definition only requires the \verb|>| to be replaced (see left side of the production). Even though your definition is not precisely correct i have listed the missing mutations to the textbook definition in the lower part of the table.
\begin{center}
\begin{tabular}{r|c|c}
Line & Ground String & Mutant \\ \hline \hline
32 & \verb|buf.length() > 2| & \verb|buf.length() != 2| \\
35 & \verb|nanos > 0| & \verb|nanos < 0| \\
44 & \verb|nanos > 0| & \verb|true| \\ \hline
18 & \verb|this == ZERO| & \verb|this > ZERO| \\
26 & \verb|hours != 0| & \verb|hours == 0| \\
29 & \verb|minutes != 0| & \verb|minutes < 0| \\
32 & \verb|secs == 0| & \verb|false| \\
32 & \verb|nanos == 0| & \verb|nanos > 0| \\
35 & \verb|secs < 0| & \verb|secs == 0| \\
36 & \verb|secs == -1| & \verb|secs <= -1| \\
46 & \verb|secs < 0| & \verb|secs >= 0| \\
20 & \verb|lastChar(buf) == '0'| & \verb|lastChar(buf) != '0'|
\end{tabular}
\end{center}
\end{answer} \end{answer}
\item Select \textit{one} other mutation operator, and apply all of its concrete mutations to \textit{one} target expression, statement or instruction inside the given \texttt{toString()} method (e.g., choose the \textit{SOR} operator, and replace one occurring \verb|<<| with the other shift operators \verb|>>| and \verb|>>>|). Document the line, original epression, and mutated expressions. \item Select \textit{one} other mutation operator, and apply all of its concrete mutations to \textit{one} target expression, statement or instruction inside the given \texttt{toString()} method (e.g., choose the \textit{SOR} operator, and replace one occurring \verb|<<| with the other shift operators \verb|>>| and \verb|>>>|). Document the line, original epression, and mutated expressions.
\begin{answer} \begin{answer}
[TODO: Add answer here] The predicate \verb|secs < 0 && nanos > 0| in line~35 results in the following mutations when applying COR:
\begin{enumerate}
\item \verb+secs < 0 || nanos > 0+
\item \verb+secs < 0 & nanos > 0+
\item \verb+secs < 0 | nanos > 0+
\item \verb+secs < 0 ^ nanos > 0+
\item \verb+false+
\item \verb+true+
\item \verb+secs < 0+
\item \verb+nanos > 0+
\end{enumerate}
\end{answer} \end{answer}
\item Pick one set of method mutations (either the mutations of task 2a or 2b), and provide a minimum set of tests that kill all introduced mutants \textit{strongly} (\textit{Strong Mutation Coverage (SMC)}). If that is not possible for a concrete mutant, explain why, and kill that mutant \textit{weakly} (\textit{Weak Mutation Coverage (WMC)}) instead. If neither of that is possible, explain it as well. \item Pick one set of method mutations (either the mutations of task 2a or 2b), and provide a minimum set of tests that kill all introduced mutants \textit{strongly} (\textit{Strong Mutation Coverage (SMC)}). If that is not possible for a concrete mutant, explain why, and kill that mutant \textit{weakly} (\textit{Weak Mutation Coverage (WMC)}) instead. If neither of that is possible, explain it as well.
\begin{answer} \begin{answer}
[TODO: Add answer here] The following test case kills all mutations from the COR set from task~2b except the second mutation, because for boolean values the \verb|&| operator is similar to the \verb|&&| operator, thus we have an equivalent mutant.
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip] \lstinputlisting[language=Java,firstline=5,lastline=16,belowskip=-0.8\baselineskip]{DurationTest.java}
/* Add code here */
\end{lstlisting}
% or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java}
\end{answer} \end{answer}
\item For the \textit{other} set of method mutations, provide a minimum set of tests that kill the mutants only \textit{weakly}, but \textbf{not} \textit{strongly}. If that is not possible for a concrete mutant, explain why, and kill the mutants \textit{strongly} instead. If that is not possible as well, explain it. \item For the \textit{other} set of method mutations, provide a minimum set of tests that kill the mutants only \textit{weakly}, but \textbf{not} \textit{strongly}. If that is not possible for a concrete mutant, explain why, and kill the mutants \textit{strongly} instead. If that is not possible as well, explain it.