Merge branch 'phase03' into main

This commit is contained in:
Michael Chen 2022-05-19 09:39:34 +02:00
commit 096a3d18d4
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB
7 changed files with 877 additions and 0 deletions

View File

@ -0,0 +1,306 @@
Solution_Phase*_*.pdf
Solution_Phase*_*.zip
*.result.txt
output.txt
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs
*.slg
*.slo
*.sls
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist
# gnuplot
*.gnuplot
*.table
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.glog
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
# *.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# newpax
*.newpax
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# svg
svg-inkscape/
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# titletoc
*.ptc
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices and outlines
*.xyc
*.xyd
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# gummi
.*.swp
# KBibTeX
*~[0-9]*
# TeXnicCenter
*.tps
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# Makeindex log files
*.lpz
# xwatermark package
*.xwm
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
# Uncomment the next line to have this generated file ignored.
#*Notes.bib

View File

@ -0,0 +1,29 @@
import java.util.Map.Entry;
public class HashMap<K,V> {
static final int MAXIMUM_CAPACITY = 1 << 10;
transient Entry<K,V>[] table;
int threshold;
final float loadFactor;
public HashMap(int initialCapacity, float loadFactor) {
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity);
if (initialCapacity > MAXIMUM_CAPACITY)
initialCapacity = MAXIMUM_CAPACITY;
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new IllegalArgumentException("Illegal load factor: " + loadFactor);
// Find a power of 2 >= initialCapacity
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
this.loadFactor = loadFactor;
threshold = (int)(capacity * loadFactor);
table = new Entry[capacity];
}
public int getCapacity() {
return table.length;
}
}

View File

@ -0,0 +1,82 @@
package com.alibaba.fastjson.parser;
import com.alibaba.fastjson.JSONException;
import org.junit.Assert;
import org.junit.Test;
public class JSONScannerTest2 {
@Test
public void stringUtf8BomTest() throws Throwable {
JSONScanner scanner = new JSONScanner("\uFEFF,");
// After construction the UTF-8 BOM should be safely skipped
scanner.nextToken();
Assert.assertEquals(JSONToken.COMMA, scanner.token());
}
@Test
public void stringHasSpecialTest() throws Throwable {
JSONScanner scanner = new JSONScanner("\"\\b\\n\\t\\\"\\uABED\"");
scanner.nextToken();
Assert.assertEquals(JSONToken.LITERAL_STRING, scanner.token());
Assert.assertEquals("\b\n\t\"\uABED", scanner.stringVal());
}
@Test
public void stringWithIso8601Date() throws Throwable {
JSONScanner scanner = new JSONScanner("2012-04-23T18:25:43.511Z");
Assert.assertTrue(scanner.scanISO8601DateIfMatch());
}
@Test
public void scanSingleComment() throws Throwable {
JSONScanner scanner = new JSONScanner("//dsajfklsjfk");
scanner.nextToken();
Assert.assertTrue(scanner.isEOF());
}
@Test
public void scanMultiComment() throws Throwable {
JSONScanner scanner = new JSONScanner("/*dsajfklsjfk*/");
scanner.nextToken();
Assert.assertTrue(scanner.isEOF());
}
@Test
public void scannerSkipWhitespace() throws Throwable {
JSONScanner scanner = new JSONScanner("\n\t\t \r\b\f232");
scanner.nextToken();
Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token());
Assert.assertEquals(232, scanner.intValue());
}
@Test
public void inputTokenTest_set() throws Throwable {
JSONScanner scanner = new JSONScanner("Set[3,2,1]");
scanner.nextToken();
Assert.assertEquals(JSONToken.SET, scanner.token());
}
@Test
public void inputTokenTest_Undefined() throws Throwable {
JSONScanner scanner = new JSONScanner("undefined");
scanner.nextToken();
Assert.assertEquals(JSONToken.UNDEFINED, scanner.token());
}
@Test
public void stringWithIso8601Date_Invalid() throws Throwable {
Assert.assertTrue(new JSONScanner("2012-04-23T18:25:43.511Z").scanISO8601DateIfMatch());
Assert.assertFalse(new JSONScanner("2012-04-32T18:25:43.511Z").scanISO8601DateIfMatch());
Assert.assertFalse(new JSONScanner("2012-00-23T18:25:43.511Z").scanISO8601DateIfMatch());
Assert.assertFalse(new JSONScanner("2012-13-23T18:25:43.511Z").scanISO8601DateIfMatch());
}
@Test
public void inputTokenTest_ExplPosInt() throws Throwable {
JSONScanner scanner = new JSONScanner("+7531"); // explicit positive with sign
scanner.nextToken();
Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token());
Assert.assertEquals(7531, scanner.intValue());
}
}

View File

@ -0,0 +1,21 @@
phase = 03
version = 1
name = MichaelChen
solutionname = Solution_Phase$(phase)_$(name)
target = $(solutionname)_V$(version).zip
package = $(solutionname).pdf HashMap.java JSONScannerTest2.java
latexmkflags =
.PHONY : all dev
all : $(target)
dev : latexmkflags = -pvc
dev : all
$(target) : $(package)
zip -FSr $(target) $(package)
%.pdf : %.tex
latexmk -jobname="$*" $(latexmkflags) -pdf $<

View File

@ -0,0 +1,228 @@
\documentclass[a4paper]{scrreprt}
\usepackage[left=4cm,bottom=3cm,top=3cm,right=4cm,nohead,nofoot]{geometry}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{listings}
\usepackage{enumitem}
\usepackage{subcaption}
\usepackage[acronym]{glossaries}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\newacronym{nc}{NC}{node coverage}
\newacronym{ec}{EC}{edge coverage}
\newacronym{adupc}{ADUPC}{all-du-path coverage}
\newacronym{ppc}{PPC}{prime path coverage}
\newacronym{auc}{AUC}{all-uses coverage}
\newacronym{adc}{ADC}{all-defs coverage}
\newacronym{srtc}{SRTC}{simple round-trip coverage}
\newacronym{crtc}{CRTC}{complete round-trip coverage}
\usepackage{xparse}
\usepackage{multirow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\textfloatsep}{16pt}
\renewcommand{\labelenumi}{\alph{enumi})}
\renewcommand{\labelenumii}{\arabic{enumii}) }
\newcommand{\baseinfo}[5]{
\begin{center}
\begin{tabular}{p{15cm}r}
\vspace{-4.5pt}{ \Large \bfseries #1} & \multirow{2}{*}{} \\[0.4cm]
#2 & \\[0.5cm]
\end{tabular}
\end{center}
\vspace{-18pt}\hrule\vspace{6pt}
\begin{tabular}{ll}
\textbf{Name:} & #4\\
\textbf{Group:} & #5\\
\end{tabular}
\vspace{4pt}\hrule\vspace{2pt}
\footnotesize \textbf{Software Testing} \hfil - \hfil Summer 2022 \hfil - \hfil #3 \hfil - \hfil Sibylle Schupp / Sascha Lehmann \hfil \\
}
\newcounter{question}
\NewDocumentEnvironment{question}{m o}{%
\addtocounter{question}{1}%
\paragraph{\textcolor{red}{Task~\arabic{question}} - #1\hfill\IfNoValueTF{#2}{}{[#2 P]}}
\leavevmode\\%
}{%
\vskip 1em%
}
\NewDocumentEnvironment{answer}{}{%
\vspace{6pt}
\leavevmode\\
\textit{Answer:}\\[-0.25cm]
{\color{red}\rule{\textwidth}{0.4mm}}
}{%
\leavevmode\\
{\color{red}\rule{\textwidth}{0.4mm}}
}
\newcommand{\projectinfo}[5]{
\baseinfo{Project Phase #1 - Submission Sheet}{#2}{#3}{#4}{#5}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\name{Michael Chen}
\def\group{Group 01 (fastjson)}
\begin{document}
\projectinfo{3}{Software Testing - Graph Coverage\small}{\today}{\name}{\group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 1 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Answer basic questions on Graph Coverage}[3]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Define the following terms in your own words:
\begin{enumerate}
\item Graph
\begin{answer}
A graph is a set of vertices and edges between two such vertices. This allows us to create mathematical models of real world applications. This includes for example network architectures with computers and links as vertices and edges, or in our situation we can model program source code to vertices and the program flow to edges between code lines.
\end{answer}
\item (Test-)Path
\begin{answer}
In software testing we use directed graphs, because in a directed graph we always have unidirectional edges between the vertices. This is usesful because our program can only flow in one direction usually. A path on a directed graph is a sequence of vertices that are connected by edges pairwise, which corresponds to a connected set of directional edges. For software this can refer to a possible execution in a program flow. A test path is a path such that the path starts at an entrypoint of the graph and ends in an exit point. A test path thus refers to a path that corresponds to one possible complete execution of a program.
\end{answer}
\item Syntactic and Semantic Reach
\begin{answer}
Syntactic reach describes if a vertex in the graph can be reached (with a path) from another vertex. This of course only refers to the graph model without taking in account if such a path is actually possible using the semantics of our language. Therefore we have semantic reach, which describes if such a path is taken from any possible program execution (including inputs). The difference between these reaches is that we check if, even though a path might exist in the graph, it might still not be a useful path, because our program state never executes this path given any input values.
\end{answer}
\end{enumerate}
\item Which testing situations are suitable for the Graph Coverage approach?
\begin{answer}
Graph Coverage is suitable for white-box testing situations where we have detailed knowledge of the system under test. A program graph can be created from different aspects of a program, for example from the code directly (control-flow graph), from a software specification model, or even from higher-level abstractions such as calls between different software modules. Graph coverage allows us to very precisely specify semantically different program states, where, in contrast to black-box testing, we can (and must) incorporate edge cases and domain knowledge directly into our execution paths.
\end{answer}
\item What is the difference between \textit{Tours}, \textit{Tours With Sidetrips}, and \textit{Tours With Detours}?
\begin{answer}
A path $p_1$ can \textit{tour} another path $p_2$ if and only if $p_2$ is a subpath of $p_1$. This means that if $p_1$ is traversed, this includes the exact sequence of vertices that are also given in $p_2$. This makes a test on $p_2$ redundant, because we know, that we already traversed the graph in this manner. A tour with a sidetrip is a tour, except that it is allowed to insert loops into the subpath, as long as all edges of $p_2$ also appear in $p_1$ in the same order. A detour is similar, but instead of the edges, we enforce that all nodes of $p_2$ must also appear in $p_1$.
\end{answer}
\item Describe (1-2 sentences) the \textit{Node Coverage} (NC) and \textit{Edge Coverage} (EC) criterion. What are their counterparts for code-based coverage?
\begin{answer}
\Gls{nc} is satisfied for a test set if every syntactically reachable vertex in the graph is reached by any test path of our test set. \Gls{ec} however is satisfied if every syntactically reachable edge in the graph was used by any test path. A mapping to code-based coverage maps vertices in the graph to statements (or non-branching blocks of statements) and edges to branches between the statements. \Gls{nc} then refers to every statement being executed, which means we have statement coverage, while \gls{ec} refers to every branch being executed, which corresponds to branch coverage.
\end{answer}
\item Name and describe (2-3 sentences) 2 \textit{Path Coverage Criteria} OR 2 \textit{Data Flow Test Criteria}. Does one of these two criteria subsume the other?
\begin{answer}
Path coverage criteria are concerned with checking if all possible paths in a graph have been executed, while data-flow criteria check if all variable definitions and their usages have been reached. \Gls{ppc} is an example for a path coverage criterion that subsumes the \gls{adupc} criterion. \Gls{ppc} requires that every prime path (path that is not subpath of any other path) must be executed, while \gls{adupc} requires that every possible path between every definition and usage of a variable must be covered, which is of course less strong than checking every possible syntactically reachable path. Another example for data-flow coverage is \gls{auc} which verifies that every usage of variables are covered by at least one path in the test set, which is easily subsumed by \gls{adupc} and thus by \gls{ppc}. Another example for path coverage is \gls{srtc} which checks if a round-trip path is executed for every node that is the start and end of a round-trip.
\end{answer}
\end{enumerate}
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 2 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Apply Graph Coverage criteria to a sample program}[5]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Create the control flow graph for the given constructor.
\begin{answer}
\begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
\tikzstyle{every state}=[fill=gray,draw=none,text=white]
\node[initial,state] (s0) {$s_0$};
\node[state] (s1) [below of=s0] {$s_1$};
\node[state] (s2) [right of=s1] {$s_2$};
\node[state] (s3) [below of=s1] {$s_3$};
\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] (s5) [right of=s4] {$s_5$};
\node[state] (s6) [below of=s4] {$s_6$};
\node[state] (throw) [right of=s2] {\texttt{throw}};
\path
(s0) edge [bend left] node {$\texttt{iC} < 0$} (throw)
(s0) edge node {$\texttt{iC} \geq 0$} (s1)
(s1) edge node {$\texttt{iC} > \texttt{MAX}$} (s2)
(s1) edge node {$\texttt{iC} \leq \texttt{MAX}$} (s3)
(s2) edge [bend left] node {} (s3)
(s3) edge node {$\texttt{lF} > 0$} (s3s)
(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)
(s4) edge [bend left] node {$\texttt{c} < \texttt{iC}$} (s5)
(s4) edge node {$\texttt{c} \geq \texttt{iC}$} (s6)
(s5) edge [bend left] node {} (s4)
;
\end{tikzpicture}
\end{center}
\end{answer}
\item Create a minimum set of test cases that reaches 100\% coverage for the instruction coverage criterion.
\begin{answer}
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}
% or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java}
\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.
\begin{answer}
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$.
\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?
\begin{enumerate}
\item All-defs with respect to \texttt{capacity}
\begin{answer}
\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}
\item All-uses with respect to \texttt{loadFactor}
\begin{answer}
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{enumerate}
\end{enumerate}
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 3 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Apply Graph Coverage criteria to your software project}[8]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Measure the coverage of your given project test suite (which includes the existing test suite as well as the tests that you created in previous project phases) by three graph coverage criteria which you can freely choose. Describe each individual result in 2-3 sentences.
\begin{answer}
My test suite for the \texttt{JSONScanner} class so far covers 1\% of the class and 5\% of the \texttt{JsonLexerBase} base class, that does most of the work for basic JSON strings, in terms of instruction coverage. The fact that roughly similar coverage values are achieved with branch coverage using my small test suite is explained by the fact that most instructions that i have not covered are not covered because of missing tests that handle edge case (in this case mostly different JSON token alternatives) branches. My method coverage currently is at about 14\% and 12\% for the base class. Similar to the above tests, I am missing lots of tests for function calls that retrieve specific token values, however the coverage is higher than the branch coverage because the token alternatives are handled within the lexing method call, thus the method coverage is higher.
\end{answer}
\item Extend the test suite with own tests, which have to fullfil \textbf{one} of the following criteria:
\begin{enumerate}
\item Increase the coverage values of all three coverage criteria that you applied in the previous subtask with at least 10 tests (compare and describe the effects on coverage for each individual test), OR
\item Reveal a new bug in the software project (describe the bug, its context, and a potential fix in detail)
\end{enumerate}
\begin{answer}
See file \texttt{JSONScannerTest2.java}. Using this test suite I increased my test instruction coverage from 1\% to more than 9\% and my branch coverage from .5\% to almost 5\% (factor 10). I almost doubled the method coverage, which matches the test suite, because I roughly doubled the amount of different methods I called for different edge cases.
\end{answer}
\end{enumerate}
\end{question}
\end{document}

