Solved task 2

This commit is contained in:
Michael Chen 2022-05-18 22:07:39 +02:00
parent 18a1b3ad44
commit 7aade7fac7
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB

View File

@ -136,14 +136,15 @@
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick] \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
\tikzstyle{every state}=[fill=gray,draw=none,text=white] \tikzstyle{every state}=[fill=gray,draw=none,text=white]
\node[initial,state] (s0) {\texttt{.ctor}}; \node[initial,state] (s0) {$s_0$};
\node[state] (s1) [below of=s0] {$s_1$}; \node[state] (s1) [below of=s0] {$s_1$};
\node[state] (s2) [right of=s1] {$s_2$}; \node[state] (s2) [right of=s1] {$s_2$};
\node[state] (s3) [below of=s1] {$s_3$}; \node[state] (s3) [below of=s1] {$s_3$};
\node[state] (s4p) [below of=s3] {$s_{4,p}$}; \node[state] (s3s) [below of=s3] {$s_{3,s}$};
\node[state] (s4p) [below of=s3s] {$s_{4,p}$};
\node[state] (s4) [right of=s4p] {$s_4$}; \node[state] (s4) [right of=s4p] {$s_4$};
\node[state] (s5) [right of=s4] {$s_5$}; \node[state] (s5) [right of=s4] {$s_5$};
\node[state] (s6) [below of=s4] {\texttt{.ret}}; \node[state] (s6) [below of=s4] {$s_6$};
\node[state] (throw) [right of=s2] {\texttt{throw}}; \node[state] (throw) [right of=s2] {\texttt{throw}};
\path \path
@ -152,8 +153,10 @@
(s1) edge node {$\texttt{iC} > \texttt{MAX}$} (s2) (s1) edge node {$\texttt{iC} > \texttt{MAX}$} (s2)
(s1) edge node {$\texttt{iC} \leq \texttt{MAX}$} (s3) (s1) edge node {$\texttt{iC} \leq \texttt{MAX}$} (s3)
(s2) edge [bend left] node {} (s3) (s2) edge [bend left] node {} (s3)
(s3) edge node {} (s4p) (s3) edge node {$\texttt{lF} > 0$} (s3s)
(s3) edge [bend right] node [right] {$\texttt{lF} \leq 0 \lor \texttt{lF} \equiv \texttt{NaN}$} (throw) (s3) edge [bend right] node {$\texttt{lF} \leq 0$} (throw)
(s3s) edge node {$\texttt{lF} \not\equiv \texttt{NaN}$} (s4p)
(s3s) edge [bend right] node {$\texttt{lF} \equiv \texttt{NaN}$} (throw)
(s4p) edge node {} (s4) (s4p) edge node {} (s4)
(s4) edge [bend left] node {$\texttt{c} < \texttt{iC}$} (s5) (s4) edge [bend left] node {$\texttt{c} < \texttt{iC}$} (s5)
(s4) edge node {$\texttt{c} \geq \texttt{iC}$} (s6) (s4) edge node {$\texttt{c} \geq \texttt{iC}$} (s6)
@ -165,34 +168,35 @@
\item Create a minimum set of test cases that reaches 100\% coverage for the instruction coverage criterion. \item Create a minimum set of test cases that reaches 100\% coverage for the instruction coverage criterion.
\begin{answer} \begin{answer}
[TODO: Add answer here] This test set covers both throw instructions and the statement in the loop and the second \texttt{if} statement. The minimal amount of test inputs for statement coverage consists of at least three tests because there are three exit points to the function (the return and both of the throws) so this is the minimum amount of tests necessary.
\begin{center}
\begin{tabular}{r|r|c}
\texttt{initialCapacity} & \texttt{loadFactor} & Instruction Coverage \\ \hline \hline
-1 & 2.0f & $throw_1$ \\
8 & \texttt{NaN} & $throw_2$ \\
1025 & 2.0f & $s_1, s_2, s_3, s_4, s_5, s_6$
\end{tabular}
\end{center}
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip]
/* Add code here */
\end{lstlisting}
% or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java} % or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java}
\end{answer} \end{answer}
\item Extend the set of test cases so that it additionally reaches 100\% coverage for the branch coverage criterion. Describe the necessity of the added tests. \item Extend the set of test cases so that it additionally reaches 100\% coverage for the branch coverage criterion. Describe the necessity of the added tests.
\begin{answer} \begin{answer}
[TODO: Add answer here] To reach 100\% branch coverage from the above test set, you need to add a test where the \texttt{loadFactor} is less than or equal to zero to account for the branch that occurs in the disjunction in the third \texttt{if} statement due to short circuit evaluation of the condition. Apart from that the above test set already satisfies branch coverage, because the second and third input execute both branches from the $s_1$ branch and the first two tests branch at the throw instructions. The last output runs all branches in the loop branch in $s_4$.
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip]
/* Add code here */
\end{lstlisting}
% or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java}
\end{answer} \end{answer}
\item Analyze the code regarding the following data flow criteria, and list all relevant DU pairs. Does your test suite require additional tests to cover them? \item Analyze the code regarding the following data flow criteria, and list all relevant DU pairs. Does your test suite require additional tests to cover them?
\begin{enumerate} \begin{enumerate}
\item All-defs with respect to \texttt{capacity} \item All-defs with respect to \texttt{capacity}
\begin{answer} \begin{answer}
[TODO: Add answer here] \texttt{capacity} is first initialized in $s_{4,p}$ and then defined in $s_5$ and used in states $s_5$ and $s_6$.
The relevant DU pairs are thus: $(s_{4,p}, s_5), (s_{4,p}, s_6), (s_5, s_6)$. The pair $(s_{4,p}, s_6)$ is currently not covered by our test set because the current path that is taken between these two nodes is not def-free in node $s_5$ with respect to def-use paths. To achieve this we would have to input a valid \texttt{loadFactor} with a $\texttt{capacity} \geq \texttt{initialCapacity}$ such that the loop definition is not executed. However, when we only consider def-paths The above test set is sufficient, becuase the initial definition is trivially covered by our non-throwing input and the loop definition is also covered because the loop is executed at least once (actually more than once, so both def-use paths from the loop definition are evaluated).
\end{answer} \end{answer}
\item All-uses with respect to \texttt{loadFactor} \item All-uses with respect to \texttt{loadFactor}
\begin{answer} \begin{answer}
[TODO: Add answer here] The relevant def-pairs are $(s_0, s_3), (s_0, s_{3,s}), (s_0, \texttt{throw}_2), (s_0, s_6)$. All of these are already covered by our branch initial test set becuase all usages of the \texttt{loadFactor} are covered by our instruction coverage and since there is only one definition (in the parameter section) all paths to every usage is trivially def-free and thus a DU path.
\end{answer} \end{answer}
\end{enumerate} \end{enumerate}