From 1850fab30d43b5a5b70c5a229d46c57e29f01828 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 18 May 2022 16:40:39 +0200 Subject: [PATCH 1/6] Unpacked project template for phase03 --- .../phase_03/project_phase03_tasks/.gitignore | 306 ++++++++++++++++++ .../project_phase03_tasks/HashMap.java | 29 ++ .../phase_03/project_phase03_tasks/Makefile | 21 ++ .../Solution_Phase03_MichaelChen.tex | 208 ++++++++++++ .../project_phase03_tasks.pdf | 3 + .../project_phase03_template.tex | 208 ++++++++++++ 6 files changed, 775 insertions(+) create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/.gitignore create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/HashMap.java create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/Makefile create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/project_phase03_tasks.pdf create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/project_phase03_template.tex diff --git a/project_task_sheets/phase_03/project_phase03_tasks/.gitignore b/project_task_sheets/phase_03/project_phase03_tasks/.gitignore new file mode 100644 index 0000000..afdad5a --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/.gitignore @@ -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 diff --git a/project_task_sheets/phase_03/project_phase03_tasks/HashMap.java b/project_task_sheets/phase_03/project_phase03_tasks/HashMap.java new file mode 100644 index 0000000..5545908 --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/HashMap.java @@ -0,0 +1,29 @@ +import java.util.Map.Entry; + +public class HashMap { + static final int MAXIMUM_CAPACITY = 1 << 10; + transient Entry[] 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; + } +} diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Makefile b/project_task_sheets/phase_03/project_phase03_tasks/Makefile new file mode 100644 index 0000000..eeda579 --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/Makefile @@ -0,0 +1,21 @@ +phase = 03 +version = 1 +name = MichaelChen + +solutionname = Solution_Phase$(phase)_$(name) +target = $(solutionname)_V$(version).zip +package = $(solutionname).pdf +latexmkflags = + +.PHONY : all dev + +all : $(target) + +dev : latexmkflags = -pvc +dev : all + +$(target) : $(package) + zip -FSr $(target) $(package) + +%.pdf : %.tex + latexmk -jobname="$*" $(latexmkflags) -pdf $< diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex new file mode 100644 index 0000000..6190a4c --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -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} diff --git a/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_tasks.pdf b/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_tasks.pdf new file mode 100644 index 0000000..383f41c --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_tasks.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34e9f7239399a2d06ead736ee14e408b6354eeeb11ebbad748c1771935a6e12c +size 421218 diff --git a/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_template.tex b/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_template.tex new file mode 100644 index 0000000..6190a4c --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/project_phase03_template.tex @@ -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} From 8571c450c3cd5a70272b310d4635df204bae2815 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 18 May 2022 17:25:41 +0200 Subject: [PATCH 2/6] Finished task 1 --- .../Solution_Phase03_MichaelChen.tex | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex index 6190a4c..e889bda 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -5,11 +5,21 @@ \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} @@ -63,8 +73,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\def\name{[Add name here]} -\def\group{[Add group here]} +\def\name{Michael Chen} +\def\group{Group 01 (fastjson)} \begin{document} \projectinfo{3}{Software Testing - Graph Coverage\small}{\today}{\name}{\group} @@ -78,38 +88,38 @@ \begin{enumerate} \item Graph \begin{answer} - [TODO: Add answer here] + 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} - [TODO: Add answer here] + 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} - [TODO: Add answer here] + 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} - [TODO: Add answer here] + 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} - [TODO: Add answer here] + 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} - [TODO: Add answer here] + \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} - [TODO: Add answer here] + 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} From 18a1b3ad4489c874df7383dc89af10408a0f3c03 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 18 May 2022 21:05:23 +0200 Subject: [PATCH 3/6] Added CFG --- .../Solution_Phase03_MichaelChen.tex | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex index e889bda..3166bd3 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -132,23 +132,33 @@ \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$}; + \node[initial,state] (s0) {\texttt{.ctor}}; + \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] (s4p) [below of=s3] {$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] {\texttt{.ret}}; + \node[state] (throw) [right of=s2] {\texttt{throw}}; - \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); + \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 {} (s4p) + (s3) edge [bend right] node [right] {$\texttt{lF} \leq 0 \lor \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} From 7aade7fac74555ce22feb8f8101a0b08b4e6678b Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 18 May 2022 22:07:39 +0200 Subject: [PATCH 4/6] Solved task 2 --- .../Solution_Phase03_MichaelChen.tex | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex index 3166bd3..4045dd1 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -136,14 +136,15 @@ \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick] \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] (s2) [right of=s1] {$s_2$}; \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] (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}}; \path @@ -152,8 +153,10 @@ (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 {} (s4p) - (s3) edge [bend right] node [right] {$\texttt{lF} \leq 0 \lor \texttt{lF} \equiv \texttt{NaN}$} (throw) + (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) @@ -165,34 +168,35 @@ \item Create a minimum set of test cases that reaches 100\% coverage for the instruction coverage criterion. \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} \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} + 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} - [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} \item All-uses with respect to \texttt{loadFactor} \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{enumerate} From 89e4bb84eef5af58ef5bdf8f749fe876a6777e1f Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Thu, 19 May 2022 08:07:46 +0200 Subject: [PATCH 5/6] Solved task 3 --- .../JSONScannerTest2.java | 88 +++++++++++++++++++ .../phase_03/project_phase03_tasks/Makefile | 2 +- .../Solution_Phase03_MichaelChen.tex | 8 +- 3 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java diff --git a/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java b/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java new file mode 100644 index 0000000..ff220ca --- /dev/null +++ b/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java @@ -0,0 +1,88 @@ +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\""); + // After construction the UTF-8 BOM should be safely skipped + 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"); + // After construction the UTF-8 BOM should be safely skipped + Assert.assertTrue(scanner.scanISO8601DateIfMatch()); + } + + @Test + public void scanSingleComment() throws Throwable { + JSONScanner scanner = new JSONScanner("//dsajfklsjfk"); + // After construction the UTF-8 BOM should be safely skipped + scanner.nextToken(); + Assert.assertTrue(scanner.isEOF()); + } + + @Test + public void scanMultiComment() throws Throwable { + JSONScanner scanner = new JSONScanner("/*dsajfklsjfk*/"); + // After construction the UTF-8 BOM should be safely skipped + 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_Null() throws Throwable { + JSONScanner scanner = new JSONScanner("null"); + // After construction the UTF-8 BOM should be safely skipped + scanner.nextToken(); + Assert.assertEquals(JSONToken.NULL, scanner.token()); + } + + @Test + public void inputTokenTest_Undefined() throws Throwable { + JSONScanner scanner = new JSONScanner("undefined"); + // After construction the UTF-8 BOM should be safely skipped + scanner.nextToken(); + Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); + } + + @Test + public void inputTokenTest_Undefined() throws Throwable { + JSONScanner scanner = new JSONScanner("undefined"); + // After construction the UTF-8 BOM should be safely skipped + scanner.nextToken(); + Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); + } + + @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()); + } +} diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Makefile b/project_task_sheets/phase_03/project_phase03_tasks/Makefile index eeda579..ce3b251 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Makefile +++ b/project_task_sheets/phase_03/project_phase03_tasks/Makefile @@ -4,7 +4,7 @@ name = MichaelChen solutionname = Solution_Phase$(phase)_$(name) target = $(solutionname)_V$(version).zip -package = $(solutionname).pdf +package = $(solutionname).pdf HashMap.java JSONScannerTest2.java latexmkflags = .PHONY : all dev diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex index 4045dd1..3137c9b 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -210,7 +210,7 @@ \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] + 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: @@ -219,11 +219,7 @@ \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} + 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} From 63807f4c0acadf15afb7711b79e030f0082be4ad Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Thu, 19 May 2022 09:34:34 +0200 Subject: [PATCH 6/6] Fixed test suite --- .../JSONScannerTest2.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java b/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java index ff220ca..c3687c7 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java +++ b/project_task_sheets/phase_03/project_phase03_tasks/JSONScannerTest2.java @@ -17,7 +17,6 @@ public class JSONScannerTest2 { @Test public void stringHasSpecialTest() throws Throwable { JSONScanner scanner = new JSONScanner("\"\\b\\n\\t\\\"\\uABED\""); - // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.LITERAL_STRING, scanner.token()); Assert.assertEquals("\b\n\t\"\uABED", scanner.stringVal()); @@ -25,15 +24,13 @@ public class JSONScannerTest2 { @Test public void stringWithIso8601Date() throws Throwable { - JSONScanner scanner = new JSONScanner("2012-04-23T18:25:43.511Z"); - // After construction the UTF-8 BOM should be safely skipped + 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"); - // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertTrue(scanner.isEOF()); } @@ -41,7 +38,6 @@ public class JSONScannerTest2 { @Test public void scanMultiComment() throws Throwable { JSONScanner scanner = new JSONScanner("/*dsajfklsjfk*/"); - // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertTrue(scanner.isEOF()); } @@ -55,27 +51,25 @@ public class JSONScannerTest2 { } @Test - public void inputTokenTest_Null() throws Throwable { - JSONScanner scanner = new JSONScanner("null"); - // After construction the UTF-8 BOM should be safely skipped + public void inputTokenTest_set() throws Throwable { + JSONScanner scanner = new JSONScanner("Set[3,2,1]"); scanner.nextToken(); - Assert.assertEquals(JSONToken.NULL, scanner.token()); + Assert.assertEquals(JSONToken.SET, scanner.token()); } @Test public void inputTokenTest_Undefined() throws Throwable { JSONScanner scanner = new JSONScanner("undefined"); - // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); } @Test - public void inputTokenTest_Undefined() throws Throwable { - JSONScanner scanner = new JSONScanner("undefined"); - // After construction the UTF-8 BOM should be safely skipped - scanner.nextToken(); - Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); + 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