Binary file not shown.

View File

@ -0,0 +1,208 @@
\documentclass[a4paper]{scrreprt}
\usepackage[left=4cm,bottom=3cm,top=3cm,right=4cm,nohead,nofoot]{geometry}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{listings}
\usepackage{enumitem}
\usepackage{subcaption}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{xparse}
\usepackage{multirow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\textfloatsep}{16pt}
\renewcommand{\labelenumi}{\alph{enumi})}
\renewcommand{\labelenumii}{\arabic{enumii}) }
\newcommand{\baseinfo}[5]{
\begin{center}
\begin{tabular}{p{15cm}r}
\vspace{-4.5pt}{ \Large \bfseries #1} & \multirow{2}{*}{} \\[0.4cm]
#2 & \\[0.5cm]
\end{tabular}
\end{center}
\vspace{-18pt}\hrule\vspace{6pt}
\begin{tabular}{ll}
\textbf{Name:} & #4\\
\textbf{Group:} & #5\\
\end{tabular}
\vspace{4pt}\hrule\vspace{2pt}
\footnotesize \textbf{Software Testing} \hfil - \hfil Summer 2022 \hfil - \hfil #3 \hfil - \hfil Sibylle Schupp / Sascha Lehmann \hfil \\
}
\newcounter{question}
\NewDocumentEnvironment{question}{m o}{%
\addtocounter{question}{1}%
\paragraph{\textcolor{red}{Task~\arabic{question}} - #1\hfill\IfNoValueTF{#2}{}{[#2 P]}}
\leavevmode\\%
}{%
\vskip 1em%
}
\NewDocumentEnvironment{answer}{}{%
\vspace{6pt}
\leavevmode\\
\textit{Answer:}\\[-0.25cm]
{\color{red}\rule{\textwidth}{0.4mm}}
}{%
\leavevmode\\
{\color{red}\rule{\textwidth}{0.4mm}}
}
\newcommand{\projectinfo}[5]{
\baseinfo{Project Phase #1 - Submission Sheet}{#2}{#3}{#4}{#5}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\name{[Add name here]}
\def\group{[Add group here]}
\begin{document}
\projectinfo{3}{Software Testing - Graph Coverage\small}{\today}{\name}{\group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 1 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Answer basic questions on Graph Coverage}[3]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Define the following terms in your own words:
\begin{enumerate}
\item Graph
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item (Test-)Path
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item Syntactic and Semantic Reach
\begin{answer}
[TODO: Add answer here]
\end{answer}
\end{enumerate}
\item Which testing situations are suitable for the Graph Coverage approach?
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item What is the difference between \textit{Tours}, \textit{Tours With Sidetrips}, and \textit{Tours With Detours}?
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item Describe (1-2 sentences) the \textit{Node Coverage} (NC) and \textit{Edge Coverage} (EC) criterion. What are their counterparts for code-based coverage?
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item Name and describe (2-3 sentences) 2 \textit{Path Coverage Criteria} OR 2 \textit{Data Flow Test Criteria}. Does one of these two criteria subsume the other?
\begin{answer}
[TODO: Add answer here]
\end{answer}
\end{enumerate}
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 2 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Apply Graph Coverage criteria to a sample program}[5]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Create the control flow graph for the given constructor.
\begin{answer}
[TODO: Add answer here]
% Example graph using tikz
\begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
\tikzstyle{every state}=[fill=gray,draw=none,text=white]
\node[initial,state] (A) {$A$};
\node[state] (B) [above right of=A] {$B$};
\node[state] (D) [below right of=A] {$C$};
\node[state] (C) [below right of=B] {$D$};
\path (A) edge node {Dummy Label 1} (B)
(B) edge [loop above] node {Dummy Label 2} (B)
edge node {Dummy Label 3} (C)
(C) edge node {Dummy Label 4} (D)
(D) edge node {Dummy Label 5} (A);
\end{tikzpicture}
\end{center}
\end{answer}
\item Create a minimum set of test cases that reaches 100\% coverage for the instruction coverage criterion.
\begin{answer}
[TODO: Add answer here]
\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}
\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}
[TODO: Add answer here]
\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}
\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}
\item All-defs with respect to \texttt{capacity}
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item All-uses with respect to \texttt{loadFactor}
\begin{answer}
[TODO: Add answer here]
\end{answer}
\end{enumerate}
\end{enumerate}
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Task 3 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}{Apply Graph Coverage criteria to your software project}[8]
\begin{enumerate}[topsep=0pt, leftmargin=*]
\item Measure the coverage of your given project test suite (which includes the existing test suite as well as the tests that you created in previous project phases) by three graph coverage criteria which you can freely choose. Describe each individual result in 2-3 sentences.
\begin{answer}
[TODO: Add answer here]
\end{answer}
\item Extend the test suite with own tests, which have to fullfil \textbf{one} of the following criteria:
\begin{enumerate}
\item Increase the coverage values of all three coverage criteria that you applied in the previous subtask with at least 10 tests (compare and describe the effects on coverage for each individual test), OR
\item Reveal a new bug in the software project (describe the bug, its context, and a potential fix in detail)
\end{enumerate}
\begin{answer}
[TODO: Add answer here]
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip]
/* Add code here */
\end{lstlisting}
\end{answer}
\end{enumerate}
\end{question}
\end{document}