From b10388b9b1e60bd6cf819fa9806a1e19c2e8afe6 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Mon, 4 Jul 2022 19:43:35 +0200 Subject: [PATCH] WIP task 2 --- .../project_phase05_tasks/DurationTest.java | 17 +++++++++ .../phase_05/project_phase05_tasks/Makefile | 2 +- .../Solution_Phase05_MichaelChen.tex | 38 +++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 project_task_sheets/phase_05/project_phase05_tasks/DurationTest.java diff --git a/project_task_sheets/phase_05/project_phase05_tasks/DurationTest.java b/project_task_sheets/phase_05/project_phase05_tasks/DurationTest.java new file mode 100644 index 0000000..3341ff1 --- /dev/null +++ b/project_task_sheets/phase_05/project_phase05_tasks/DurationTest.java @@ -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()); + } +} diff --git a/project_task_sheets/phase_05/project_phase05_tasks/Makefile b/project_task_sheets/phase_05/project_phase05_tasks/Makefile index f678320..8dfc24e 100644 --- a/project_task_sheets/phase_05/project_phase05_tasks/Makefile +++ b/project_task_sheets/phase_05/project_phase05_tasks/Makefile @@ -4,7 +4,7 @@ name = MichaelChen solutionname = Solution_Phase$(phase)_$(name) 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 = .PHONY : all dev diff --git a/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex b/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex index 81f5916..474424b 100644 --- a/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex +++ b/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex @@ -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. \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} \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} - [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} \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} - [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] -/* Add code here */ - \end{lstlisting} - % or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java} + \lstinputlisting[language=Java,firstline=5,lastline=16,belowskip=-0.8\baselineskip]{DurationTest.java} \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.