Skip to content
Snippets Groups Projects
Verified Commit 530e766a authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Final Exam halfsheets answer key (mostly done)

parent bff7c73c
No related branches found
No related tags found
No related merge requests found
\documentclass[11pt, portrait]{article}
\usepackage{multicol}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,tabsize=4,texcl=true,escapechar=\^,keepspaces,showstringspaces=false,commentstyle=\ttfamily}
\input{preamble}
\renewcommand{\exam}{Final~Exam}
\begin{document}
% \renewcommand{\arraystretch}{2}
\linespread{0.9}
\begin{enumerate}
\item \input{final-exam/program-state-diagram} \input{final-exam/program-state-diagram_key} \newpage
\item \input{final-exam/code-reading} \input{final-exam/code-reading_key} \newpage
\item \input{final-exam/class-diagram} \input{final-exam/class-diagram_key} \newpage
\item \input{final-exam/testing} \input{final-exam/testing_key} \newpage
\item \input{final-exam/object-orientation} \input{final-exam/object-orientation_key} \newpage
\item \input{final-exam/loop-code-writing} \input{final-exam/loop-code-writing_key} \newpage
\item \input{final-exam/design-an-algorithm_3-grades} \input{final-exam/design-an-algorithm_3-grades_key} \newpage
\item \input{final-exam/unit-testing} \newpage \input{final-exam/unit-testing_key} \newpage
\item \input{final-exam/control-flow-graph} \input{final-exam/control-flow-graph_key}
\end{enumerate}
\end{document}
\ No newline at end of file
\begin{key}
We briefly went over how to diagram the methods, so students might include them in the diagram.
Make sure the public/private modifiers are correct and the format is correct.
It is helpful to keep the fields and methods in the same order as they appear in the code.
\begin{center}
\begin{tabular}{|c@{}l|}
\hline
\multicolumn{2}{|c|}{Pay} \\ \hline
- & hours : double \\
- & amount : double \\ \hline
\end{tabular}
\end{center}
or
\begin{center}
\begin{tabular}{|c@{}l|}
\hline
\multicolumn{2}{|c|}{Pay} \\ \hline
- & hours : double \\
- & amount : double \\ \hline
+ & Pay(hours: double, amount: double) : Pay \\
+ & getHourlyRate() : double \\
+ & isOvertime() : boolean \\
+ & toString() : String \\ \hline
\end{tabular}
\end{center}
``\lstinline{$0.5 per hour}'' is printed.
\end{key}
\ No newline at end of file
\begin{key}
\begin{enumerate}
\item{A new \lstinline{Point} is created.}
\item{The constructor is called with \lstinline{this} set to the new object
and the arguments \lstinline{4} and \lstinline{6}.}
\item{The constructor sets the object's fields to \lstinline{4} and
\lstinline{6}.}
\item{The constructor returns.}
\item{The \lstinline{mystery} method is called with \lstinline{this} set to
the object.}
\item{The \lstinline{mystery} method computes \lstinline{-2 * x}, which is
\lstinline{-8}, and \lstinline{-2 * y}, which is \lstinline{-12}.}
\item{The \lstinline{translate} method is called with \lstinline{this} set to
the object and the arguments \lstinline{-8} and \lstinline{-12}.}
\item{The \lstinline{translate} method changes the object's fields to
\lstinline{-4} and \lstinline{-6}.}
\item{The \lstinline{translate} method returns the object.}
\item{The \lstinline{mystery} method returns the object.}
\item{The \lstinline{println} method is called with \lstinline{this} set to
\lstinline{System.out} and the argument being the object.}
\item{The object is formatted as a string by calling its \lstinline{toString}
method with \lstinline{this} set to the object.}
\item{The \lstinline{toString} computes and returns the string
``\lstinline{(-4, -6)}''.}
\item{``\lstinline{(-4, -6)}'' is printed.}
\end{enumerate}
\end{key}
\ No newline at end of file
\textcolor{red}{TODO: do the first part}
\begin{key}
\dots
\end{key}
\begin{key}
\begin{itemize}
\item{\lstinline{18} (being \lstinline{moreData[3]}, which was set to \lstinline{data[2]})}
\item{\lstinline{11} (being \lstinline{moreData[2]}, which was set to \lstinline{data[1]})}
\item{\lstinline{2} (being \lstinline{moreData[1]}, which was set to \lstinline{data[0]})}
\item{\lstinline{1} (being \lstinline{moreData[0]}, which was set to \lstinline{data[0] - 1})}
\end{itemize}
\end{key}
\ No newline at end of file
\textcolor{red}{TODO: do}
\begin{key}
\dots
\end{key}
\ No newline at end of file
\begin{key}
\begin{description}
\item[Base case] A board with no squares is vacuously has no occupied squares (effectively assumes that the entire board is blank until proven otherwise)
\item[Initiation, outer loop] \lstinline{x = 0} (start in the 0th column)
\item[Consecution, outer loop] \lstinline{x++} (advance to the next column)
\item[Termination, inner loop] \lstinline{x < 2} (terminate after we've passed the 2nd column)
\item[Action, outer loop] Evaluate each square in the $x$th column
\item[Initiation, inner loop] \lstinline{y = 0} (start in square $(x, 0)$)
\item[Consecution, outer loop] \lstinline{y++} (advance to the next square in the $x$th column)
\item[Termination, inner loop] \lstinline{y < 2} (terminate after we've passed the 2nd row in the $x$th column)
\item[Action, inner loop] if square $(x,y)$ has an `X' or a `Y' then we have a counterexample to the assumption that the board is blank
\end{description}
\begin{lstlisting}
boolean empty = true;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
if (hasCross(x, y) || hasNaught(x, y)) {
empty = false;
}
}
}
\end{lstlisting}
(Student \textit{must} design their solutions, but they should avoid overengineering their solutions.
There is, for instance, no need to count the empty or filled cells.)
\end{key}
\ No newline at end of file
Given the following class diagram, write the class in Java:
%\illustration{0}
\begin{center}
\begin{tabular}{|c@{}l|}
\hline
......
\begin{key}
\begin{lstlisting}
public class Course {
public String title;
private List<Course> corequisites;
private List<Course> prerequisites;
public Course(String title) {
this.title = title;
corequisites = new ArrayList<Course>();
prerequisites = new ArrayList<Course>();
}
}
\end{lstlisting}
Notes:
\begin{itemize}
\item{Per convention, the name of the constructor's parameter matches the name of the field, and we distinguish the two via the \lstinline{this} keyword.}
\item{We do not write \lstinline{this.corequisites} or \lstinline{this.prerequisites}, as the convention in Java is to omit \lstinline{this} when it is unnecessary.}
\item{We cannot say just \lstinline{new List<Course>()} because we must choose which kind of list \lstinline{corequisites} and \lstinline{prerequisites} are.
We \textit{could}, however, say just \lstinline{new ArrayList<>()} because Java can infer the ``\lstinline{<Course>}'' from the declared type.}
\end{itemize}
\vspace{1cm}
\begin{lstlisting}
Course soft160 = new Course("Software Engineering I");
\end{lstlisting}
\end{key}
\ No newline at end of file
Draw a program state diagram (showing all contexts) for the
program state just after line 9 executes. What is the output of the program?
Draw a program state diagram (showing all contexts) for the program state just after the second time that line 3 executes.
What is the output of the program?
\begin{quote}
\begin{lstlisting}[numbers=left]
......
\begin{key}
\begin{tabular}[h]{clclcl}
\textbf{main} & \hspace{3cm} & \textbf{baz} & \hspace{3cm} & \textbf{fie} & \\ \cline{1-1}\cline{3-3}\cline{5-5}
\multicolumn{1}{|l|}{arguments} & $\rightarrow$ \textlangle unknown\textrangle & \multicolumn{1}{|l|}{fum} & $\rightarrow$ 1 & \multicolumn{1}{|l|}{fum} & $\rightarrow$ 4 \\
\multicolumn{1}{|l|}{fum} & $\rightarrow$ \textlangle undefined\textrangle & \multicolumn{1}{|l|}{result} & $\rightarrow$ \textlangle undefined\textrangle & \multicolumn{1}{|l|}{i} & $\rightarrow$ 1 \\ \cline{1-1}\cline{3-3}\cline{5-5}
\end{tabular}
\vspace{1cm}
The program outputs ``1 true''
\end{key}
\ No newline at end of file
\begin{key}
\begin{enumerate}
\item A software engineer would need to consult (a)~either the specification or the
design documents (to determine the requirements on the method) and (b)~either
the design documents or the code (to determine the method's signature).
\item When run, the tests would analyze (a)~the code, specifically the method under
test and any of its callees, but also, implicitly, (b)~the unit tests being
run (because their correctness also affects the test results).
\item Metrics collected would include (a)~the number of tests run, (b)~the number of
tests that passed, and (c) the test pass rate (the ratio of (a) and (b)).
\item The number of tests run would speak to testedness, and may also give some
sense of testability. The number of tests passing and the test pass rate
would speak to functional correctness.
\item If coverage were collected, an additional metric, code coverage, would be
measured. It would provide information about testedness and, implicitly,
testability.
\item Category-partition testing is a black-box testing technique because it does
not use the code (in particular, the structure of the code) to create the
test cases (it uses the specification but it also use the method signature).
\end{enumerate}
\end{key}
\ No newline at end of file
......@@ -14,14 +14,14 @@ The \lstinline{countWords} method has the following specification:
\item{number of words in \lstinline{identifier}:}
\item{\lstinline{identifier} starts with a capital letter:}
\item{\lstinline{identifier} contains a one-letter word:}
\item{return value:}
\end{itemize}
\end{quote}
\begin{enumerate}
\item Given the specification above, identify a partition for each category and the return value.
\item Identify a representative value for each choice.
\item Given the specification above, identify a partition for each category.
\item Write a set of test frames that achieve 1-way coverage of your partitions.
\item Identify a representative value for each choice.
\item Use those representative values to convert your test frames into test cases.
\item Using your partitions from above and the following JUnit test template, create a JUnit test that matches the test name.
\begin{lstlisting}
......
\begin{key}
\begin{enumerate}
\item
\begin{itemize}
\item{\lstinline{identifier}'s length: 0, 1, more than 1}
\item{number of words in \lstinline{identifier}: 0, 1, more than 1}
\item{\lstinline{identifier} starts with a capital letter: true, false}
\item{\lstinline{identifier} contains a one-letter word: true, false}
\end{itemize}
\vspace{1cm}
\item
\hbox{}
\centerline{%
\begin{tabular}{ccccc}
Code Under Test & length & number of words & starts with capital letter & contains a 1-letter word \\ \hline
\lstinline{countWords} & 0 & 0 & & \\
\lstinline{countWords} & 1 & 1 & true & true \\
\lstinline{countWords} & more than 1 & more than 1 & false & false \\
\end{tabular}%
}
\hbox{}
\vspace{1cm}
\item
\begin{itemize}
\item{\lstinline{identifier}'s length: 0, 1, 2}
\item{number of words in \lstinline{identifier}: 0, 1, 2}
\item{\lstinline{identifier} starts with a capital letter: true, false}
\item{\lstinline{identifier} contains a one-letter word: true, false}
\end{itemize}
\vspace{1cm}
\item
\hbox{}
\centerline{%
\begin{tabular}{ccc}
Code Under Test & Argument(s) & Return Value \\ \hline
\lstinline{countWords} & \lstinline{identifier:""} & \lstinline{0} \\
\lstinline{countWords} & \lstinline{identifier: "A"} & \lstinline{1} \\
\lstinline{countWords} & \lstinline{identifier: "theDog"} & \lstinline{2} \\
\end{tabular}%
}
\hbox{}
\vspace{1cm}
\item
\begin{lstlisting}
@Test
public void countWords() {
int result = Editor.countWords("A");
assertEquals(1, result);
}
\end{lstlisting}
\end{enumerate}
\end{key}
\ No newline at end of file
\usepackage{fullpage}
\usepackage{xcolor}
\usepackage{tikz}
% headers and footers
\usepackage{fancyhdr}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment