diff --git a/Assignments/A3/A3Soln/A3P1_Spec.pdf b/Assignments/A3/A3Soln/A3P1_Spec.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2f8c51da14b7c4c17344bfc960445fb060119ee4 Binary files /dev/null and b/Assignments/A3/A3Soln/A3P1_Spec.pdf differ diff --git a/Assignments/A3/A3Soln/A3P1_Spec.tex b/Assignments/A3/A3Soln/A3P1_Spec.tex new file mode 100644 index 0000000000000000000000000000000000000000..6ef43a43f1a00fa05d76e24d76254f43e8d69889 --- /dev/null +++ b/Assignments/A3/A3Soln/A3P1_Spec.tex @@ -0,0 +1,710 @@ +\documentclass[12pt]{article} + +\usepackage{graphicx} +\usepackage{paralist} +\usepackage{amsfonts} +\usepackage{amsmath} +\usepackage{hhline} +\usepackage{booktabs} +\usepackage{multirow} +\usepackage{multicol} + +\oddsidemargin 0mm +\evensidemargin 0mm +\textwidth 160mm +\textheight 200mm +\renewcommand\baselinestretch{1.0} + +\pagestyle {plain} +\pagenumbering{arabic} + +\newcounter{stepnum} + +%% Comments + +\usepackage{color} + +\newif\ifcomments\commentstrue + +\ifcomments +\newcommand{\authornote}[3]{\textcolor{#1}{[#3 ---#2]}} +\newcommand{\todo}[1]{\textcolor{red}{[TODO: #1]}} +\else +\newcommand{\authornote}[3]{} +\newcommand{\todo}[1]{} +\fi + +\newcommand{\wss}[1]{\authornote{blue}{SS}{#1}} + +\title{Assignment 3, Part 1, Specification} +\author{SFWR ENG 2AA4} + +\begin {document} + +\maketitle + +The purpose of this software design exercise is to design and implement a +portion of the specification for a Geographic Information System (GIS). This +document shows the complete specification, which will be the basis for your +implementation and testing. In this specification natural numbers +($\mathbb{N}$) include zero ($0$). + +\wss{The parts that you need to fill in are marked by comments, like this one. + In several of the modules local functions are specified. You can use these + local functions to complete the missing specifications.} + +\newpage + +\section* {Map Types Module} + +\subsection*{Module} + +MapTypes + +\subsection* {Uses} + +N/A + +\subsection* {Syntax} + +\subsubsection* {Exported Constants} + +None + +\subsubsection* {Exported Types} + +CompassT = \{N, S, E, W\}\\ +LanduseT = \{Recreational, Transport, Agricultural, Residential, Commercial\}\\ +RotateT = \{CW, CCW\} + +\subsubsection* {Exported Access Programs} + +None + +\subsection* {Semantics} + +\subsubsection* {State Variables} + +None + +\subsubsection* {State Invariant} + +None + +\newpage + +\section* {Point ADT Module} + +\subsection*{Template Module} + +PointT + +\subsection* {Uses} + +N/A + +\subsection* {Syntax} + +\subsubsection* {Exported Types} + +\wss{What should be written here?}PointT = ? + +\subsubsection* {Exported Access Programs} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +PointT & $\mathbb{Z}$, $\mathbb{Z}$ & PointT & \\ +\hline +x & ~ & $\mathbb{Z}$ & ~\\ +\hline +y & ~ & $\mathbb{Z}$ & ~\\ +\hline +translate & $\mathbb{Z}$, $\mathbb{Z}$ & PointT & ~\\ +\hline +\end{tabular} + +\subsection* {Semantics} + +\subsubsection* {State Variables} + +$xc$: \wss{What is the type of the state variables?}$\mathbb{Z}$\\ +$yc$: \wss{What is the type of the state variables?}$\mathbb{Z}$ + +\subsubsection* {State Invariant} + +None + +\subsubsection* {Assumptions} + +The constructor PointT is called for each object instance before any other +access routine is called for that object. The constructor cannot be called on +an existing object. + +\subsubsection* {Access Routine Semantics} + +PointT($x, y$): +\begin{itemize} +\item transition: \wss{What should the state transition be for the constructor?}$xc, yc := x, y$ +\item output: $out := \mathit{self}$ +\item exception: None +\end{itemize} + +\noindent x(): +\begin{itemize} +\item output: $out := xc$ +\item exception: None +\end{itemize} + +\noindent y(): +\begin{itemize} +\item \wss{What should go here?}output: $out := yc$ +\item exception: None +\end{itemize} + +\noindent translate($\Delta x$, $\Delta y$): +\begin{itemize} +\item \wss{What should go here?}output: $out := \mbox{PointT}(xc + \Delta x, yc + \Delta y)$ +\item exception: \wss{What should go here?}None +\end{itemize} + +\newpage + +\section* {Line ADT Module} + +\subsection*{Template Module} + +LineT + +\subsection* {Uses} + +\wss{What should go here?}PointT, MapTypes + +\subsection* {Syntax} + +\subsubsection* {Exported Types} + +LineT = ? + +\subsubsection* {Exported Access Programs} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +LineT & PointT, CompassT, $\mathbb{N}$ & LineT & invalid\_argument\\ +\hline +strt & ~ & PointT & ~\\ +\hline +end & ~ & PointT & ~\\ +\hline +orient & ~ & CompassT & ~\\ +\hline + len & ~ & $\mathbb{N}$ & ~\\ +\hline +flip & ~ & LineT & ~\\ +\hline +rotate & RotateT & LineT & ~\\ +\hline +translate & $\mathbb{Z}$, $\mathbb{Z}$ & LineT & ~\\ +\hline +\end{tabular} + +\subsection* {Semantics} + +\subsubsection* {State Variables} + +$s$: PointT\\ +$o$: CompassT\\ +$L$: $\mathbb{N}$\\ + +\subsubsection* {State Invariant} + +None + +\subsubsection* {Assumptions} + +The constructor LineT is called for each object instance before any other +access routine is called for that object. The constructor cannot be called on +an existing object. + +\subsubsection* {Access Routine Semantics} + +LineT($st, ornt, l$): +\begin{itemize} +\item transition: $s, o, L := st, ornt, l$ +\item output: $out := \mathit{self}$ +\item exception: \wss{Write the spec for an exception when the length of the line is 0}$exc := (L = 0 \Rightarrow \mathrm{invalid\_argument})$ +\end{itemize} + +\noindent strt(): +\begin{itemize} +\item output: $out := \mbox{PointT}(s.x(), s.y())$ +\item exception: None +\end{itemize} + +\noindent end(): +\begin{itemize} +% \item output: +% $out := (o = \mbox{N} \Rightarrow \mbox{PointT}(s.x, s.y + (L-1)) | o = \mbox{S} \Rightarrow +% \mbox{PointT}(s.x, s.y - (L-1)) | o = \mbox{W} \Rightarrow \mbox{PointT}(s.x - (L-1), s.y) | +% o = \mbox{E} \Rightarrow \mbox{PointT}(s.x + (L-1), s.y))$ +\item output: \wss{Write the spec for returning the end point of the + line.}$out := \mbox{PointT}((o = \mbox{W} \Rightarrow s.x - (L-1) | o = + \mbox{E} \Rightarrow s.x + (L-1) | \mbox{True} \Rightarrow s.x), (o = \mbox{N} + \Rightarrow s.y + (L-1) | o = \mbox{S} \Rightarrow s.y - (L-1) | \mbox{True} + \Rightarrow s.y))$ + +\item exception: None +\end{itemize} + +\noindent orient(): +\begin{itemize} +\item output: $out := o$ +\item exception: None +\end{itemize} + +\noindent len(): +\begin{itemize} +\item output: $out := L$ +\item exception: None +\end{itemize} + +\noindent flip(): +\begin{itemize} +\item output: \wss{Write the spec for returning a new line that is the mirror + image of the current line. That is, the start point and length of the new + line will remain the same, but the orientation will be changed by 180 + degrees}$out := \mbox{LineT}(s, (o = \mbox{N} \Rightarrow \mbox{S} | o = + \mbox{S} \Rightarrow \mbox{N} | o = \mbox{W} \Rightarrow \mbox{E} | o = + \mbox{E} \Rightarrow \mbox{W}), L)$ +\item exception: None +\end{itemize} + +\noindent rotate(r): +\begin{itemize} +\item output: +\begin{tabular}{|p{2.cm}|p{2.3cm}|l|} +\hhline{~|~|-|} +\multicolumn{1}{r}{} & \multicolumn{1}{r|}{} & \multicolumn{1}{l|}{$out :=$}\\ +\hhline{|-|-|-|} +$r = \mbox{CW}$ & $o = \mbox{N}$ & \wss{?}$\mbox{LineT}(s, E, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{S}$ & \wss{?}$\mbox{LineT}(s, W, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{W}$ & \wss{?}$\mbox{LineT}(s, N, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{E}$ & \wss{?}$\mbox{LineT}(s, S, L)$\\ +\hhline{-|-|-|} +$r = \mbox{CCW}$ & $o = \mbox{N}$ & \wss{?}$\mbox{LineT}(s, W, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{S}$ & \wss{?}$\mbox{LineT}(s, E, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{W}$ & \wss{?}$\mbox{LineT}(s, S, L)$\\ +\hhline{|~|-|-|} +~ & $o = \mbox{E}$ & \wss{?}$\mbox{LineT}(s, N, L)$\\ +\hhline{-|-|-|} +\end{tabular} + +\item exception: None +\end{itemize} + +\noindent translate($\Delta x$, $\Delta y$): +\begin{itemize} +\item output: \wss{Add the missing spec}$out := \mbox{LineT}(s.\mbox{translate}(\Delta x, \Delta y), o, L)$ +\item exception: None +\end{itemize} + +\newpage + +\section* {Path ADT Module} + +\subsection*{Template Module} + +PathT + +\subsection* {Uses} + +PointT, LineT, MapTypes + +\subsection* {Syntax} + +\subsubsection* {Exported Types} + +PathT = ? + +\subsubsection* {Exported Access Programs} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +PathT & PointT, CompassT, $\mathbb{N}$ & PathT & \\ %LineT constructor for invalid\_argument +\hline +append & CompassT, $\mathbb{N}$ & & invalid\_argument\\ +\hline +strt & ~ & PointT & ~\\ +\hline +end & ~ & PointT & ~\\ +\hline +line & $\mathbb{N}$ & LineT & outside\_bounds\\ +\hline +size & ~ & $\mathbb{N}$ & \\ +\hline + len & ~ & $\mathbb{N}$ & ~\\ +\hline +translate & $\mathbb{Z}$, $\mathbb{Z}$ & PathT & ~\\ +\hline +\end{tabular} + +\subsection* {Semantics} + +\subsubsection* {State Variables} + +$s$: sequence of LineT + +\subsubsection* {State Invariant} + +None + +\subsubsection* {Assumptions} + +\begin{itemize} +\item The constructor PathT is called for each object instance before any other +access routine is called for that object. The constructor cannot be called on +an existing object. +%\item Appends will not be made while iterating through the list of lines. +\end{itemize} + +\subsubsection* {Access Routine Semantics} + +PathT($st, ornt, l$): +\begin{itemize} +\item transition: \wss{What is the spec to add the first element to the sequence + of LineT?}$s[0] := \mbox{LineT}(st, ornt, l)$ +\item output: $out := \mathit{self}$ +\item exception: None +\end{itemize} + +\noindent append($ornt, l$): +\begin{itemize} +\item transition: \wss{What is the missing specification? The appended line + starts at a point adjacent to the end point of the previous line in the + direction $ornt$. The lines are not allowed to + overlap.}$s := s || \langle \mbox{LineT}(\mbox{adjPt}(ornt), ornt, l\rangle$ +\item exception: \wss{What is the specification for the exception? An exception + should be generated if the introduced line overlaps with any of the previous + points in the existing path.} +\begin{multline*} + exc :=\\ + (\mbox{pointsInLine}(\mbox{LineT}(st, ornt, l)) \cap (\cup + (l: \mbox{LineT} | l \in s : \mbox{pointsInLine}(l))) \neq \emptyset \Rightarrow \mbox{invalid\_argument}) +\end{multline*} +\end{itemize} + +\noindent strt(): +\begin{itemize} +\item output: \wss{What is the missing spec?}$out := s[0].\mbox{strt}$ +\item exception: None +\end{itemize} + +\noindent end(): +\begin{itemize} +\item output: \wss{What is the missing spec?}$out := s[|s|-1].\mbox{end}$ +\item exception: None +\end{itemize} + +\noindent line($i$): +\begin{itemize} +\item output: \wss{Returns the ith line in the sequence. What is the missing spec?}$out := \mbox{LineT}(s[i].\mbox{strt}(), s[i].\mbox{orient}(), s[i].\mbox{len}())$ +\item exception: \wss{Generate the exception if the index is not in the sequence.}$exc := (i \geq |s| \Rightarrow \mbox{outside\_bounds})$ +\end{itemize} + +\noindent size: +\begin{itemize} +\item output: \wss{Output the number of lines in the path.}$out := |s|$ +\item exception: None +\end{itemize} + +\noindent len: +\begin{itemize} +\item output: \wss{Output the total number of points (grid cells) on the path, + including the beginning and end points (cells).}$out := +(l: \mbox{LineT} | i \in s: l.\mbox{len})$ +\item exception: None +\end{itemize} + +\noindent translate($\Delta x$, $\Delta y$): +\begin{itemize} +\item output: Create a new PathT object with state variable $s'$ such that: +$$\forall(i: \mathbb{N} | i \in [0..|s|-1] : s'[i] = s[i].\mbox{translate}(\Delta x, \Delta y))$$ +\item exception: None +\end{itemize} + +\subsection*{Local Functions} + +pointsInLine: $\mbox{LineT} \rightarrow \mbox{(set of PointT)}$\\ + +\noindent pointsInLine ($l$) +\begin{multline*} +\equiv \{ i: \mathbb{N} | i \in [0 + .. (l.\mbox{len} - 1)] : l.\mbox{strt}.\mbox{translate}(\wss{Complete the spec.}\\ +(l.\mbox{orient}=\mbox{W} \Rightarrow -i | + l.\mbox{orient}=\mbox{E} \Rightarrow i | \mbox{True} \Rightarrow 0), (l.\mbox{orient}=\mbox{N} \Rightarrow i | + l.\mbox{orient}=\mbox{S} \Rightarrow -i | \mbox{True} \Rightarrow 0) ) \} +\end{multline*} + +\noindent adjPt: $\mbox{CompassT} \rightarrow \mbox{PointT}$\\ +adjPt$(ornt) \equiv$ + +\medskip + +\begin{tabular}{|l|l|} +\hline +$ornt = \mbox{N}$ & $s[|s|-1].\mbox{end}.\mbox{translate}\wss{?}(0, 1)$\\ +\hline +$ornt = \mbox{S}$ & $s[|s|-1].\mbox{end}.\mbox{translate}\wss{?}(0, -1)$\\ +\hline +$ornt = \mbox{W}$ & $s[|s|-1].\mbox{end}.\mbox{translate}\wss{?}(-1, 0)$\\ +\hline +$ornt = \mbox{E}$ & $s[|s|-1].\mbox{end}.\mbox{translate}\wss{?}(1, 0)$\\ +\hline +\end{tabular} + +\newpage + +\section* {Generic Seq2D Module} + +\subsection* {Generic Template Module} + +Seq2D(T) + +\subsection* {Uses} + +MapTypes, PointT, LineT, PathT + +\subsection* {Syntax} + +\subsubsection* {Exported Types} + +Seq2D(T) = ? + +\subsubsection* {Exported Constants} + +None + +\subsubsection* {Exported Access Programs} + +\begin{tabular}{| l | l | l | p{5cm} |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +Seq2D & seq of (seq of T), $\mathbb{R}$ & Seq2D & invalid\_argument\\ +\hline +set & PointT, T & ~ & outside\_bounds\\ +\hline +get & PointT & T & outside\_bounds\\ +\hline +getNumRow & ~ & $\mathbb{N}$ & \\ +\hline +getNumCol & ~ & $\mathbb{N}$ & \\ +\hline +getScale & ~ & $\mathbb{R}$ & \\ +\hline +count & T & $\mathbb{N}$ & \\ +\hline +count & LineT, T & $\mathbb{N}$ & invalid\_argument\\ +\hline +count & PathT, T & $\mathbb{N}$ & invalid\_argument\\ +\hline +length & PathT & $\mathbb{R}$ & invalid\_argument\\ +\hline +connected & PointT, PointT & $\mathbb{B}$ & invalid\_argument\\ +\hline +\end{tabular} + +\subsection* {Semantics} + +\subsubsection* {State Variables} + +$s$: seq of (seq of T)\\ +scale: $\mathbb{R}$\\ +nRow: $\mathbb{N}$\\ +nCol: $\mathbb{N}$ + +\subsubsection* {State Invariant} + +None + +\subsubsection* {Assumptions} + +\begin{itemize} +\item The Seq2D(T) constructor is called for each object instance before any +other access routine is called for that object. The constructor can only be +called once. +\item Assume that the input to the constructor is a sequence of rows, where each + row is a sequence of elements of type T. The number of columns (number of + elements) in each row is assumed to be equal. That is each row + of the grid has the same number of entries. $s[i][j]$ means the ith row and + the jth column. The 0th row is at the bottom of the map and the 0th column + is at the leftmost side of the map. +\end{itemize} + +\subsubsection* {Access Routine Semantics} + +Seq2D($S$, scl): +\begin{itemize} +\item transition: \wss{Fill in the transition.}$s, \mbox{scale}, \mbox{nCol}, \mbox{nRow} := S, + \mbox{scl}, |S[0]|, |S|$ +\item output: $\mathit{out} := \mathit{self}$ +\item exception: \wss{Fill in the exception. One should be generated if the + scale is less than zero, or the input sequence is empty, or the number of + columns is zero in the first row, or the number of columns in any row is + different from the number of columns in the first row.}$exc := (\mbox{scale} \leq 0 \lor |S| = 0 \lor |S[0]| = 0 \Rightarrow \mbox{invalid\_argument}|\\ + \lnot\forall(l : \mbox{seq of T}|l \in S : |l| = |S[0]|) \Rightarrow + \mbox{invalid\_argument})$ +\end{itemize} + +\noindent set($p, v$): +\begin{itemize} +\item transition: \wss{?}$s[p.y][p.x] := v$ +\item exception: \wss{Generate an exception if the point lies outside of the + map.}$exc := (\neg \mbox{validPoint}(p) \Rightarrow \mbox{outside\_bounds})$ +\end{itemize} + +\noindent get($p$): +\begin{itemize} +\item output: \wss{?}$out := s[p.y][p.x]$ +\item exception: \wss{Generate an exception if the point lies outside of the + map.}$exc := (\neg \mbox{validPoint}(p) \Rightarrow \mbox{outside\_bounds})$ +\end{itemize} + +\noindent getNumRow(): +\begin{itemize} +\item output: $out := \mbox{nRow}$ +\item exception: None +\end{itemize} + +\noindent getNumCol(): +\begin{itemize} +\item output: $out := \mbox{nCol}$ +\item exception: None +\end{itemize} + +\noindent getScale(): +\begin{itemize} +\item output: $out := \mbox{scale}$ +\item exception: None +\end{itemize} + +\noindent count($t$: T): +\begin{itemize} +\item output: \wss{Count the number of times the value $t$ occurs in the 2D + sequence.}$out := +(i, j: \mathbb{N}| \mbox{validRow}(i) \land + \mbox{validCol}(j) \wedge s[i][j] = t : 1)$ +\item exception: None +\end{itemize} + +\noindent count($l$: LineT, $t$: T): +\begin{itemize} +\item output: \wss{Count the number of times the value $t$ occurs in the line + $l$.}$out := +(p: \mbox{PointT} | p \in \mbox{pointsInLine}(l) \wedge + s[p.y][p.x] = t : 1)$ +\item exception: \wss{Exception if any point on the line lies off of the 2D + sequence (map)}$exc := (\neg\mbox{validLine}(l) \Rightarrow \mbox{invalid\_argument})$ +\end{itemize} + +\noindent count($\mathit{pth}$: PathT, $t$: T): +\begin{itemize} +\item output: \wss{Count the number of times the value $t$ occurs in the path + $pth$.}$out := +(p: \mbox{PointT} | p \in \mbox{pointsInPath}(\mathit{pth}) + \wedge s[p.y][p.x] = t : 1)$ +\item exception: \wss{Exception if any point on the path lies off of the 2D + sequence (map)}$exc := (\neg\mbox{validPath}(\mathit{pth}) \Rightarrow \mbox{invalid\_argument})$ +\end{itemize} + +\noindent length($\mathit{pth}$: PathT): +\begin{itemize} +\item output: \wss{Use the scale to find the length of the + path.}$out := \mathit{pth}.\mbox{len} \cdot \mbox{scale}$ +\item exception: \wss{Exception if any point on the path lies off of the 2D + sequence (map)}$exc := (\neg\mbox{validPath}(\mathit{pth}) \Rightarrow \mbox{invalid\_argument})$ +\end{itemize} + +\noindent connected($p_1$: PointT, $p_2$: PointT): +\begin{itemize} +\item output: \wss{Return true if a path exists between $p_1$ and $p_2$ with all + of the points on the path being of the same value. $p_1$ and $p_2$ are + considered to be part of the path.} + $out := \exists (\mathit{pth}: \mbox{PathT} | \mbox{validPath}(\mathit{pth}) + \wedge \mathit{pth}.\mbox{strt} = p_1 \wedge \mathit{pth}.\mbox{end} = p_2 : + \mbox{count}(\mathit{pth}, s[p_1.y][p_1.x]) = \mathit{pth}.\mbox{len})$ +\item exception: \wss{Return an exception if either of the input points is not + valid.}$exc := (\neg\mbox{validPoint}(p_1) \vee \neg\mbox{validPoint}(p_1) + \Rightarrow \mbox{invalid\_argument})$ + +\end{itemize} + +\subsection*{Local Functions} + +\noindent validRow: $\mathbb{N} \rightarrow \mathbb{B}$\\ +\noindent \wss{returns true if the given natural number is a valid row + number.}$\mbox{validRow}(i) \equiv 0 \leq i \leq (\mbox{nRow} - 1)$\\ + +\noindent validCol: $\mathbb{N} \rightarrow \mathbb{B}$\\ +\noindent \wss{returns true if the given natural number is a valid column + number.}$\mbox{validCol}(j) \equiv 0 \leq j \leq (\mbox{nCol} - 1)$\\ + +\noindent validPoint: $\mbox{PointT} \rightarrow \mathbb{B}$\\ +\noindent \wss{Returns true if the given point lies within the boundaries of the + map.}$\mbox{validPoint}(p) \equiv \mbox{validRow}(p.y) \wedge \mbox{validCol}(p.x)$\\ + +\noindent validLine: $\mbox{LineT} \rightarrow \mathbb{B}$\\ +\noindent \wss{Returns true if all of the points for the given line lie within the boundaries of the + map.}$\mbox{validLine}(l) \equiv \forall(p: \mbox{PointT} | p \in \mbox{pointsInLine}(l): + \mbox{validPoint}(p))$\\ + +\noindent validPath: $\mbox{PathT} \rightarrow \mathbb{B}$\\ +\noindent \wss{Returns true if all of the points for the given path lie within the boundaries of the + map.}$\mbox{validPath}(\mathit{pth}) \equiv \forall(p: \mbox{PointT} | p \in \mbox{pointsInPath}(\mathit{pth}): + \mbox{validPoint}(p))$\\ + +\noindent pointsInLine: $\mbox{LineT} \rightarrow \mbox{(set of PointT)}$\\ +\noindent pointsInLine ($l$) +\wss{The same local function as given in the Path module.} +\begin{multline*} +\equiv \{ i: \mathbb{N} | i \in [0 + .. (l.\mbox{len} - 1)] : l.\mbox{strt}.\mbox{translate}(\\ +(l.\mbox{orient}=\mbox{W} \Rightarrow -i | + l.\mbox{orient}=\mbox{E} \Rightarrow i | \mbox{True} \Rightarrow 0), (l.\mbox{orient}=\mbox{N} \Rightarrow i | + l.\mbox{orient}=\mbox{S} \Rightarrow -i | \mbox{True} \Rightarrow 0) ) \} +\end{multline*} + +\noindent pointsInPath: $\mbox{PathT} \rightarrow \mbox{(set of PointT)}$\\ +\wss{Return the set of points that make up the input path.} +\noindent pointsInPath($p$) +$\equiv \cup (i: \mathbb{N} | i \in [0..p.\mbox{size}]: +\mbox{pointsInLine}(p.\mbox{line}(i)))$ + +\newpage + +\section* {LanduseMap Module} + +\subsection* {Template Module} + +LanduseMapT is Seq2D(LanduseT) + +\section* {DEM Module} + +\subsection* {Template Module} + +DEMT is Seq2D($\mathbb{Z}$) + +\newpage + +\section{Critique of Design} + +Write a critique of the interface for the modules in this project. Is there +anything missing? Is there anything you would consider changing? Why? + +\end {document} \ No newline at end of file diff --git a/Assignments/A4/A4.pdf b/Assignments/A4/A4.pdf new file mode 100644 index 0000000000000000000000000000000000000000..beda6ad8ab3f8283393dcc69dc3aa21526eff71c Binary files /dev/null and b/Assignments/A4/A4.pdf differ diff --git a/Assignments/A4/A4.tex b/Assignments/A4/A4.tex new file mode 100644 index 0000000000000000000000000000000000000000..617aea723fdf8ae499ee9a12aa06488c55268fb4 --- /dev/null +++ b/Assignments/A4/A4.tex @@ -0,0 +1,97 @@ +\documentclass[12pt]{article} + +\usepackage{graphicx} +\usepackage{paralist} +\usepackage{amsfonts} +\usepackage{hyperref} + +\oddsidemargin 0mm +\evensidemargin 0mm +\textwidth 160mm +\textheight 200mm +\renewcommand\baselinestretch{1.0} + +\pagestyle {plain} +\pagenumbering{arabic} + +\newcounter{stepnum} + +\title{DRAFT Assignment 4} +\author{COMP SCI 2ME3, SFWR ENG 2AA4} + +\begin {document} + +\maketitle + +\begin{description} +\item [Assigned:] March 22, 2018 +\item [Spec and Code:] April 9, 2018 +\item [Last Revised:] \today +\end{description} + +\noindent All submissions are made through git, using your own repo located at:\\ + +\texttt{https://gitlab.cas.mcmaster.ca/se2aa4\_cs2me3\_assignments\_2018/[macid].git}\\ + +\noindent where \texttt{[macid]} should be replaced with your actual macid. The +time for all deadlines is 11:59 pm. + +\section{Introduction} + +The purpose of this assignment is to design and specify a module (or modules) to +store the state of a game of Freecell. The modules cover the Model portion of +the Model View Controller design pattern. The rules for Freecell can be found +at the following web-page: + +~\newline \href {https://www.freecell-solitaire-download.com/rules.html} +{https://www.freecell-solitaire-download.com/rules.html} ~\newline + +A sample implementation can be found at: + +~\newline \href {http://www.cardgamesolitaire.com/freecell.php} +{http://www.cardgamesolitaire.com/freecell.php} ~\newline + +Your assignment is for the module that stores the state of the game board and +the status of the game. You do not need to worry about modules that display +graphics, or control the game play, etc. + +Your specification should be written using LaTeX. All of your code should be +written in C++. All code files, except for testing files, should be documented +using doxygen. Your test code should use \texttt{catch}, version 2. + +\section*{Part 1} + +\section *{Step \refstepcounter{stepnum} \thestepnum} + +Submit your design specification, written in LaTeX, of the MIS for the game +state module. If your specification requires additional modules, you should +include their MISes as well. It is up to you to determine your modules +interface; that is, you decide on the exported constants, access programs, +exceptions etc. You also determine your state variables and specify the +semantics for your access program calls. Your design does not need to concern +itself with performance. + +\section*{Part 2} + +\section *{Step \refstepcounter{stepnum} \thestepnum} + +Submit C++ code that matches the specification given in the previous step. You +should also submit code that tests your module(s) using \texttt{catch} 2. +Document your source code using doxygen. You code should include a makefile, +with rules \texttt{make test} and \texttt{make doc}. Performance will not be +considered in the grading. + +\subsubsection*{Notes} + +\begin{enumerate} +\item Your git repo is organized with the following directories at the top + level: {\tt A1}, {\tt A2}, {\tt A3}, and {\tt A4}. Your specification and + code files should be placed in the {\tt A4} folder +\item Please put your name and macid at the top of each of your source files. +\item Your program must work in the ITB labs on mills. +\item \textbf{Any changes to the assignment specification will be announced in + class. It is your responsibility to be aware of these changes. Please + monitor all pushes to the course git repo.} +\end{enumerate} + +\end {document} \ No newline at end of file diff --git a/Assignments/A4/Assig4.pdf b/Assignments/A4/Assig4.pdf deleted file mode 100644 index 297c2a55ee2fc62bce67786b8b5b72accbe36948..0000000000000000000000000000000000000000 Binary files a/Assignments/A4/Assig4.pdf and /dev/null differ diff --git a/Assignments/A4/Assig4.tex b/Assignments/A4/Assig4.tex deleted file mode 100644 index a77bedf6bf62f60aa83a06bd6c09091ffed918f3..0000000000000000000000000000000000000000 --- a/Assignments/A4/Assig4.tex +++ /dev/null @@ -1,26 +0,0 @@ -\documentclass[12pt]{article} - -\usepackage{graphicx} -\usepackage{paralist} -\usepackage{amsfonts} -\usepackage{hyperref} - -\oddsidemargin 0mm -\evensidemargin 0mm -\textwidth 160mm -\textheight 200mm -\renewcommand\baselinestretch{1.0} - -\pagestyle {plain} -\pagenumbering{arabic} - -\newcounter{stepnum} - -\title{Assignment 4} -\author{COMP SCI 2ME3, SFWR ENG 2AA4} - -\begin {document} - -\maketitle - -\end {document} \ No newline at end of file diff --git a/Lectures/Figures/Adapter.png b/Lectures/Figures/Adapter.png new file mode 100644 index 0000000000000000000000000000000000000000..bee9923049afbe4a18bc86df4f55ba06b0803892 Binary files /dev/null and b/Lectures/Figures/Adapter.png differ diff --git a/Lectures/Figures/MVC.png b/Lectures/Figures/MVC.png new file mode 100644 index 0000000000000000000000000000000000000000..33c30238afb98ae3ff2903e35860581373f79696 Binary files /dev/null and b/Lectures/Figures/MVC.png differ diff --git a/Lectures/Figures/MVCExampleStudent.png b/Lectures/Figures/MVCExampleStudent.png new file mode 100644 index 0000000000000000000000000000000000000000..3cbc33e785c0735a3f27db90a016fdc6885a9dec Binary files /dev/null and b/Lectures/Figures/MVCExampleStudent.png differ diff --git a/Lectures/Figures/MeasurableInterface.pdf b/Lectures/Figures/MeasurableInterface.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c59665831ba138e22f2922cb4862e65f424fd183 Binary files /dev/null and b/Lectures/Figures/MeasurableInterface.pdf differ diff --git a/Lectures/Figures/WebAppMVC.png b/Lectures/Figures/WebAppMVC.png new file mode 100644 index 0000000000000000000000000000000000000000..bc2e69c290cd3e15ef1007e41e16a7bf5b74bdb5 Binary files /dev/null and b/Lectures/Figures/WebAppMVC.png differ diff --git a/Lectures/Figures/command.png b/Lectures/Figures/command.png new file mode 100644 index 0000000000000000000000000000000000000000..2810e07df5203815d9cf29b1f9155865601ee824 Binary files /dev/null and b/Lectures/Figures/command.png differ diff --git a/Lectures/L25_EnglishToMath/EnglishToMath.pdf b/Lectures/L25_EnglishToMath/EnglishToMath.pdf index 75c27728b9e8e76d3524bdffcba8833fb7f01460..8532c1c17590a9b239fb7b8f76a3472a77fbff69 100644 Binary files a/Lectures/L25_EnglishToMath/EnglishToMath.pdf and b/Lectures/L25_EnglishToMath/EnglishToMath.pdf differ diff --git a/Lectures/L25_EnglishToMath/EnglishToMath.tex b/Lectures/L25_EnglishToMath/EnglishToMath.tex index beade9ed6b231a71617ad4e7c90e220d5c345380..8a4dddd42111d7423177964003c5c885ff36afa0 100755 --- a/Lectures/L25_EnglishToMath/EnglishToMath.tex +++ b/Lectures/L25_EnglishToMath/EnglishToMath.tex @@ -162,7 +162,7 @@ See \begin{itemize} -\item Therefore, mathematics is the language of engineering +\item Therefore, mathematics is the language of engineering and science \end{itemize} @@ -418,7 +418,8 @@ See \item Modularize \item Example \bi -\item Find the location in $D$ of a particular value $key$ +\item Find the location in $D (: \mbox{sequence of } T)$ of a particular value + $key (: T)$ \item \structure<1>{What are the two cases?} \item \uncover<2->{$key$ in $D$, $key$ not in $D$} \item \uncover<3->{\structure<3>{How do you mathematically specify $key$ is @@ -446,7 +447,7 @@ See \item $n=\inf$ \end{itemize} \item Think of a normal sized problem, usually something like $n \geq 3$ -\item You might want to write down truth tables +\item You might want to write down truth tables (or Parnas tables) \end{itemize} @@ -528,13 +529,13 @@ or more students have the same birthday. Write a mathematical expression that is True if this condition is met, and False otherwise\\ \bi -\item \structure<1>{Identify all objects referred to in this message} +\item \structure<1>{Identify all objects referred to in this problem statement} \item \uncover<2->{{Class? Students? Many? Instructor? Birthday?}} \item \uncover<2->{\structure<2>{Distinguish between essential objects and background information}} \item \uncover<3->{\structure<3>{How would we model the relationship between a student and their birthday? A set? A type? A variable? A relation? \structure<4>{A function?}}} -\item \uncover<4->{\structure<4>{Using $\mbox{StudentT}$, $C: \mbox{StudentT}$ and +\item \uncover<4->{\structure<4>{Using $\mbox{StudentT}$, $C: \mbox{set of StudentT}$ and $\mbox{Bday}(s1) = \mbox{Bday}(s2)$ what is the predicate?}} \item \uncover<5->{$\vee (s1, s2: \mbox{StudentT} | s1 \in C \wedge s2 \in C \wedge s1 \neq s2 : \mbox{Bday}(s1) = \mbox{Bday}(s2))$} diff --git a/Lectures/L26_SpecViaUML/DataSet/Makefile b/Lectures/L26_SpecViaUML/DataSet/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSet/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSet/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSet/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSet/bin/experiment b/Lectures/L26_SpecViaUML/DataSet/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..0d59df813474bbcda943bcd3eeac9395c83bd62f Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSet/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSet/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSet/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..205661e09ee57ff9b04a4aebbb2d121d940b5fcd --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSet/experimentation/main.cpp @@ -0,0 +1,18 @@ +#include "DataSet.h" + +#include <iostream> +using namespace std; + +int main() { + + DataSet ds; + ds.add(0.0); + ds.add(5.0); + ds.add(25.0); + ds.add(13.0); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSet/include/DataSet.h b/Lectures/L26_SpecViaUML/DataSet/include/DataSet.h new file mode 100644 index 0000000000000000000000000000000000000000..d709321a22a716352d80b09094c47d44f69b89e5 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSet/include/DataSet.h @@ -0,0 +1,18 @@ +#ifndef DATASET_H +#define DATASET_H + +class DataSet +{ + private: + double sum; + double maximum; + int count; + + public: + DataSet(); + void add(double x); + double getAverage(); + double getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSet/src/DataSet.cpp b/Lectures/L26_SpecViaUML/DataSet/src/DataSet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0cc8a8e5fd5d52df620a79d81c5d173b249d71e7 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSet/src/DataSet.cpp @@ -0,0 +1,26 @@ +#include "DataSet.h" + +DataSet::DataSet() +{ + this->sum = 0.0; + this->maximum = 0.0; + this->count = 0; +} + +void DataSet::add(double x) +{ + this->sum += x; + if (count == 0 || maximum < x) maximum = x; + count++; +} + +double DataSet::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +double DataSet::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/Makefile b/Lectures/L26_SpecViaUML/DataSetBankAccount/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSetBankAccount/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/bin/experiment b/Lectures/L26_SpecViaUML/DataSetBankAccount/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..9282b727ae21b5adf2bb74c2d25334fc18f6464d Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetBankAccount/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSetBankAccount/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc590ff8b37b3fd881ea44fb29cef447e51a2b9c --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/experimentation/main.cpp @@ -0,0 +1,23 @@ +#include "BankAccount.h" +#include "DataSetBankAccount.h" + +#include <iostream> +using namespace std; + +int main() +{ + + BankAccount b1; + b1.deposit(300); + BankAccount b2; + b2.deposit(100); + + DataSetBankAccount ds; + ds.add(b1); + ds.add(b2); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/include/BankAccount.h b/Lectures/L26_SpecViaUML/DataSetBankAccount/include/BankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..90b9e5870c46c1cefed0a3c8ec91c823cdcaed2a --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/include/BankAccount.h @@ -0,0 +1,20 @@ +#ifndef BANKACCOUNT_H +#define BANKACCOUNT_H + +#include <iostream> + +class BankAccount +{ + public: + BankAccount(); + void deposit(double amount); + void withdraw(double amount); + double getBalance(); + + friend std::ostream& operator<< (std::ostream &out, const BankAccount &ba); + + private: + double balance; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h b/Lectures/L26_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..fbc4622bd3e39e2aaf2acbfb53ecee1c7e977295 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h @@ -0,0 +1,20 @@ +#ifndef DATASETBANKACCOUNT_H +#define DATASETBANKACCOUNT_H + +#include "BankAccount.h" + +class DataSetBankAccount +{ + private: + double sum; + BankAccount maximum; + int count; + + public: + DataSetBankAccount(); + void add(BankAccount x); + double getAverage(); + BankAccount getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp b/Lectures/L26_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e4673801d59ef59e3a660e07c6fa33fdd72f085 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp @@ -0,0 +1,29 @@ +#include "BankAccount.h" + +BankAccount::BankAccount() +{ + this->balance = 0.0; +} + +void BankAccount::deposit(double amount) +{ + this->balance += amount; +} + +void BankAccount::withdraw(double amount) +{ + this->balance -= amount; +} + +double BankAccount::getBalance() +{ + return balance; +} + +std::ostream& operator<< (std::ostream &out, const BankAccount &ba) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + out << "BankAccount(" << ba.balance << ") "; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp b/Lectures/L26_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..975543369132ab972b32d01fa8bd5828a50f86d8 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp @@ -0,0 +1,26 @@ +#include "DataSetBankAccount.h" +#include "BankAccount.h" + +DataSetBankAccount::DataSetBankAccount() : maximum() +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetBankAccount::add(BankAccount x) +{ + this->sum += x.getBalance(); + if (count == 0 || maximum.getBalance() < x.getBalance()) maximum = x; + count++; +} + +double DataSetBankAccount::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +BankAccount DataSetBankAccount::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/Makefile b/Lectures/L26_SpecViaUML/DataSetInterface/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSetInterface/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/bin/experiment b/Lectures/L26_SpecViaUML/DataSetInterface/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..e1e8c00d74884768128abb8a40ccd58f9e5e95ba Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetInterface/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSetInterface/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..362986cb668629a69d411c318f794a4c2ed69402 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/experimentation/main.cpp @@ -0,0 +1,51 @@ +#include "PointT.h" +#include "BankAccount.h" +#include "DataSetInterface.h" + +#include <iostream> +using namespace std; + +int main() +{ + + //Test Data Set Inteface with PointT + PointT p1(0.0, 0.0); + PointT p2(3.0, 4.0); + PointT p3(7.0, 24.0); + PointT p4(5.0, 12.0); + + DataSetInterface ds; + ds.add(&p1); + ds.add(&p2); + ds.add(&p3); + ds.add(&p4); + + cout << "average = " << ds.getAverage() << "\n"; + + Measurable *maxM = ds.getMaximum(); + + PointT *maxP = (PointT*) maxM; + + cout << "maximum = " << *maxP << "\n"; + + //Test Data Set Inteface with Bank Account + + BankAccount b1; + b1.deposit(300); + BankAccount b2; + b2.deposit(100); + + DataSetInterface dsBank; + dsBank.add(&b1); + dsBank.add(&b2); + + cout << "average = " << dsBank.getAverage() << "\n"; + + maxM = dsBank.getMaximum(); + + BankAccount *maxB = (BankAccount*) maxM; + + cout << "maximum = " << *maxB << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/include/BankAccount.h b/Lectures/L26_SpecViaUML/DataSetInterface/include/BankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..70a52a482779aa306f125a7d8132faabbfdf8fb1 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/include/BankAccount.h @@ -0,0 +1,24 @@ +#ifndef BANKACCOUNT_H +#define BANKACCOUNT_H + +#include "Measurable.h" + +#include <iostream> + +class BankAccount : public Measurable +{ + public: + BankAccount(); + void deposit(double amount); + void withdraw(double amount); + double getBalance(); + + friend std::ostream& operator<< (std::ostream &out, const BankAccount &ba); + + double getMeasure(); + + private: + double balance; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/include/DataSetInterface.h b/Lectures/L26_SpecViaUML/DataSetInterface/include/DataSetInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..ae93b2308f729be1ab4bfd1ee4ba900aa37fe1fb --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/include/DataSetInterface.h @@ -0,0 +1,20 @@ +#ifndef DATASETINTERFACE_H +#define DATASETINTERFACE_H + +#include "Measurable.h" + +class DataSetInterface +{ + private: + double sum; + Measurable *maximum; + int count; + + public: + DataSetInterface(); + void add(Measurable *x); + double getAverage(); + Measurable *getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/include/Measurable.h b/Lectures/L26_SpecViaUML/DataSetInterface/include/Measurable.h new file mode 100644 index 0000000000000000000000000000000000000000..16c20c1a00f08018823afa2f7e31d86f7cd168cf --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/include/Measurable.h @@ -0,0 +1,10 @@ +#ifndef MEASURABLE_H +#define MEASURABLE_H + +class Measurable +{ + public: + virtual double getMeasure() = 0; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/include/PointT.h b/Lectures/L26_SpecViaUML/DataSetInterface/include/PointT.h new file mode 100644 index 0000000000000000000000000000000000000000..324f9ee4a8c399c6849df54c8540d52fa997bc0e --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/include/PointT.h @@ -0,0 +1,25 @@ +#ifndef POINTT_H +#define POINTT_H + +#include "Measurable.h" + +#include <iostream> + +class PointT : public Measurable +{ + public: + PointT(double x, double y); + double xcoord(); + double ycoord(); + double distToOrigin(); + + friend std::ostream& operator<< (std::ostream &out, const PointT &point); + + double getMeasure(); + + private: + double xc; + double yc; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/src/BankAccount.cpp b/Lectures/L26_SpecViaUML/DataSetInterface/src/BankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2abe22d20604df3233bde6a7c4cb606104e5ab69 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/src/BankAccount.cpp @@ -0,0 +1,34 @@ +#include "BankAccount.h" + +BankAccount::BankAccount() +{ + this->balance = 0.0; +} + +void BankAccount::deposit(double amount) +{ + this->balance += amount; +} + +void BankAccount::withdraw(double amount) +{ + this->balance -= amount; +} + +double BankAccount::getBalance() +{ + return balance; +} + +double BankAccount::getMeasure() +{ + return balance; +} + +std::ostream& operator<< (std::ostream &out, const BankAccount &ba) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + out << "BankAccount(" << ba.balance << ") "; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/src/DataSetInterface.cpp b/Lectures/L26_SpecViaUML/DataSetInterface/src/DataSetInterface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83204b04c836f9141f78ca1b44ee43e53bc25b4e --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/src/DataSetInterface.cpp @@ -0,0 +1,26 @@ +#include "DataSetInterface.h" +#include "Measurable.h" + +DataSetInterface::DataSetInterface() : maximum() +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetInterface::add(Measurable *x) +{ + this->sum += x->getMeasure(); + if (count == 0 || maximum->getMeasure() < x->getMeasure()) maximum = x; + count++; +} + +double DataSetInterface::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +Measurable *DataSetInterface::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L26_SpecViaUML/DataSetInterface/src/PointT.cpp b/Lectures/L26_SpecViaUML/DataSetInterface/src/PointT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e79171ebb5318185dc2d4d86c78de056969e780 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetInterface/src/PointT.cpp @@ -0,0 +1,45 @@ +#include "PointT.h" +#include <cmath> + +#include "Measurable.h" + +PointT::PointT(double x, double y) +{ + this->xc = x; + this->yc = y; +} + +double PointT::xcoord() +{ + return this->xc; +} + +double PointT::ycoord() +{ + return this->yc; +} + +double PointT::distToOrigin() +{ + double dx; + double dy; + + dx = this->xc; + dy = this->yc; + + return sqrt(pow(dx,2.0) + pow(dy,2.0)); +} + +double PointT::getMeasure() +{ + return this->distToOrigin(); +} + +std::ostream& operator<< (std::ostream &out, const PointT& point) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + // Since operator<< is a friend of the Point class, we can access Point's members directly. + out << "PointT(" << point.xc << ", " << point.yc << ")"; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/Makefile b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/bin/experiment b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..6d4c70fa59ee5d0634c23861f7c618e64f8cd435 Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de0e6cf8e696e6599e44b257fc1171b580e2cd0a --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/experimentation/main.cpp @@ -0,0 +1,31 @@ +#include "PointMT.h" +#include "DataSetInterface.h" + +#include <iostream> +using namespace std; + +int main() +{ + + //Test Data Set Inteface with PointT + PointMT p1(0.0, 0.0); + PointMT p2(3.0, 4.0); + PointMT p3(7.0, 24.0); + PointMT p4(5.0, 12.0); + + DataSetInterface ds; + ds.add(&p1); + ds.add(&p2); + ds.add(&p3); + ds.add(&p4); + + cout << "average = " << ds.getAverage() << "\n"; + + Measurable *maxM = ds.getMaximum(); + + PointMT *maxP = (PointMT*) maxM; + + cout << "maximum = " << *maxP << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/DataSetInterface.h b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/DataSetInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..ae93b2308f729be1ab4bfd1ee4ba900aa37fe1fb --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/DataSetInterface.h @@ -0,0 +1,20 @@ +#ifndef DATASETINTERFACE_H +#define DATASETINTERFACE_H + +#include "Measurable.h" + +class DataSetInterface +{ + private: + double sum; + Measurable *maximum; + int count; + + public: + DataSetInterface(); + void add(Measurable *x); + double getAverage(); + Measurable *getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/Measurable.h b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/Measurable.h new file mode 100644 index 0000000000000000000000000000000000000000..16c20c1a00f08018823afa2f7e31d86f7cd168cf --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/Measurable.h @@ -0,0 +1,10 @@ +#ifndef MEASURABLE_H +#define MEASURABLE_H + +class Measurable +{ + public: + virtual double getMeasure() = 0; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointMT.h b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointMT.h new file mode 100644 index 0000000000000000000000000000000000000000..c8c28f14ebfd71a684632969396aa4305bf6aa17 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointMT.h @@ -0,0 +1,14 @@ +#ifndef POINTMT_H +#define POINTMT_H + +#include "PointT.h" +#include "Measurable.h" + +class PointMT : public PointT, public Measurable +{ + public: + PointMT(double x, double y); + double getMeasure(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointT.h b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointT.h new file mode 100644 index 0000000000000000000000000000000000000000..ce3f800ecd4af22fe4c37714023a797d48500acd --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/include/PointT.h @@ -0,0 +1,21 @@ +#ifndef POINTT_H +#define POINTT_H + +#include <iostream> + +class PointT +{ + public: + PointT(double x, double y); + double xcoord(); + double ycoord(); + double distToOrigin(); + + friend std::ostream& operator<< (std::ostream &out, const PointT &point); + + private: + double xc; + double yc; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/DataSetInterface.cpp b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/DataSetInterface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83204b04c836f9141f78ca1b44ee43e53bc25b4e --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/DataSetInterface.cpp @@ -0,0 +1,26 @@ +#include "DataSetInterface.h" +#include "Measurable.h" + +DataSetInterface::DataSetInterface() : maximum() +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetInterface::add(Measurable *x) +{ + this->sum += x->getMeasure(); + if (count == 0 || maximum->getMeasure() < x->getMeasure()) maximum = x; + count++; +} + +double DataSetInterface::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +Measurable *DataSetInterface::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointMT.cpp b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointMT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..efc60b99b498ff7e05225b6d5819b6542c7bc56a --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointMT.cpp @@ -0,0 +1,11 @@ +#include "PointMT.h" +#include "Measurable.h" + +PointMT::PointMT(double x, double y) : PointT(x, y) +{ +} + +double PointMT::getMeasure() +{ + return this->distToOrigin(); +} diff --git a/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointT.cpp b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f1d5014514b00c70bbffe4c957e03fa9eb3ef62 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetMultipleInheritance/src/PointT.cpp @@ -0,0 +1,38 @@ +#include "PointT.h" +#include <cmath> + +PointT::PointT(double x, double y) +{ + this->xc = x; + this->yc = y; +} + +double PointT::xcoord() +{ + return this->xc; +} + +double PointT::ycoord() +{ + return this->yc; +} + +double PointT::distToOrigin() +{ + double dx; + double dy; + + dx = this->xc; + dy = this->yc; + + return sqrt(pow(dx,2.0) + pow(dy,2.0)); +} + +std::ostream& operator<< (std::ostream &out, const PointT& point) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + // Since operator<< is a friend of the Point class, we can access Point's members directly. + out << "PointT(" << point.xc << ", " << point.yc << ")"; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/Makefile b/Lectures/L26_SpecViaUML/DataSetPointT/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSetPointT/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/bin/experiment b/Lectures/L26_SpecViaUML/DataSetPointT/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..674f0f6c1ffbc463f3ebf29fbb5d2acb7c1e0d3d Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetPointT/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSetPointT/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e135e0ffe1abd64ceda2cc412b9e41295d57bf50 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/experimentation/main.cpp @@ -0,0 +1,20 @@ +#include "PointT.h" +#include "DataSetPoint.h" + +#include <iostream> +using namespace std; + +int main() +{ + + DataSetPoint ds; + ds.add(PointT(0.0, 0.0)); + ds.add(PointT(3.0, 4.0)); + ds.add(PointT(7.0, 24.0)); + ds.add(PointT(5.0, 12.0)); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/include/DataSetPoint.h b/Lectures/L26_SpecViaUML/DataSetPointT/include/DataSetPoint.h new file mode 100644 index 0000000000000000000000000000000000000000..bcc6f2698b6b83a0a32534baf6386ba57d37eab9 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/include/DataSetPoint.h @@ -0,0 +1,20 @@ +#ifndef DATASETPOINT_H +#define DATASETPOINT_H + +#include "PointT.h" + +class DataSetPoint +{ + private: + double sum; + PointT maximum; + int count; + + public: + DataSetPoint(); + void add(PointT x); + double getAverage(); + PointT getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/include/PointT.h b/Lectures/L26_SpecViaUML/DataSetPointT/include/PointT.h new file mode 100644 index 0000000000000000000000000000000000000000..ce3f800ecd4af22fe4c37714023a797d48500acd --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/include/PointT.h @@ -0,0 +1,21 @@ +#ifndef POINTT_H +#define POINTT_H + +#include <iostream> + +class PointT +{ + public: + PointT(double x, double y); + double xcoord(); + double ycoord(); + double distToOrigin(); + + friend std::ostream& operator<< (std::ostream &out, const PointT &point); + + private: + double xc; + double yc; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp b/Lectures/L26_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc6da8faa43b1d40e9e2de8140453c5c48f58525 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp @@ -0,0 +1,26 @@ +#include "DataSetPoint.h" +#include "PointT.h" + +DataSetPoint::DataSetPoint() : maximum(0.0, 0.0) +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetPoint::add(PointT x) +{ + this->sum += x.distToOrigin(); + if (count == 0 || maximum.distToOrigin() < x.distToOrigin()) maximum = x; + count++; +} + +double DataSetPoint::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +PointT DataSetPoint::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L26_SpecViaUML/DataSetPointT/src/PointT.cpp b/Lectures/L26_SpecViaUML/DataSetPointT/src/PointT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f1d5014514b00c70bbffe4c957e03fa9eb3ef62 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetPointT/src/PointT.cpp @@ -0,0 +1,38 @@ +#include "PointT.h" +#include <cmath> + +PointT::PointT(double x, double y) +{ + this->xc = x; + this->yc = y; +} + +double PointT::xcoord() +{ + return this->xc; +} + +double PointT::ycoord() +{ + return this->yc; +} + +double PointT::distToOrigin() +{ + double dx; + double dy; + + dx = this->xc; + dy = this->yc; + + return sqrt(pow(dx,2.0) + pow(dy,2.0)); +} + +std::ostream& operator<< (std::ostream &out, const PointT& point) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + // Since operator<< is a friend of the Point class, we can access Point's members directly. + out << "PointT(" << point.xc << ", " << point.yc << ")"; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/Makefile b/Lectures/L26_SpecViaUML/DataSetTemplate/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/bin/.gitkeep b/Lectures/L26_SpecViaUML/DataSetTemplate/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/bin/experiment b/Lectures/L26_SpecViaUML/DataSetTemplate/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..1d18dba6b3dd053f4af4df8ba610796138725f12 Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetTemplate/bin/experiment differ diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/experimentation/main.cpp b/Lectures/L26_SpecViaUML/DataSetTemplate/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81f42b8a16ea36fe1c226bd850116eba7550f18a --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/experimentation/main.cpp @@ -0,0 +1,46 @@ +#include "PointT.h" +#include "BankAccount.h" +#include "DataSetTemplate.h" + +#include <iostream> +using namespace std; + +typedef DataSetTemplate<PointT> DataSetPointT; +typedef DataSetTemplate<BankAccount> DataSetBankAccount; + +int main() +{ + + //Test Data Set Inteface with PointT + PointT p1(0.0, 0.0); + PointT p2(3.0, 4.0); + PointT p3(7.0, 24.0); + PointT p4(5.0, 12.0); + + DataSetPointT ds; + ds.add(p1); + ds.add(p2); + ds.add(p3); + ds.add(p4); + + cout << "average = " << ds.getAverage() << "\n"; + + cout << "maximum = " << ds.getMaximum() << "\n"; + + //Test Data Set Inteface with Bank Account + + BankAccount b1; + b1.deposit(300); + BankAccount b2; + b2.deposit(100); + + DataSetBankAccount dsBank; + dsBank.add(b1); + dsBank.add(b2); + + cout << "average = " << dsBank.getAverage() << "\n"; + + cout << "maximum = " << dsBank.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/include/BankAccount.h b/Lectures/L26_SpecViaUML/DataSetTemplate/include/BankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..3fd9408245b058d8863580a74e2df0f8d71421c7 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/include/BankAccount.h @@ -0,0 +1,22 @@ +#ifndef BANKACCOUNT_H +#define BANKACCOUNT_H + +#include <iostream> + +class BankAccount +{ + public: + BankAccount(); + void deposit(double amount); + void withdraw(double amount); + double getBalance(); + + friend std::ostream& operator<< (std::ostream &out, const BankAccount &ba); + + double getMeasure(); + + private: + double balance; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/include/DataSetTemplate.h b/Lectures/L26_SpecViaUML/DataSetTemplate/include/DataSetTemplate.h new file mode 100644 index 0000000000000000000000000000000000000000..15f22feafb589688a7360265a6c2b3e382a80988 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/include/DataSetTemplate.h @@ -0,0 +1,19 @@ +#ifndef DATASETTEMPLATE_H +#define DATASETTEMPLATE_H + +template <class T> +class DataSetTemplate +{ + private: + double sum; + T maximum; + int count; + + public: + DataSetTemplate(); + void add(T x); + double getAverage(); + T getMaximum(); +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/include/PointT.h b/Lectures/L26_SpecViaUML/DataSetTemplate/include/PointT.h new file mode 100644 index 0000000000000000000000000000000000000000..65a934b24ddfbbbcd29460635b7cf37a96df44cd --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/include/PointT.h @@ -0,0 +1,24 @@ +#ifndef POINTT_H +#define POINTT_H + +#include <iostream> + +class PointT +{ + public: + PointT(); + PointT(double x, double y); + double xcoord(); + double ycoord(); + double distToOrigin(); + + friend std::ostream& operator<< (std::ostream &out, const PointT &point); + + double getMeasure(); + + private: + double xc; + double yc; +}; + +#endif diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/src/BankAccount.cpp b/Lectures/L26_SpecViaUML/DataSetTemplate/src/BankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2abe22d20604df3233bde6a7c4cb606104e5ab69 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/src/BankAccount.cpp @@ -0,0 +1,34 @@ +#include "BankAccount.h" + +BankAccount::BankAccount() +{ + this->balance = 0.0; +} + +void BankAccount::deposit(double amount) +{ + this->balance += amount; +} + +void BankAccount::withdraw(double amount) +{ + this->balance -= amount; +} + +double BankAccount::getBalance() +{ + return balance; +} + +double BankAccount::getMeasure() +{ + return balance; +} + +std::ostream& operator<< (std::ostream &out, const BankAccount &ba) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + out << "BankAccount(" << ba.balance << ") "; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/src/DataSetTemplate.cpp b/Lectures/L26_SpecViaUML/DataSetTemplate/src/DataSetTemplate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ee1d3bc05fa116eff8ae6e9b40da1d99e57afe34 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/src/DataSetTemplate.cpp @@ -0,0 +1,37 @@ +#include "DataSetTemplate.h" + +#include "PointT.h" +#include "BankAccount.h" + +template <class T> +DataSetTemplate<T>::DataSetTemplate() : maximum() +{ + this->sum = 0.0; + this->count = 0; +} + +template <class T> +void DataSetTemplate<T>::add(T x) +{ + this->sum += x.getMeasure(); + if (count == 0 || maximum.getMeasure() < x.getMeasure()) maximum = x; + count++; +} + +template <class T> +double DataSetTemplate<T>::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +template <class T> +T DataSetTemplate<T>::getMaximum() +{ + return maximum; +} + +// explicit instantiations +template class DataSetTemplate<PointT>; +template class DataSetTemplate<BankAccount>; + diff --git a/Lectures/L26_SpecViaUML/DataSetTemplate/src/PointT.cpp b/Lectures/L26_SpecViaUML/DataSetTemplate/src/PointT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a3e5043509fa4ab060082eaa30bdf82f059ab97 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetTemplate/src/PointT.cpp @@ -0,0 +1,49 @@ +#include "PointT.h" +#include <cmath> + +PointT::PointT() +{ + this->xc = 0.0; + this->yc = 0.0; +} + +PointT::PointT(double x, double y) +{ + this->xc = x; + this->yc = y; +} + +double PointT::xcoord() +{ + return this->xc; +} + +double PointT::ycoord() +{ + return this->yc; +} + +double PointT::distToOrigin() +{ + double dx; + double dy; + + dx = this->xc; + dy = this->yc; + + return sqrt(pow(dx,2.0) + pow(dy,2.0)); +} + +double PointT::getMeasure() +{ + return this->distToOrigin(); +} + +std::ostream& operator<< (std::ostream &out, const PointT& point) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + // Since operator<< is a friend of the Point class, we can access Point's members directly. + out << "PointT(" << point.xc << ", " << point.yc << ")"; + + return out; +} diff --git a/Lectures/L26_SpecViaUML/DataSetsAggregation.pdf b/Lectures/L26_SpecViaUML/DataSetsAggregation.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ed80247d83342071c054fdf831d2926ed83d3585 Binary files /dev/null and b/Lectures/L26_SpecViaUML/DataSetsAggregation.pdf differ diff --git a/Lectures/L26_SpecViaUML/DataSetsAggregation.xml b/Lectures/L26_SpecViaUML/DataSetsAggregation.xml new file mode 100644 index 0000000000000000000000000000000000000000..f91e3926ef0881cc883ec5224a7b9bfcbef09b55 --- /dev/null +++ b/Lectures/L26_SpecViaUML/DataSetsAggregation.xml @@ -0,0 +1 @@ +<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" version="8.4.6" editor="www.draw.io" type="device"><diagram id="51d45c3b-694b-ad9c-a1ca-de0ff4b50e78" name="Page-1">1VZdb8IgFP01fV3aslZ99HN7WbJEk7lHVq4tsS0GUdv9+lGhtohdzDJd5oPhHuDAOZdjdNA4K5443iQvjEDq+C4pHDRxfD8YhPK7AkoFoIGvgJhToiCvAeb0EzToanRHCWyNhYKxVNCNCUYszyESBoY5Zwdz2Yql5qkbHIMFzCOc2ugbJSJRaD9wG/wZaJzUJ3uunvnA0TrmbJfr8xwfrY4fNZ3hmkuv3yaYsEMLQlMHjTljQo2yYgxpZW1tm9o365g93ZtDLq7ZoNuyx+lOS59ggecgXhmVDOqOoqx9SUSWypHnoJHeCFxA0Xm4d5IkXwqwDAQv5ZLC7HZplofGca/GkpbbdRewbnJ8Im6EyoHWelk3snQfBS9urNh3/07yoyXZEgs5GVbpkRWhOGM5WSQ0l9LlxIxWzBNXVTqykhSNWhZJG3i5bBfv1Z6HoCoLKpY1gxw3M+oeQKxMntkq78p2PAKjhQLzGETrNdvmt90NtZMcUizo3jzxkr2aTueh4+n2z/qj7tlkaNZF0/ueR4mzeI6tPgm8qvtBV9BHOF8Po7tn/Z4vP7S0K9GR/J2+tW4r8fcU3vtvkW/nO7TzHVzt/u0j7/1W5i2iH4dels0/B7W8+XeGpl8=</diagram></mxfile> \ No newline at end of file diff --git a/Lectures/L26_SpecViaUML/MeasurableInterface.pdf b/Lectures/L26_SpecViaUML/MeasurableInterface.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c59665831ba138e22f2922cb4862e65f424fd183 Binary files /dev/null and b/Lectures/L26_SpecViaUML/MeasurableInterface.pdf differ diff --git a/Lectures/L26_SpecViaUML/MeasurableInterface.xml b/Lectures/L26_SpecViaUML/MeasurableInterface.xml new file mode 100644 index 0000000000000000000000000000000000000000..eb2f1155fbd26c568079747d74e7207c81fea151 --- /dev/null +++ b/Lectures/L26_SpecViaUML/MeasurableInterface.xml @@ -0,0 +1 @@ +<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" version="8.4.6" editor="www.draw.io" type="device"><diagram id="375c196d-1333-2840-e13d-7bbed8fb0d51" name="Page-1">3VbLbqMwFP0atiPAIWqWTdLHplKlVJp26eAbsAI4MiaP+fox2AaMSScaDYo0WUT28fXjnHuujYdW+fmF40P6xghkXuiTs4fWXhhGi7n8r4GLAtA8VEDCKVFQ0AEb+gs06Gu0ogRKK1Awlgl6sMGYFQXEwsIw5+xkh+1YZu96wAk4wCbGmYv+pESkCn2I/A5/BZqkZufA1yNbHO8TzqpC7+eFaNf81HCOzVo6vkwxYacehJ48tOKMCdXKzyvIammNbGre85XR9twcCnHLBJ2WI84qTX2NBd6A0McTFyNJKvJMtgIPLd1N9L5H4ALOPUhv+gIsB8EvMkSPzjT/1h+6f+rUDowZ0p7SJgNYJzhpV+5IyobmOc4ZOZy9cI7zg2SWiYZev0cLAXyHY2jhxAoyvSZ4y2WrQd4AlxXHWynftEreJGU4kZQzR8p3JgX7mJgzCmzOs4cRzv5EnCOH8xIX+8c4llU/ddkEizsSX4zUzYAtFOSxvn5lj1Ccs4J8pLSQ3OXAM61XXvuqp+986SC07GkEZyo+TZRsf9XtH1EzRx7304TVnW7sqrIlq3gMVtkLzBMQ1u0HxHoNXPX76pry4pBhQY/2gzEmr16uKYxe2aJB2S4GGVJH17P6N/hgoaElomGqFWFnoSbbLcebDBC45f6dA7YZi/cyOwSXKZA2c+NGCMIrRlDJN1boG6Hniy+rxAb5/KMzItcZ6G5GmA3zd6sR0PBumNAI7h34XxhhdlcjRIP8/e2N4LyO4b8ygux2n6YqvPv8R0+/AQ==</diagram></mxfile> \ No newline at end of file diff --git a/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.pdf b/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2056af399a59ee51edcb762a067c7ad744d232de Binary files /dev/null and b/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.pdf differ diff --git a/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.xml b/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.xml new file mode 100644 index 0000000000000000000000000000000000000000..e73ededf5d30385b0b29858bfe341b3b2ecbcd28 --- /dev/null +++ b/Lectures/L26_SpecViaUML/MeasurableInterfaceInheritance.xml @@ -0,0 +1 @@ +<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" version="8.4.6" editor="www.draw.io" type="device"><diagram id="375c196d-1333-2840-e13d-7bbed8fb0d51" name="Page-1">3VfLbqMwFP0atiPAgTbLpmk7m0gjpdK0SwffgBXAkeO85uvHYPMwJg2KhkaaLCL7+NrmnHuuDQ56zk5vHG+TBSOQOr5LTg6aO74fTEP5XwBnBaDQV0DMKVGQ1wBL+gc06Gp0TwnsjEDBWCro1gQjlucQCQPDnLOjGbZmqbnrFsdgAcsIpzb6mxKRKPQxcBv8J9A4qXb2XD2ywtEm5myf6/0cH63LnxrOcLWWjt8lmLBjC0IvDnrmjAnVyk7PkBbSVrKpea8XRuvn5pCLIRN0Wg443WvqcyzwEoR+PHGuJElElsqW56CZvYne9wBcwKkF6U3fgGUg+FmG6NGJ5l/7Q/ePjdpeZYakpXSVAawTHNcrNyRlQ/Ps54wszo4f4mwrmaWipNfu0VwAX+MIajg2gqpeGbzislUiC8C7PccrKd+4Sg6S0h9Jyokl5S8mBVu8j0waeSbpyWMPaXck0oFFeobzzVMUybIfu2686R2JT3sKp8MWcvJUnL+yRyjOWE7eE5pL7nLglRYrz13V04e+tBCatTSCExUfVZRsfxbtH0E5Rz7uRxVWdJqxi8ru2J5HYNS9wDwGYRx/QIzrwFa/rW5VXxxSLOjBvDH65NXLlZXRqlvUqdtpJ0Pq0fWs9hHeWahriaCbakXYWqjMds1xkAE8u96/csAqZdFGZofgXQKkzly/ETz/ghFU8isrtI3Q8sWnUWKdfF51RmA7A93NCJNu/oYaAXXPhhGNYJ+B/4URJnc1QtDJ360ngnU7+uMZIbSMUC474AXAuvR6sjP4BSB4+MZ70Hu4yf0ti4eW/68a3vvC8O6/NLxK6bc4vvPqGk5uNLzvXlnoZsPLbvMxpsKbD1708hc=</diagram></mxfile> \ No newline at end of file diff --git a/Lectures/L26_SpecViaUML/SpecViaUML.pdf b/Lectures/L26_SpecViaUML/SpecViaUML.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4b788ed15d8e377541d99f2bcb37fdbf2d7417b5 Binary files /dev/null and b/Lectures/L26_SpecViaUML/SpecViaUML.pdf differ diff --git a/Lectures/L26_SpecViaUML/SpecViaUML.tex b/Lectures/L26_SpecViaUML/SpecViaUML.tex new file mode 100755 index 0000000000000000000000000000000000000000..58b683f565e866a67fbf968be8beeebbe78e7574 --- /dev/null +++ b/Lectures/L26_SpecViaUML/SpecViaUML.tex @@ -0,0 +1,394 @@ +%\documentclass[t,12pt,numbers,fleqn,handout]{beamer} +\documentclass[t,12pt,numbers,fleqn]{beamer} + +\usepackage{pgfpages} +\usepackage{hyperref} +\hypersetup{colorlinks=true, + linkcolor=blue, + citecolor=blue, + filecolor=blue, + urlcolor=blue, + unicode=false} +\urlstyle{same} + +\usepackage{booktabs} +\usepackage{multirow} +\usepackage{listings} + +\useoutertheme{split} %so the footline can be seen, without needing pgfpages + +% \pgfpagesuselayout{resize to}[letterpaper,border +% shrink=5mm,landscape] %if this is uncommented, the hyperref links do not work + +\mode<presentation>{} + +\input{../def-beamer} +\Draftfalse + +\newcommand{\topicTitle}{26 Specification Via UML (Ch.\ 5 and others)} +\ifDraft +\newcommand{\topic}{\topicTitle~DRAFT} +\else +\newcommand{\topic}{\topicTitle} +\fi + +\input{../titlepage} + +\begin{document} + +\input{../footline} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{\topic} + +\begin{itemize} +\item Administrative details +\item Software tool of the day +\item Best specification technique? +\item Designing spec of modules +\item Interfaces in UML +\bi +\item Measurable interface +\item Multiple inheritance example +\ei +\item Generic classes in UML +\item Use cases with UML +\item Sequence diagrams in UML +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Administrative Details} + +\ifDraft +TBD +\else +{ +\begin{itemize} + +\item A3 +\begin{itemize} +\item Part 1 - Solution: Mar 18 +\item Part 2 - Code: due 11:59 pm Mar 26 +\end{itemize} + +\item A4 +\bi +\item Your own design and specification +\item Model module for game of Freecell +\item Due April 9 at 11:59 pm +\ei + +\item Sources of slides +\bi +\item DataSet example based on Cay Horstmann, Big Java, John Wiley \& Sons, 2002 +\item Other UML examples from Stevens, Using UML, 2006 +\item Ghezzi et al 2003 +\ei +\end{itemize} +} +\fi + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Software Tool of the Day} + +\href{https://www.draw.io/}{draw.io} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Best?} + +\bi +\item \structure{What is the best software development tool?} +\item \structure{What is the most important software design principle?} +\item \structure{What is the best specification technique?} +\item \structure{What is the best programming language?} +\item \structure{What is the best engineering/scientific discipline?} +\item \structure{What is the best movie? video game?} +\item \structure{What is the best genre of music?} +\item \structure{What is the best food?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Deciding the Best Strategy For a Given Problem} + +\bi +\item Many ways to accomplish the same goals, each with pros and cons +\item What is the approach at your company? +\item Likely maintenance, so many decisions have likely been made +\item What tools/techniques/programming language etc.\ do you know? +\item What can you afford in terms of cost/time? +\item What tool is appropriate for the task at hand? +\item What are the requirements? +\bi +\item Verifiability? +\item Maintainability? +\item Reusability? +\item etc. +\ei +\item etc. +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Modelling Larger Components} + +\begin{itemize} + +\item From last day, Baber focuses on translating low level mathematical + expressions +\item In our specification, we will also need to organize the information +\item For larger problems, think about your types, Abstract Data Types and + Abstract objects +\item Interactively switch between types, ADTs, Abstract Objects and detailed + mathematical spec +\item Example +\bi +\item Modelling game state for + \href{https://www.freecell-solitaire-download.com/rules.html} {Freecell} +\item \structure{What are some potential types?} %suitT, rankT, cardT, deckT, + %stackT, gameBoard +\item \structure{What are some mathematical expressions you will need?} %is_validMove +\ei + +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Base For Examples: DataSet} + +\href{https://gitlab.cas.mcmaster.ca/smiths/se2aa4_cs2me3/tree/master/Lectures/L26_SpecViaUML/DataSet} +{Data Set with Doubles} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram Datasets of PointT and BankAccount} + +\medskip + +\includegraphics[scale=0.85]{DataSetsAggregation.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Code for DataSetPointT and DataSetBankAccount} + +\href{https://gitlab.cas.mcmaster.ca/smiths/se2aa4_cs2me3/tree/master/Lectures/L26_SpecViaUML/DataSetPointT} +{Data Set with PointT}\\ + +~\newline + +\href{https://gitlab.cas.mcmaster.ca/smiths/se2aa4_cs2me3/tree/master/Lectures/L26_SpecViaUML/DataSetBankAccount} +{Data Set with BankAccount} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Problems} + +\bi +\item Inadequate reuse +\item Maintenance challenge +\item Examples only differ in the measure +\ei +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram of Measurable Interface} + +\medskip + +\includegraphics[scale=0.85]{MeasurableInterface.pdf} + +\begin{itemize} +\item UML diagram can also show interface method names +\item Realization arrow is like weak generalization (inheritance) +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Code For DataSetInterface} + +\href{https://gitlab.cas.mcmaster.ca/smiths/se2aa4_cs2me3/tree/master/Lectures/L26_SpecViaUML/DataSetInterface} +{Data Set with Measurable Interface} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Interface Strategy} +\begin{itemize} +\item There are limitations to the Measurable interface +\begin{itemize} +\item You can only add a Measurable interface to classes that you control +\item You can measure an object in only one way +\end{itemize} +\item Move responsibility for measuring outside of objects themselves +\item Java +\bi +\item Have another object carry out the comparison +\item Introduce a Measurer interface +\ei +\item C++ +\bi +\item Multiple inheritance +\ei +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram of Measurer Interface (Java)} + +\includegraphics[scale=0.55]{../Figures/UMLDataSetMeasurerInterface.pdf} + +\bi +\item Rectangle is part of Class java.awt +\item You cannot change it +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram of Multiple Inheritance} + +\includegraphics[scale=0.75]{MeasurableInterfaceInheritance.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Code For Multiple Inheritance} + +\href{https://gitlab.cas.mcmaster.ca/smiths/se2aa4_cs2me3/tree/master/Lectures/L26_SpecViaUML/DataSetMultipleInheritance} +{Data Set with Measurable Interface} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram for Generic Classes} + +\includegraphics[scale=0.55]{../Figures/UML_class_diagram_template.png} + +\href{https://coderanch.com/t/626984/a/5041/UML_class_diagram_template.png}{UML + Class Diagram Template} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +%\frametitle{Use Cases} + +\includegraphics[scale=0.65]{../Figures/useCaseDiagram.jpg} + +\href{http://www.agilemodeling.com/artifacts/useCaseDiagram.htm}{UML + 2 Use Case Diagrams: An Agile Introduction} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Use Cases} + +\bi +\item Often used for capturing requirements +\item From user's (actor's) viewpoint +\bi +\item Person +\item Other system +\item Hardware +\item etc. (anything external +\ei +\item Each circle is a use case +\item Lines represent possible interactions +\item An actor represents a role, individuals can take on different roles +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[plain] +%\frametitle{Use Cases} + +\includegraphics[scale=0.45]{../Figures/buying_3.jpg} + +\href{http://people.cs.ksu.edu/~reshma/buying_3.JPG}{Sequence Diagram For + On-Line Shopping} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Sequence Diagram Question} + +\bi +\item \structure{Is a sequence diagram an operational or a descriptive + specification?} +\item \structure{If objects exchange a message, should there be an association + between their classes?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Sequence Diagrams} + +\bi +\item Represents a specific use case scenario +\item How objects interact by exchanging messages +\item Time progresses in the vertical direction +\item The vertically oriented boxes show the object's lifeline +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\end{document} + diff --git a/Lectures/L27_DesignPatterns/DesignPatterns.pdf b/Lectures/L27_DesignPatterns/DesignPatterns.pdf new file mode 100644 index 0000000000000000000000000000000000000000..020094d76b4ed25c956ff87d2774499789eeeb56 Binary files /dev/null and b/Lectures/L27_DesignPatterns/DesignPatterns.pdf differ diff --git a/Lectures/L36_DesignPatterns/DesignPatterns.tex b/Lectures/L27_DesignPatterns/DesignPatterns.tex similarity index 62% rename from Lectures/L36_DesignPatterns/DesignPatterns.tex rename to Lectures/L27_DesignPatterns/DesignPatterns.tex index 669905699a5e7836f562bb2a9be4924d325269da..9f4888b889a49f62f3dc1949934c98e017193e3b 100755 --- a/Lectures/L36_DesignPatterns/DesignPatterns.tex +++ b/Lectures/L27_DesignPatterns/DesignPatterns.tex @@ -29,9 +29,9 @@ \mode<presentation>{} \input{../def-beamer} -\Drafttrue +\Draftfalse -\newcommand{\topicTitle}{36 Design Patterns} +\newcommand{\topicTitle}{27 Design Patterns} \ifDraft \newcommand{\topic}{\topicTitle~DRAFT} \else @@ -39,13 +39,14 @@ \fi \input{../titlepage} -\Drafttrue +\Draftfalse \begin{document} \input{../footline} -\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\lstset{language=java, breaklines=true, showspaces=false, + showstringspaces=false, breakatwhitespace=true} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -54,14 +55,13 @@ \begin{itemize} \item Administrative details -\item Debugging -\item Verifying performance and reliability +\item Specification using UML \item Design patterns \end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Administrative Details} @@ -74,149 +74,129 @@ TBD \item Today's slide are partially based on slides by Dr.\ Wassyng and on van Vliet (2000) -\item A4 -\bi -\item {Due April 5 at 11:59 pm} -\ei - -\item Course evaluations -\bi -\item CS 2ME3: 49\% -\item SE 2AA4: 63\% -\item \href{https://evals.mcmaster.ca/login.php}{https://evals.mcmaster.ca/} -\item Closes: 11:59 pm, Monday, April 10 -\ei +\item A3 +\begin{itemize} +\item Part 1 - Solution: Mar 18 +\item Part 2 - Code: due 11:59 pm Mar 26 +\end{itemize} -\item CAS poster and demo competition +\item A4 \bi -\item April 6, 4 - 6 pm -\item \structure{ITB/201} -\item 12 graduate student submissions +\item Your own design and specification +\item Model module for game of Freecell +\item Due April 9 at 11:59 pm \ei -\item Think about course improvements for Wednesday \end{itemize} } \fi \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Verifying Performance} +\frametitle{UML Diagram for Generic Classes} -\begin{itemize} -\item Worst case analysis versus average behaviour -\item For worst case focus on proving that the system response time is bounded - by some function of the external requests -\item Standard deviation -\item Analytical versus experimental approaches -\item Consider verifying the performance of a pacemaker -\item Visualize performance via -\bi -\item Identify a measure of performance (time, storage, FLOPS, accuracy, etc.) -\item Identify an independent variable (problem size, number of processors, - condition number, etc.) -\ei -\end{itemize} +\includegraphics[scale=0.55]{../Figures/UML_class_diagram_template.png} +\href{https://coderanch.com/t/626984/a/5041/UML_class_diagram_template.png}{UML + Class Diagram Template} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Verifying Reliability} +\frametitle{Use Cases} -\begin{itemize} -\item There are approaches to measuring reliability on a probabilistic basis, as - in other engineering fields -\item Unfortunately there are some difficulties with this approach -\item Independence of failures does not hold for software -\item Reliability is concerned with measuring the probability of the occurrence - of failure -\item Meaningful parameters include -\begin{itemize} -\item Average total number of failures observed at time $t$: $AF(t)$ -\item Failure intensity: $FI(T)=AF'(t)$ -\item Mean time to failure at time $t$: $MTTF(t) = 1/FI(t)$ -\end{itemize} -\item Time in the model can be execution or clock or calendar time -\end{itemize} +\bi +\item An overview of the usage requirements for a system +\item Made up of: +\bi +\item Actors - person, organization, external system +\item Use cases - action to be performed +\ei +\item Example of University Enterprise Resource Planning (ERP) software (Mosaic) +\bi +\item \structure{Actors?} +\item \structure{Use cases?} +\ei +\ei \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Verifying Subjective Qualities} +%\frametitle{Use Cases} -\begin{itemize} -\item \structure{What do you think is meant by empirical software engineering?} -\item \structure{What problems might be studied by empirical software - engineering?} -\item \structure{Does the usual engineering analogy hold for empirical software - engineering?} -\end{itemize} +\includegraphics[scale=0.65]{../Figures/useCaseDiagram.jpg} +\href{http://www.agilemodeling.com/artifacts/useCaseDiagram.htm}{UML + 2 Use Case Diagrams: An Agile Introduction} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Verifying Subjective Qualities} +\frametitle{Use Cases} -\begin{itemize} -\item Consider notions like simplicity, reusability, understandability … -\item Software science (due to Halstead) has been an attempt -\item Tries to measure some software qualities, such as -abstraction level, effort, … -\item by measuring some quantities on code, such as \bi -\item $\eta_1$, number of distinct operators in the program -\item $\eta_2$, number of distinct operands in the program -\item $N_1$, number of occurrences of operators in the program -\item $N_2$, number of occurrences of operands in the program +\item Often used for capturing requirements +\item From user's (actor's) viewpoint +\bi +\item Person +\item Other system +\item Hardware +\item etc. (anything external +\ei +\item Each circle is a use case +\item Lines represent possible interactions +\item An actor represents a role, individuals can take on different roles \ei -\item Extract information from repo, including number of commits, issues etc. -\item Empirical software engineering -\item Appropriate analogy switches from engineering to medicine -\end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[plain] +%\frametitle{Use Cases} + +\includegraphics[scale=0.45]{../Figures/buying_3.jpg} + +\href{http://people.cs.ksu.edu/~reshma/buying_3.JPG}{Sequence Diagram For + On-Line Shopping} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Source Code Metric} +\frametitle{Sequence Diagram Question} -\begin{itemize} -\item \structure{What are the consequences of complex code?} -\item \structure{How might you measure code complexity?} -\end{itemize} +\bi +\item \structure{Is a sequence diagram an operational or a descriptive + specification?} +\item \structure{If objects exchange a message, should there be an association + between their classes?} +\ei \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{McCabe's Source Code Metric} +\frametitle{Sequence Diagrams} -\begin{itemize} -\item Cyclomatic complexity of the control graph \bi -\item $C = e - n + 2 p$ -\item $e$ is number of edges, $n$ is number of nodes, and $p$ is number of - connected components +\item Represents a specific use case scenario +\item How objects interact by exchanging messages +\item Time progresses in the vertical direction +\item The vertically oriented boxes show the object's lifeline \ei -\item McCabe contends that well-structured modules have $C$ in range $3 .. 7$, - and $C = 10$ is a reasonable upper limit for the complexity of a single module -\item Confirmed by empirical evidence -\end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Design Patterns} @@ -225,21 +205,24 @@ abstraction level, effort, … \item Christopher Alexander (1977, buildings/towns): \begin{itemize} -\item ``Each pattern describes a problem which occurs over and over again in our environment, and then describes the -core of the solution to that problem, in such a way that you can use this solution a million times over, without ever -doing it the same way.'' +\item ``Each pattern describes a problem which occurs over and over again in our + environment, and then describes the core of the solution to that problem, in + such a way that you can use this solution a million times over, without ever + doing it the same way.'' \end{itemize} \item Design reuse (intended for OO) \item Solution for recurring problems \item Transferring knowledge from expert to novice %\item Provides language for communicating about design -\item A design pattern is a recurring structure of communicating components that solves a general design problem within a particular context -\item Design patterns consist of multiple modules, but they do not constitute an entire system architecture +\item A design pattern is a recurring structure of communicating components that + solves a general design problem within a particular context +\item Design patterns consist of multiple modules, but they do not constitute an + entire system architecture \end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Strategy Design Pattern} @@ -258,16 +241,19 @@ doing it the same way.'' \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{UML Diagram of Measurable Interface} -\includegraphics[scale=0.65]{../Figures/UMLDataSetMeasurableInterface.pdf} +\medskip +\medskip + +\includegraphics[scale=0.85]{../Figures/MeasurableInterface.pdf} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{UML Diagram of Measurer Interface} @@ -298,6 +284,63 @@ doing it the same way.'' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{MVC} + +\includegraphics[scale=0.6]{../Figures/MVC.png} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{MVC Web Applications} + +\includegraphics[scale=1]{../Figures/WebAppMVC.png} +~\\ +From /Tutorials/OLD\_MVC + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{MVC Example} + +\includegraphics[scale=0.5]{../Figures/MVCExampleStudent.png}\\ +\href{https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm} +{https://www.tutorialspoint.com/design\_pattern/mvc\_pattern.htm} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{MVC Critique} + +\bi +\item Advantages +\bi +\item Simultaneous development +\item High cohesion +\item Low coupling +\item Ease of modification +\item Multiple views for a model +\ei +\item Disadvantages +\bi +\item Code navigability +\item Multi-artifact consistency +\item Pronounced learning curve +\ei +\ei + +\href{https://en.wikipedia.org/wiki/Model–view–controller}{Wikipedia page} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + \begin{frame} \frametitle{Design Pattern Properties} @@ -316,6 +359,53 @@ doing it the same way.'' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Classification of Patterns} + +\begin{itemize} + +\item Creational design patterns +\bi +\item Abstract factory +%\item Builder +%\item Factory method +\item Object pool +\item Prototype +\item Singleton +\ei +\item Structural design patterns +\bi +\item Adapter +\item Bridge +%\item Composite +%\item Decorator +\item Facade +%\item Flyweight +%\item Private Class Data +\item Proxy +\ei +\item Behavioural design patterns +\bi +%\item Chain of responsibility +\item Command +%\item Interpreter +\item Iterator +%\item Mediator +%\item Memento +%\item Null object +\item Observer +\item State +\item Strategy +%\item Template method +%\item Visitor +\ei + +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \frametitle{Describing Patterns} @@ -391,6 +481,18 @@ so on. The actual execution of the command is delegated to a supplier component %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Command in UML} + +\includegraphics[scale=0.8]{../Figures/command.png} +~\\ +\href{http://www.dofactory.com/net/command-design-pattern} +{http://www.dofactory.com/net/command-design-pattern} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \frametitle{Adapter Design Pattern} @@ -405,6 +507,8 @@ so on. The actual execution of the command is delegated to a supplier component \includegraphics[scale=0.7]{../Figures/500px-AdapterPatternForWiki.jpg} +Adapter wraps one class + \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/Lectures/L28_ParnasTables/ParnasTables.pdf b/Lectures/L28_ParnasTables/ParnasTables.pdf index a5cd6f409ea9546fa171e3c809b202fd9d21cfb0..2153a1ee22602bd21dbfdd289d52507005e14167 100644 Binary files a/Lectures/L28_ParnasTables/ParnasTables.pdf and b/Lectures/L28_ParnasTables/ParnasTables.pdf differ diff --git a/Lectures/L28_ParnasTables/ParnasTables.tex b/Lectures/L28_ParnasTables/ParnasTables.tex index cb9fffd6df21937ee67b9f83542b0d8cd7241095..b1b3050ad5c64d67a663f0d3ab24abeb222555f5 100755 --- a/Lectures/L28_ParnasTables/ParnasTables.tex +++ b/Lectures/L28_ParnasTables/ParnasTables.tex @@ -29,7 +29,7 @@ \mode<presentation>{} \input{../def-beamer} -\Drafttrue +\Draftfalse \newcommand{\topicTitle}{28 Parnas Tables} \ifDraft @@ -54,7 +54,7 @@ \begin{itemize} \item Today's slide are partially based on slides by Dr.\ Wassyng \item Administrative details -\item Translating English to Math exercise +\item Design patterns \item Motivating example: midterm question \item History of tables \item Example tables @@ -78,16 +78,17 @@ TBD { \begin{itemize} -\item A3 deadlines +\item Multiple potential Academic Dishonesty cases are currently being + investigated + +\item A3 \begin{itemize} -\item Part 2 - Code: due 11:59 pm Mar 20 -\item \structure{Part 1 spec available in repo} +\item Part 2 - Code: due 11:59 pm Mar 26 \end{itemize} \item A4 \bi -\item Your own design and specification -\item Due April 3 at 11:59 pm +\item Due April 9 at 11:59 pm \ei \end{itemize} @@ -99,178 +100,109 @@ TBD %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise} - -\bi -\item - \href{http://www.lonelyplanet.com/blog/2011/11/24/lost-in-translation-our-top-20-photos/}{For - SE Section} -\ei - -Consider an array $D$ with index values ranging from $1$ to $n$. The subject of this example is part of a specification -for a subprogram that will count how many times a particular given value occurs in the array $D$.\\ -~\newline - -The goal of this exercise is to write a postcondition for the subprogram, relating the various relevant variablesÕ -values when the search is complete. - -\end{frame} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{frame} -\frametitle{Exercise Continued} - -Understand the task in the original language +\frametitle{Command Processor Pattern} \begin{itemize} -\item Identify objects referred to (look for nouns in the original English text) -\item<2-> \structure<2>{Array $D$, index value, times (count), particular given value, relevant variables's value} -\item Identify missing information -\item<3-> \structure<3>{Names of variable for: index, times (count), particular given value} -\item<4-> \structure<4>{Are there any other relevant variables?} -\end{itemize} - -\end{frame} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{frame} -\frametitle{Exercise} - -\begin{itemize} +\item Context: User interfaces which must be flexible or provide functionality that goes beyond the direct handling of +user functions. Examples are undo facilities or logging functions +\item Problem: We want a well-structured solution for mapping an interface to the internal functionality of a system. +All `extras' which have to do with the way user commands are input, additional commands such as undo and redo, and any +non-application-specific processing of user commands, such as logging, should be kept separate from the interface to +the internal functionality. -\item Identify missing information -\item Names of variable for -\begin{itemize} -\item Index: assume $i$ -\item Times (count): ask the author of the task, assume $\mathit{count}$ -\item Particular given value: Ask the author of the task, assume $\mathit{key}$ -\item Are there any other relevant variables? (no?) -\end{itemize} \end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise Continued} +\frametitle{Command Processor Pattern Continued} \begin{itemize} -\item Close the gap between English text and mathematics -\begin{itemize} -\item Reword the English text to be closer to mathematics -\item Use the English verb $\mathit{count}$ -\end{itemize} + +\item Solution: A separate component, the \structure{command processor}, takes care of all commands. The command +processor component schedules the execution of commands, stores them for later undo, logs them for later analysis, and +so on. The actual execution of the command is delegated to a supplier component within the application. \end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise Continued} +\frametitle{Command in UML} -\begin{itemize} - -\item The English verb $count$ means, in programming language and in terms closer to mathematics, $\mathit{add}$ $1$ -\item But this is a dynamic (action) concept -\item The corresponding static (state, relational) concept in mathematics is the function \textit{addition with 1}, -that is $+1$ +\includegraphics[scale=0.8]{../Figures/command.png} +~\\ +\href{http://www.dofactory.com/net/command-design-pattern} +{http://www.dofactory.com/net/command-design-pattern} -\end{itemize} +%invoker can track list of previous commands +%command can include undo execute +%receiver actually knows how to do the calculation +%client associates receiver and concrete command \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise Continued} - -\begin{itemize} +\frametitle{Adapter Design Pattern} -\item The occurrence of the particular given value in an array element in $D$ -\item $D[i] = \mathit{key}$ -\item A condition for the addition with 1 -\item The repetition over a variable number of index values suggests quantification with the function addition and -with the argument $1$ -\item $+(i : ? | ... \wedge D[i] = \mathit{key} : 1)$ - -\end{itemize} +\structure{When have we used the adapter (or wrapper) design pattern?} +% wrapper for sequence for A1 +% npolyVal(n, x) implemented by numpy polyfit \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise Continued} - -Identify relationships between essential objects +\frametitle{Adapter Design Pattern} -\begin{itemize} - -\item Array $D$, index value, particular given value: $D[i] = \mathit{key}$ -\item Combine the above with count ($+$ conditionally with $1$) -\item $\mathit{count} = +(i: \mathbb{N} | ... \leq i \leq ... \wedge D[i] = \mathit{key} : 1)$ -\item Range of $i$ missing -\item Refer to original English text: $1$ to $n$ -\item $\mathit{count} = +(i: \mathbb{N} | 1 \leq i \leq n \wedge D[i] = \mathit{key} : 1)$ -\end{itemize} +\includegraphics[scale=0.7]{../Figures/500px-AdapterPatternForWiki.jpg} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Exercise: New Glossary Entry} +\frametitle{Adapter UML Diagram} -Now we have a new entry for our glossary +\includegraphics[scale=0.42]{../Figures/Adapter.png} -\begin{itemize} - -\item count: $ +(i: \mathbb{N} | ... \leq i \leq ... \wedge ... : 1)$, where the ... defines the range of the -quantified variable and the condition for counting - -\end{itemize} +\href{https://commons.wikimedia.org/wiki/File:Adapter_using_delegation_UML_class_diagram.png} +{Link} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Summary} +\frametitle{Factory Pattern} -\begin{itemize} +\includegraphics[scale=0.55]{../Figures/factory_pattern_uml_diagram.jpg} -\item Knowledge of English and Mathematics is necessary but not sufficient to translate into Mathematics -\item Knowledge of subject area also needed -\item Translating skills needed -\item The three are different - -\end{itemize} +\href{https://www.tutorialspoint.com/design_pattern/factory_pattern.htm}{Code} +% create object without exposing the creation logic, refer to newly created +% object using a common interface. +% Client is decoupled from the implementation details of derived classes \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} -\frametitle{Summary} +\frametitle{Singleton Pattern} -\begin{itemize} - -\item Compile your own glossary -\item Make intermediate steps and expressions conscious -\item Modularize -\item Organize systematically -\item KISSS -\end{itemize} +\includegraphics[scale=1.7]{../Figures/Singleton.jpg} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Tables Motivating Example: ptOn(c, s)} @@ -359,6 +291,10 @@ designs %sp is set point %e mean enumerated type %subscript -1 means previous value +~\\ +~\\ +\structure{What is this table specifying?} + \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -466,12 +402,15 @@ If Condition 1 then f\_name = Result 1\\ Elseif Condition 2 then f\_name = Result 2\\ Elseif ...\\ Elseif Condition n then f\_name = Result n\\ +or f\_name = (Condition 1 $\Rightarrow$ Result 1 $|$ ...) + ~\newline \uncover<2->{\structure<2>{Disjointedness $\equiv$ $\forall (i, j: \mathbb{N} | 1 \leq i \leq n \wedge 1 \leq j \leq n \wedge i \neq j : \mbox{Condition } i \wedge \mbox{Condition } j \Leftrightarrow \mbox{false})$\\ ~\\ -Completeness $\equiv \vee (i: \mathbb{N} | 1 \leq i \leq n : \mbox{Condition } i )$}} +Completeness $\equiv \vee (i: \mathbb{N} | 1 \leq i \leq n : \mbox{Condition } i +)$}} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -529,8 +468,8 @@ Horizontal condition tables \\ \frametitle{World View of Tables} \bi -\item \structure{Do tables take a dynamic or a static world view?} -\item \structure{Can you write an algorithm with a table?} +\item \structure{Do tables take a dynamic or a static world view?} %static +\item \structure{Can you directly write an algorithm from a table?} %maybe \ei \end{frame} @@ -583,7 +522,7 @@ sequences of operations \begin{itemize} -\item Consider all of the cases +\item Consider all of the cases for a rectangle \item Draw a picture \item Short form notation \begin{itemize} @@ -594,6 +533,7 @@ sequences of operations \item $llxw = \mathit{lower\_left}.\mbox{xcoord()} + \mathit{width}$ \item $llyh = \mathit{lower\_left}.\mbox{ycoord()} + \mathit{height}$ \item T = Constants.TOLERANCE +\item $p1$.dist$(p2$) is the distance between p1 and p2 \end{itemize} \end{itemize} @@ -722,4 +662,16 @@ $p.\mbox{dist}(\mbox{PointT}(llxw, llyh)) ] \leq \mbox{T}$}\\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Nine Cases, but 2D} + +\bi +\item \structure{How would you write all 9 cases, but with a tabular form that + closely matches the original 2D problem description?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \end{document} \ No newline at end of file diff --git a/Lectures/L35_Analysis/Analysis.pdf b/Lectures/L35_Analysis/Analysis.pdf index 3dbbe68b16174cf3ce38baf889bb1d94d7ecf936..62dfcd8b6f7d1e2b33157cc80ed127f59a811c47 100644 Binary files a/Lectures/L35_Analysis/Analysis.pdf and b/Lectures/L35_Analysis/Analysis.pdf differ diff --git a/Lectures/L35_Analysis/Analysis.tex b/Lectures/L35_Analysis/Analysis.tex index f4406b070eff6318a240799527bb5bf40e2d072e..4a04f333e2221c0533799fe20cd74d72eef37c39 100755 --- a/Lectures/L35_Analysis/Analysis.tex +++ b/Lectures/L35_Analysis/Analysis.tex @@ -336,7 +336,7 @@ TBD \ei \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Testing your Tests: Mutation Testing} @@ -351,7 +351,7 @@ TBD \end{itemize} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Analysis Versus Testing} @@ -550,7 +550,123 @@ View all of these as complementary \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Verifying Performance} + +\begin{itemize} +\item Worst case analysis versus average behaviour +\item For worst case focus on proving that the system response time is bounded + by some function of the external requests +\item Standard deviation +\item Analytical versus experimental approaches +\item Consider verifying the performance of a pacemaker +\item Visualize performance via +\bi +\item Identify a measure of performance (time, storage, FLOPS, accuracy, etc.) +\item Identify an independent variable (problem size, number of processors, + condition number, etc.) +\ei +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Verifying Reliability} + +\begin{itemize} +\item There are approaches to measuring reliability on a probabilistic basis, as + in other engineering fields +\item Unfortunately there are some difficulties with this approach +\item Independence of failures does not hold for software +\item Reliability is concerned with measuring the probability of the occurrence + of failure +\item Meaningful parameters include +\begin{itemize} +\item Average total number of failures observed at time $t$: $AF(t)$ +\item Failure intensity: $FI(T)=AF'(t)$ +\item Mean time to failure at time $t$: $MTTF(t) = 1/FI(t)$ +\end{itemize} +\item Time in the model can be execution or clock or calendar time +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Verifying Subjective Qualities} + +\begin{itemize} +\item \structure{What do you think is meant by empirical software engineering?} +\item \structure{What problems might be studied by empirical software + engineering?} +\item \structure{Does the usual engineering analogy hold for empirical software + engineering?} +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Verifying Subjective Qualities} + +\begin{itemize} +\item Consider notions like simplicity, reusability, understandability … +\item Software science (due to Halstead) has been an attempt +\item Tries to measure some software qualities, such as +abstraction level, effort, … +\item by measuring some quantities on code, such as +\bi +\item $\eta_1$, number of distinct operators in the program +\item $\eta_2$, number of distinct operands in the program +\item $N_1$, number of occurrences of operators in the program +\item $N_2$, number of occurrences of operands in the program +\ei +\item Extract information from repo, including number of commits, issues etc. +\item Empirical software engineering +\item Appropriate analogy switches from engineering to medicine +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Source Code Metric} + +\begin{itemize} +\item \structure{What are the consequences of complex code?} +\item \structure{How might you measure code complexity?} +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{McCabe's Source Code Metric} + +\begin{itemize} +\item Cyclomatic complexity of the control graph +\bi +\item $C = e - n + 2 p$ +\item $e$ is number of edges, $n$ is number of nodes, and $p$ is number of + connected components +\ei +\item McCabe contends that well-structured modules have $C$ in range $3 .. 7$, + and $C = 10$ is a reasonable upper limit for the complexity of a single module +\item Confirmed by empirical evidence +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \end{document} diff --git a/Lectures/L36_DesignPatterns/DesignPatterns.pdf b/Lectures/L36_DesignPatterns/DesignPatterns.pdf deleted file mode 100644 index bff86c6eb4dfb747077eada167bb283d460e6262..0000000000000000000000000000000000000000 Binary files a/Lectures/L36_DesignPatterns/DesignPatterns.pdf and /dev/null differ diff --git a/Lectures/L26_TemplatesInCpp/GenericsAndInterfacesInJava.pdf b/Lectures/OLD_GenericsAndInterfacesJava/GenericsAndInterfacesInJava.pdf similarity index 100% rename from Lectures/L26_TemplatesInCpp/GenericsAndInterfacesInJava.pdf rename to Lectures/OLD_GenericsAndInterfacesJava/GenericsAndInterfacesInJava.pdf diff --git a/Lectures/L26_TemplatesInCpp/GenericsAndInterfacesInJava.tex b/Lectures/OLD_GenericsAndInterfacesJava/GenericsAndInterfacesInJava.tex similarity index 100% rename from Lectures/L26_TemplatesInCpp/GenericsAndInterfacesInJava.tex rename to Lectures/OLD_GenericsAndInterfacesJava/GenericsAndInterfacesInJava.tex diff --git a/Lectures/L26_TemplatesInCpp/src/AllTests.java b/Lectures/OLD_GenericsAndInterfacesJava/src/AllTests.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/AllTests.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/AllTests.java diff --git a/Lectures/L26_TemplatesInCpp/src/FullException.java b/Lectures/OLD_GenericsAndInterfacesJava/src/FullException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/FullException.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/FullException.java diff --git a/Lectures/L26_TemplatesInCpp/src/GenericSet.java b/Lectures/OLD_GenericsAndInterfacesJava/src/GenericSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/GenericSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/GenericSet.java diff --git a/Lectures/L26_TemplatesInCpp/src/IntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/src/IntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/IntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/IntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/src/Makefile b/Lectures/OLD_GenericsAndInterfacesJava/src/Makefile similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/Makefile rename to Lectures/OLD_GenericsAndInterfacesJava/src/Makefile diff --git a/Lectures/L26_TemplatesInCpp/src/MemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/src/MemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/MemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/MemberException.java diff --git a/Lectures/L26_TemplatesInCpp/src/NotMemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/src/NotMemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/NotMemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/NotMemberException.java diff --git a/Lectures/L26_TemplatesInCpp/src/TestIntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/src/TestIntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/TestIntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/TestIntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/src/TestVectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/src/TestVectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/TestVectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/TestVectorTSet.java diff --git a/Lectures/L26_TemplatesInCpp/src/VectorT.java b/Lectures/OLD_GenericsAndInterfacesJava/src/VectorT.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/VectorT.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/VectorT.java diff --git a/Lectures/L26_TemplatesInCpp/src/VectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/src/VectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/src/VectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/src/VectorTSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/AllTests.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/AllTests.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/AllTests.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/AllTests.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/FullException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/FullException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/FullException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/FullException.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/GenericSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/GenericSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/GenericSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/GenericSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/IntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/IntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/IntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/IntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/Makefile b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/Makefile similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/Makefile rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/Makefile diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/MemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/MemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/MemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/MemberException.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/NotMemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/NotMemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/NotMemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/NotMemberException.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/TestIntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/TestIntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/TestIntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/TestIntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/TestVectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/TestVectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/TestVectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/TestVectorTSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/VectorT.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/VectorT.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/VectorT.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/VectorT.java diff --git a/Lectures/L26_TemplatesInCpp/srcComparable/VectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcComparable/VectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcComparable/VectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcComparable/VectorTSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/AllTests.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/AllTests.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/AllTests.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/AllTests.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/FullException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/FullException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/FullException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/FullException.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/GenericSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/GenericSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/GenericSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/GenericSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/IntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/IntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/IntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/IntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/Makefile b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/Makefile similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/Makefile rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/Makefile diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/MemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/MemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/MemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/MemberException.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/NotMemberException.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/NotMemberException.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/NotMemberException.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/NotMemberException.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/TestIntegerSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/TestIntegerSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/TestIntegerSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/TestIntegerSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/TestVectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/TestVectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/TestVectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/TestVectorTSet.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/VectorT.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/VectorT.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/VectorT.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/VectorT.java diff --git a/Lectures/L26_TemplatesInCpp/srcEquality/VectorTSet.java b/Lectures/OLD_GenericsAndInterfacesJava/srcEquality/VectorTSet.java similarity index 100% rename from Lectures/L26_TemplatesInCpp/srcEquality/VectorTSet.java rename to Lectures/OLD_GenericsAndInterfacesJava/srcEquality/VectorTSet.java diff --git a/Lectures/L27_SpecViaUML/SpecViaUML.pdf b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf similarity index 77% rename from Lectures/L27_SpecViaUML/SpecViaUML.pdf rename to Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf index a9b894e7c503b98221c5eccff8208bcd26440054..12e4432309b5d737a6e58509bb5de1359b5880e8 100644 Binary files a/Lectures/L27_SpecViaUML/SpecViaUML.pdf and b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf differ diff --git a/Lectures/L27_SpecViaUML/SpecViaUML.tex b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex similarity index 98% rename from Lectures/L27_SpecViaUML/SpecViaUML.tex rename to Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex index ed9af30abc690638c8e624111f2a31ddc8e91461..84416f2e4af03a74f0b065977361e8147bc7b6fe 100755 --- a/Lectures/L27_SpecViaUML/SpecViaUML.tex +++ b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex @@ -23,9 +23,9 @@ \mode<presentation>{} \input{../def-beamer} -\Drafttrue +\Draftfalse -\newcommand{\topicTitle}{27 Specification Via UML (Ch.\ 5 and others)} +\newcommand{\topicTitle}{26 Specification Via UML (Ch.\ 5 and others)} \ifDraft \newcommand{\topic}{\topicTitle~DRAFT} \else @@ -48,10 +48,11 @@ \begin{itemize} \item Administrative details \item Best specification technique? +\item Designing spec of modules \item Interfaces in UML \bi \item Measurable interface -\item Measurer interface +\item Multiple inheritance example \ei \item Generic classes in UML \item Use cases with UML diff --git a/Lectures/L27_SpecViaUML/src/BankAccount.java b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccount.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/BankAccount.java rename to Lectures/OLD_SpecViaUMLWithJava/src/BankAccount.java diff --git a/Lectures/L27_SpecViaUML/src/BankAccountInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccountInterface.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/BankAccountInterface.java rename to Lectures/OLD_SpecViaUMLWithJava/src/BankAccountInterface.java diff --git a/Lectures/L27_SpecViaUML/src/DataSet.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSet.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSet.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSet.java diff --git a/Lectures/L27_SpecViaUML/src/DataSetBankAccount.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetBankAccount.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSetBankAccount.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetBankAccount.java diff --git a/Lectures/L27_SpecViaUML/src/DataSetInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java similarity index 93% rename from Lectures/L27_SpecViaUML/src/DataSetInterface.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java index dcc8738027c62331b44e18584912c22be1db8e29..7f0a3895fd34f93d326ebbb557d9a90bf610e419 100644 --- a/Lectures/L27_SpecViaUML/src/DataSetInterface.java +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java @@ -1,7 +1,7 @@ public class DataSetInterface { private double sum; - private Measurable maximum; + private Measurable* maximum; private int count; public DataSetInterface() @@ -23,4 +23,4 @@ public class DataSetInterface public Measurable getMaximum() { return maximum; } -} \ No newline at end of file +} diff --git a/Lectures/L27_SpecViaUML/src/DataSetPoint.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetPoint.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSetPoint.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetPoint.java diff --git a/Lectures/L27_SpecViaUML/src/DataSetStrategy.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategy.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSetStrategy.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategy.java diff --git a/Lectures/L27_SpecViaUML/src/DataSetStrategyTest.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategyTest.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSetStrategyTest.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategyTest.java diff --git a/Lectures/L27_SpecViaUML/src/DataSetTest.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetTest.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/DataSetTest.java rename to Lectures/OLD_SpecViaUMLWithJava/src/DataSetTest.java diff --git a/Lectures/L27_SpecViaUML/src/Measurable.java b/Lectures/OLD_SpecViaUMLWithJava/src/Measurable.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/Measurable.java rename to Lectures/OLD_SpecViaUMLWithJava/src/Measurable.java diff --git a/Lectures/L27_SpecViaUML/src/Measurer.java b/Lectures/OLD_SpecViaUMLWithJava/src/Measurer.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/Measurer.java rename to Lectures/OLD_SpecViaUMLWithJava/src/Measurer.java diff --git a/Lectures/L27_SpecViaUML/src/PointT.java b/Lectures/OLD_SpecViaUMLWithJava/src/PointT.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/PointT.java rename to Lectures/OLD_SpecViaUMLWithJava/src/PointT.java diff --git a/Lectures/L27_SpecViaUML/src/PointTInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/PointTInterface.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/PointTInterface.java rename to Lectures/OLD_SpecViaUMLWithJava/src/PointTInterface.java diff --git a/Lectures/L27_SpecViaUML/src/RectangleMeasurer.java b/Lectures/OLD_SpecViaUMLWithJava/src/RectangleMeasurer.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/RectangleMeasurer.java rename to Lectures/OLD_SpecViaUMLWithJava/src/RectangleMeasurer.java diff --git a/Lectures/L27_SpecViaUML/src/TestArraysSortComparable.java b/Lectures/OLD_SpecViaUMLWithJava/src/TestArraysSortComparable.java similarity index 100% rename from Lectures/L27_SpecViaUML/src/TestArraysSortComparable.java rename to Lectures/OLD_SpecViaUMLWithJava/src/TestArraysSortComparable.java diff --git a/Tutorials/OLD-MVC/Tutorial 9 - MVC.pdf b/Tutorials/OLD-MVC/Tutorial 9 - MVC.pdf new file mode 100644 index 0000000000000000000000000000000000000000..229147fb5ec200cc5c118e0888b706229a3e29fb Binary files /dev/null and b/Tutorials/OLD-MVC/Tutorial 9 - MVC.pdf differ diff --git a/Tutorials/OLD-MVC/Tutorial 9 - MVC.pptx b/Tutorials/OLD-MVC/Tutorial 9 - MVC.pptx new file mode 100644 index 0000000000000000000000000000000000000000..c00303be3d6b1a5560bcc906d6f068c89719f9d8 Binary files /dev/null and b/Tutorials/OLD-MVC/Tutorial 9 - MVC.pptx differ diff --git a/Tutorials/OLD-MVC/src/MVCPatternDemo.java b/Tutorials/OLD-MVC/src/MVCPatternDemo.java new file mode 100755 index 0000000000000000000000000000000000000000..51dadbcbedc2ebb6322bc19191d22294bba623a6 --- /dev/null +++ b/Tutorials/OLD-MVC/src/MVCPatternDemo.java @@ -0,0 +1,25 @@ +public class MVCPatternDemo { + private static Student retriveStudentFromDatabase(){ + Student student = new Student(); + student.setName("Robert"); + student.setStudentNumber(10); + return student; + } + public static void main(String[] args) { + + //fetch student record based on his Student Number from the database + Student model = retriveStudentFromDatabase(); + + //Create a view : to write student details on console + StudentView view = new StudentView(); + + StudentController controller = new StudentController(model, view); + controller.updateView(); + + //update model data + controller.setStudentName("John"); + controller.setStudentNumber(11); + controller.updateView(); + } + +} diff --git a/Tutorials/OLD-MVC/src/Student.java b/Tutorials/OLD-MVC/src/Student.java new file mode 100755 index 0000000000000000000000000000000000000000..1ec1ef4c6c25d5b215966bcfccf65fca9525f089 --- /dev/null +++ b/Tutorials/OLD-MVC/src/Student.java @@ -0,0 +1,21 @@ +public class Student { + private String name; + private int number; + + + public int getStudentNumber() { + return number; + } + + public void setStudentNumber(int number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/Tutorials/OLD-MVC/src/StudentController.java b/Tutorials/OLD-MVC/src/StudentController.java new file mode 100755 index 0000000000000000000000000000000000000000..7a2c58e7a724e2595f135bbca051c934090eb99c --- /dev/null +++ b/Tutorials/OLD-MVC/src/StudentController.java @@ -0,0 +1,29 @@ +public class StudentController { + private Student model; + private StudentView view; + + public StudentController(Student model, StudentView view){ + this.model = model; + this.view = view; + } + + public void setStudentName(String name){ + model.setName(name); + } + + public String getStudentName(){ + return model.getName(); + } + + public void setStudentNumber(int number){ + model.setStudentNumber(number); + } + + public int getStudentstudentNumber(){ + return model.getStudentNumber(); + } + + public void updateView(){ + view.printStudentDetails(model.getName(), model.getStudentNumber()); + } +} diff --git a/Tutorials/OLD-MVC/src/StudentView.java b/Tutorials/OLD-MVC/src/StudentView.java new file mode 100755 index 0000000000000000000000000000000000000000..2c191d3bc9d636b731c48a8a0a78d60c4f9e8939 --- /dev/null +++ b/Tutorials/OLD-MVC/src/StudentView.java @@ -0,0 +1,9 @@ +public class StudentView { + + public void printStudentDetails(String studentName, int studentNumber){ + System.out.println("---Student---"); + System.out.println("Name: " + studentName); + System.out.println("Student Number: " + studentNumber); + } + +} diff --git a/Tutorials/T05-PyUnit/slides/Unit Testing.pdf b/Tutorials/T05-PyUnit/slides/Unit Testing.pdf deleted file mode 100644 index 79ff2bfd8c83957ffd3e5e931f2a9a99c95336ba..0000000000000000000000000000000000000000 Binary files a/Tutorials/T05-PyUnit/slides/Unit Testing.pdf and /dev/null differ diff --git a/Tutorials/T05-PyUnit/slides/Unit Testing.tex b/Tutorials/T05-PyUnit/slides/Unit Testing.tex deleted file mode 100644 index 997ca72163f5ed5963b0d47d66eae828382fd4fa..0000000000000000000000000000000000000000 --- a/Tutorials/T05-PyUnit/slides/Unit Testing.tex +++ /dev/null @@ -1,484 +0,0 @@ -% Define Document Class -% Class Options Include: -% notes, notesonly, handout, trans, -% hidesubsections, shadesubsections, -% inrow, blue, red, grey, brown -%-------------------------------------------------------------------------- -\documentclass[xcolor=dvipsnames, shownotes, colorlinks]{beamer} -%-------------------------------------------------------------------------- - -% ------------------------------------------------------------------------- -% Define Package Theme -%-------------------------------------------------------------------------- -\usepackage{color} -\usepackage[T1]{fontenc} -%% \usepackage{fix-cm} -\usepackage{hyperref} -\hypersetup{ - urlcolor=cyan, - linkcolor=white -} -\usepackage{subfigure} -\usepackage{graphicx} -\graphicspath{ {/} } - -\usepackage{enumerate} -\usetheme{Antibes} -\setbeamertemplate{sidebar}[right] -\setbeamertemplate{caption}[numbered] -\usepackage{listings} % Code formatting -\usepackage{lstautogobble} -\usepackage{dirtytalk} - -\lstset{ - language=[LaTeX]TeX, - basicstyle=\ttfamily\scriptsize, - tabsize=2, - breaklines=true, - prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, - frame=single, - showstringspaces=true, - showspaces=false, - keywordstyle=\color{blue}, - stringstyle=\color{magenta}, - commentstyle=\color{ForestGreen}, - morekeywords={maketitle, tableofcontents, subsection, subsubsection, includegraphics, toprule, midrule, bottomrule}, - autogobble=true -} - -%------------------------------------------------------------------------------ -% Commands -%------------------------------------------------------------------------------ - -\newcommand*\oldmacro{}% -\let\oldmacro\insertshorttitle% -\renewcommand*\insertshorttitle{% - \oldmacro\hfill% - \insertframenumber\,/\,\inserttotalframenumber} - -% Figure Source -\usepackage[absolute,overlay]{textpos} - -\setbeamercolor{framesource}{fg=gray} -\setbeamerfont{framesource}{size=\tiny} - -\newcommand{\source}[1]{\begin{textblock*}{\paperwidth}(-5pt,\textheight) - \begin{beamercolorbox}[ht=0.5cm,right]{framesource} - \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1} - \end{beamercolorbox} -\end{textblock*}} - -%-------------------------------------------------------------------------- -% Presentation Title Slide -%-------------------------------------------------------------------------- -\title{Unit Testing - pytest} -\subtitle{CS 2ME3/SE 2AA4} -\author{Zichen Jiang\\ -Owen Huyn} -\institute{Department of Computing and Software\\ -McMaster University\\ } -\date{\today} -%-------------------------------------------------------------------------- - - -% Document -% To add notes to the slides use: \note{} -% Add \section{} or \subsection{} for use in table of contents -%-------------------------------------------------------------------------- -\begin{document} - -% Create Title Slide -\begin{frame} -\maketitle -\end{frame} - -\section[Outline]{} -% Create Table of Contents Slide - Outline -\begin{frame} -\frametitle{Outline} - {\hypersetup{linkcolor=black} - \tableofcontents - } -\end{frame} - -% ----------------------------------------------------- -\section{Introduction} -% ----------------------------------------------------- - -\begin{frame}[fragile] - \frametitle{What is Unit Testing} - \begin{itemize} - \item{Unit testing verifies that individual units of code (usually functions) work as intended} - \item{Designed to be \textbf{simple}, easy to write and run} - \item{You can test both from a blackbox perspective and a whitebox perspective} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Who writes unit tests} - \begin{itemize} - \item{Developers should test their own code!} - \item{The person who wrote the code usually has the best understanding of what their code does} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Why Unit Test?} - \begin{itemize} - \item{You can catch bugs much earlier} - \item{Provides documentation on a specific function} - \item{Helps developer improve the implementation/design of a function} - \item{Every good developer should be a good tester too!\\ -No one likes to work with someone who doesn't verify/test if their code works.} - - \end{itemize} -\end{frame} - - -% ----------------------------------------------------- -\section{pytest} -% ----------------------------------------------------- -\begin{frame}[fragile] - \frametitle{What is pytest} - \begin{itemize} - \item{pytest is a framework that makes it easy to write small tests} - \item{Similar to JUnit (Java), CppUnit (C++)} - \item{Knowledge is transferable to another xUnit framework regardless of language} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Getting Started} -\begin{itemize} - \item{Installing pytest is very simple, simply run the following command in your command line} - - \item{\texttt{pip install -U pytest }} - - \item{For more information, visit \href{https://docs.pytest.org/en/latest/getting-started.html} {pytest Installation and Getting Started}} -\end{itemize} -\end{frame} - -% ----------------------------------------------------- -\section{Demo} -% ----------------------------------------------------- -\begin{frame}[fragile] -\frametitle{Demo} -\begin{itemize} - \item{Let's get started, I encourage everyone to pull out their laptops and follow along.} - \item{We will test A1 from last year, which was introduced in the past tutorials} - \item{Don't be afraid to ask any questions!} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Create our first unit test file} -\begin{itemize} - \item{To start, create a new Python file called test\_circles.py in the same directory of our file that we want to test} - \item{You can do this from the command line or any text editor of your choice. Don't be afraid to ask any questions!} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Create our first test template} -\begin{itemize} - \item{To start with our unit test, follow this template:} -\end{itemize} -\begin{lstlisting}[language=Python] - import pytest - - class TestCircles: -\end{lstlisting} -\begin{enumerate} - \item{Import the pytest library} - \item{Write a unit testing class starting with the word \texttt{Test}} -\end{enumerate} -\end{frame} - -\begin{frame}[fragile] -\frametitle{What is Assert?} -\begin{itemize} - \item{ Wikipedia: \say{... an assertion is a statement that a predicate (Boolean-valued function, i.e. a true-false expression) is expected to always be true at that point in the code. If an assertion evaluates to false at run time, an assertion failure results, which typically causes the program to crash, or to throw an assertion exception.}} - \item{Basically, if whatever follows assert is true, it will continue. Otherwise the test will fail and stop running.} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Example of Assert?} -\begin{itemize} - \item{To assert something to be true, you can write} - \begin{lstlisting}[language=Python] - assert <true statement> - \end{lstlisting} - \item{To assert something to be false, you can write} - \begin{lstlisting}[language=Python] - assert not <false statement> - \end{lstlisting} - - -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Writing our first test} - -\begin{lstlisting}[language=Python] -import pytest -from CircleADT import * - -class TestCircles: - - def test_xcoord_are_equal(self): - circle = CircleT(1,2,3) - assert circle.xcoord() == 1 - - def test_xcoord_are_not_equal(self): - circle = CircleT(1,2,3) - assert not (circle.xcoord() == 2) - # or `assert circle.xcoord() != 2' -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Running our first test} -\begin{itemize} - \item{Run this command in your command prompt inside the folder of your test file: \texttt{pytest test\_circles.py}} - \item{To run all tests within the directory, just run \texttt{pytest}. It will search for all files starting with "test\_" and run all methods starting with "test\_"} - \begin{figure}[b] - {\includegraphics[width=10cm]{test-result}} - \end{figure} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{What if a test failed?} -\begin{itemize} - \item{Say we have the following code:} -\end{itemize} -\begin{lstlisting}[language=Python] -import pytest -from CircleADT import * - -class TestCircles: - - def test_xcoord_are_equal(self): - circle = CircleT(1,2,3) - assert circle.xcoord() == 1 - - def test_xcoord_are_not_equal(self): - circle = CircleT(1,2,3) - assert circle.xcoord() != 1 -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] -\frametitle{What if a test failed?} - - \begin{figure}[b] - {\includegraphics[width=10cm]{test-result-fail}} - \end{figure} - -\end{frame} - -\begin{frame}[fragile] -\frametitle{Floating Point assertions} -\begin{itemize} - \item{\texttt{approx(expected, rel=None, abs=None, nan\_ok=False)}} - - \begin{itemize} - \item{\texttt{rel}: relative tolerance} - \item{\texttt{abs}: absolute tolerance} - \item{\texttt{nan\_ok}: facilitates comparing arrays that use NaN to mean "no data"} - - \end{itemize} - - \item{By default, \texttt{approx} considers numbers within a relative tolerance of 1e-6 and absolute tolerance of 1e-12 of its expected value to be equal. } -\end{itemize} -\begin{lstlisting}[language=Python, escapechar=!] ->>> 1.0001 == approx(1) -False ->>> 1.0001 == approx(1, rel=1e-3) -True ->>> 1.0001 == approx(1, abs=1e-3) -True -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Redundant code in tests} -\begin{lstlisting}[language=Python, escapechar=!] -import pytest -from CircleADT import * - -class TestCircles: - - def test_xcoord_are_equal(self): - !\colorbox{yellow}{circle = CircleT(1,2,3)}! - assert circle.xcoord() == 1 - - def test_xcoord_are_not_equal(self): - !\colorbox{yellow}{circle = CircleT(1,2,3)}! - assert not circle.xcoord() == 1 -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Cleaned up code} -\begin{lstlisting}[language=Python, escapechar=!] -import pytest -from CircleADT import * - -class TestCircles: - - def setup_method(self, method): - self.circle = CircleT(1,2,3) - - def teardown_method(self, method): - self.circle = None - - def test_xcoord_are_equal(self): - assert self.circle.xcoord() == 1 - - def test_xcoord_are_not_equal(self): - assert not self.circle.xcoord() == 2 -\end{lstlisting} -\end{frame} - - -\begin{frame}[fragile] -\frametitle{Setup and Teardown} -\begin{itemize} - \item{\texttt{setup\_class(cls)}} - \begin{itemize} - \item{setup any state specific to the execution of the given class} - \end{itemize} - \item{\texttt{teardown\_class(cls)}} - \begin{itemize} - \item{teardown any state that was previously setup with a call to \texttt{setup\_class}.} - \end{itemize} - \item{\texttt{setup\_method(self, method)}} - \begin{itemize} - \item{setup any state tied to the execution of the given method in a class. \texttt{setup\_method} is invoked for every test method of a class.} - \end{itemize} - \item{\texttt{teardown\_method(self, method)}} - \begin{itemize} - \item{teardown any state that was previously setup with a \texttt{setup\_method} call.} - \end{itemize} -\end{itemize} -\end{frame} - - -\begin{frame}[fragile] -\frametitle{Asserting about exceptions} -\begin{itemize} - \item{It is very important in unit testing to check for edge cases and behaviour in the case of unexpected input.} - \item{If a function raises an exception in some cases, you should include those cases in your unit testing as well.} - \item{You can do so by using a context manager called pytest.raises.} -\end{itemize} -\begin{lstlisting}[language=Python, escapechar=!] -import pytest - -def test_zero_division(): - with pytest.raises(ZeroDivisionError): - 1 / 0 -\end{lstlisting} -\end{frame} - - -\begin{frame}[fragile] -\frametitle{Asserting about exceptions} -\begin{itemize} - \item{If an exception is not raised in a pytest.raises block, the test will fail.} -\end{itemize} -\begin{lstlisting}[language=Python, escapechar=!] -import pytest - -def test_zero_division(): - with pytest.raises(ZeroDivisionError): - 2 / 1 -\end{lstlisting} -\begin{itemize} - \item{If you run this test, it will give the result:} -\end{itemize} - -\begin{figure}[b] - {\includegraphics[width=8cm]{exception-not-raised}} -\end{figure} - - -\end{frame} - - -% ----------------------------------------------------- -\section{Code Coverage} -% ----------------------------------------------------- -\begin{frame}[fragile] -\frametitle{How much should I test?} -\begin{itemize} - \item {Test all requirements in each function} - \item{Cover edge cases that may cause unintended consequences} - \item{Have an acceptable amount of - \href{https://en.wikipedia.org/wiki/Code_coverage}{code coverage}} - \item{Code coverage will be covered in more detail in future lectures} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Code Coverage} -\begin{itemize} -\item{Function coverage: has each function (or subroutine) in the program been called?} -\item{Statement coverage: has each statement in the program been executed?} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Code Coverage} -\begin{itemize} -\item{Branch coverage: has each branch of each control structure (such as in if and case statements) been executed?} - \begin{itemize} - \item{For example, given an if statement, have both the true and false branches been executed?} - \item{Another way of saying this is, has every edge in the program been executed?} - \end{itemize} -\item{Condition coverage (or predicate coverage): has each Boolean sub-expression evaluated both to true and false?} -\end{itemize} -\end{frame} - - -\begin{frame}[fragile] -\frametitle{Pytest plugin for measuring coverage} - \begin{itemize} - \item{\url{https://pypi.python.org/pypi/pytest-cov}} - \item{Install with pip: \texttt{pip install pytest-cov}} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Running the coverage plugin} -\begin{itemize} - \item{In the source code directory, run \texttt{pytest -{}-cov}} -\item{ -\begin{figure}[b] - {\includegraphics[width=8cm]{test-coverage}} -\end{figure} -} - \item{We can see that \texttt{CircleADT.py} has onlyl 51\% coverage. This is because only the methods \texttt{xcoord} and \texttt{ycoord} were tested} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Exercise} -\begin{itemize} - \item{The rest of the methods are left for you as practices} - \item{You can Refer to testStatistics.py for a more complete breakdown on how to test complicated functions} -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{References} -\begin{itemize} - \item{\url{https://docs.pytest.org/en/latest/xunit_setup.html}} - \item{\url{https://en.wikipedia.org/wiki/Code_coverage}} - \item{\url{http://pytest.readthedocs.io/en/reorganize-docs/new-docs/user/pytest_raises.html}} -\end{itemize} -\end{frame} - -\end{document}