author | Shantanu <shantanu@fossee.in> |
Mon, 05 Oct 2009 21:58:16 +0530 | |
changeset 23 | 14c817585247 |
parent 22 | 492017122355 |
child 46 | 63704b5650f1 |
permissions | -rw-r--r-- |
22 | 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 |
%% Talk given somewhere on dd/mm/yyyy |
|
3 |
%% |
|
4 |
%% Author: Prabhu Ramachandran <prabhu@aero.iitb.ac.in> |
|
5 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
6 |
||
7 |
\documentclass[compress,14pt]{beamer} |
|
8 |
% \documentclass[handout]{beamer} |
|
9 |
% \usepackage{pgfpages} |
|
10 |
% \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape] |
|
11 |
\usepackage{tikz} |
|
12 |
\newcommand{\hyperlinkmovie}{} |
|
13 |
%\usepackage{movie15} |
|
14 |
||
15 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
16 |
% Note that in presentation mode |
|
17 |
% \paperwidth 364.19536pt |
|
18 |
% \paperheight 273.14662pt |
|
19 |
% h/w = 0.888 |
|
20 |
||
21 |
||
22 |
\mode<presentation> |
|
23 |
{ |
|
24 |
\usetheme{CambridgeUS} |
|
25 |
%\usetheme{Boadilla} |
|
26 |
%\usetheme{default} |
|
27 |
\useoutertheme{split} |
|
28 |
\setbeamercovered{transparent} |
|
29 |
} |
|
30 |
||
31 |
% To remove navigation symbols |
|
32 |
\setbeamertemplate{navigation symbols}{} |
|
33 |
||
34 |
\usepackage{amsmath} |
|
35 |
\usepackage[english]{babel} |
|
36 |
\usepackage[latin1]{inputenc} |
|
37 |
\usepackage{times} |
|
38 |
\usepackage[T1]{fontenc} |
|
39 |
||
40 |
% Taken from Fernando's slides. |
|
41 |
\usepackage{ae,aecompl} |
|
42 |
\usepackage{mathpazo,courier,euler} |
|
43 |
\usepackage[scaled=.95]{helvet} |
|
44 |
\usepackage{pgf} |
|
45 |
||
46 |
\definecolor{darkgreen}{rgb}{0,0.5,0} |
|
47 |
||
48 |
\usepackage{listings} |
|
49 |
\lstset{language=Python, |
|
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
50 |
basicstyle=\ttfamily\bfseries, |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
51 |
commentstyle=\color{red}\itshape, |
22 | 52 |
stringstyle=\color{darkgreen}, |
53 |
showstringspaces=false, |
|
54 |
keywordstyle=\color{blue}\bfseries} |
|
55 |
||
56 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
57 |
% My Macros |
|
58 |
\setbeamercolor{postit}{bg=yellow,fg=black} |
|
59 |
\setbeamercolor{emphbar}{bg=blue!20, fg=black} |
|
60 |
\newcommand{\emphbar}[1] |
|
61 |
{\begin{beamercolorbox}[rounded=true]{emphbar} |
|
62 |
{#1} |
|
63 |
\end{beamercolorbox} |
|
64 |
} |
|
65 |
%{\centerline{\fcolorbox{gray!50} {blue!10}{ |
|
66 |
%\begin{minipage}{0.9\linewidth} |
|
67 |
% {#1} |
|
68 |
%\end{minipage} |
|
69 |
% }}} |
|
70 |
||
71 |
\newcommand{\myemph}[1]{\structure{\emph{#1}}} |
|
72 |
\newcommand{\PythonCode}[1]{\lstinline{#1}} |
|
73 |
||
74 |
\newcommand{\tvtk}{\texttt{tvtk}} |
|
75 |
\newcommand{\mlab}{\texttt{mlab}} |
|
76 |
||
77 |
\newcounter{time} |
|
78 |
\setcounter{time}{0} |
|
79 |
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}} |
|
80 |
||
81 |
\newcommand\BackgroundPicture[1]{% |
|
82 |
\setbeamertemplate{background}{% |
|
83 |
\parbox[c][\paperheight]{\paperwidth}{% |
|
84 |
\vfill \hfill |
|
85 |
\hfill \vfill |
|
86 |
}}} |
|
87 |
||
88 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
89 |
% Configuring the theme |
|
90 |
%\setbeamercolor{normal text}{fg=white} |
|
91 |
%\setbeamercolor{background canvas}{bg=black} |
|
92 |
||
93 |
||
94 |
||
95 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
96 |
% Title page |
|
97 |
\title[]{3D data Vizualization\\ \& \\Test Driven Approach} |
|
98 |
||
99 |
\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran} |
|
100 |
||
101 |
\institute[FOSSEE] {FOSSEE Team} |
|
102 |
\date[] {11, October 2009} |
|
103 |
\date[] % (optional) |
|
104 |
} |
|
105 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
106 |
||
107 |
%\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo} |
|
108 |
%\logo{\pgfuseimage{iitblogo}} |
|
109 |
||
110 |
\AtBeginSection[] |
|
111 |
{ |
|
112 |
\begin{frame}<beamer> |
|
113 |
\frametitle{Outline} |
|
114 |
\Large |
|
115 |
\tableofcontents[currentsection,currentsubsection] |
|
116 |
\end{frame} |
|
117 |
} |
|
118 |
||
119 |
%% Delete this, if you do not want the table of contents to pop up at |
|
120 |
%% the beginning of each subsection: |
|
121 |
\AtBeginSubsection[] |
|
122 |
{ |
|
123 |
\begin{frame}<beamer> |
|
124 |
\frametitle{Outline} |
|
125 |
\tableofcontents[currentsection,currentsubsection] |
|
126 |
\end{frame} |
|
127 |
} |
|
128 |
||
129 |
\AtBeginSection[] |
|
130 |
{ |
|
131 |
\begin{frame}<beamer> |
|
132 |
\frametitle{Outline} |
|
133 |
\tableofcontents[currentsection,currentsubsection] |
|
134 |
\end{frame} |
|
135 |
} |
|
136 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
137 |
% DOCUMENT STARTS |
|
138 |
\begin{document} |
|
139 |
||
140 |
\begin{frame} |
|
141 |
\maketitle |
|
142 |
\end{frame} |
|
143 |
||
144 |
\begin{frame} |
|
145 |
\frametitle{Outline} |
|
146 |
\Large |
|
147 |
\tableofcontents |
|
148 |
% You might wish to add the option [pausesections] |
|
149 |
\end{frame} |
|
150 |
||
151 |
\section{3D Data Visualization} |
|
152 |
||
153 |
\begin{frame} |
|
154 |
\frametitle{What is visualization?} |
|
155 |
\Large |
|
156 |
\begin{center} |
|
157 |
Visual representation of data |
|
158 |
\end{center} |
|
159 |
\end{frame} |
|
160 |
||
161 |
\begin{frame} |
|
162 |
\frametitle{3D visualization} |
|
163 |
\Large |
|
164 |
\begin{center} |
|
165 |
Harder but important |
|
166 |
\end{center} |
|
167 |
\end{frame} |
|
168 |
||
169 |
\begin{frame} |
|
170 |
\frametitle{Is this Graphics?} |
|
171 |
\Large |
|
172 |
\begin{center} |
|
173 |
Visualization is about data! |
|
174 |
\end{center} |
|
175 |
\end{frame} |
|
176 |
||
177 |
\begin{frame} |
|
178 |
\frametitle{Examples: trajectory in space} |
|
179 |
\Large |
|
180 |
\begin{center} |
|
181 |
\pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
182 |
\end{center} |
|
183 |
\end{frame} |
|
184 |
||
185 |
\begin{frame} |
|
186 |
\frametitle{Examples: Fire in a room} |
|
187 |
\Large |
|
188 |
\begin{center} |
|
189 |
Demo of data |
|
190 |
\end{center} |
|
191 |
\inctime{10} |
|
192 |
\end{frame} |
|
193 |
||
194 |
\section{Tools at your disposal:} |
|
195 |
||
196 |
\subsection{mlab} |
|
197 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
198 |
\begin{frame} |
22 | 199 |
{Overview} |
200 |
\Large |
|
201 |
\begin{itemize} |
|
202 |
\item Simple |
|
203 |
\item Convenient |
|
204 |
\item Full-featured |
|
205 |
\end{itemize} |
|
206 |
\end{frame} |
|
207 |
||
208 |
\begin{frame}[fragile] |
|
209 |
||
210 |
\frametitle{Getting started} |
|
211 |
\myemph{\Large Vanilla:} |
|
212 |
\begin{lstlisting}[language=bash] |
|
213 |
$ ipython -wthread |
|
214 |
\end{lstlisting} |
|
215 |
\myemph{\Large with Pylab:} |
|
216 |
\begin{lstlisting}[language=bash] |
|
217 |
$ ipython -pylab -wthread |
|
218 |
\end{lstlisting} |
|
219 |
\end{frame} |
|
220 |
||
221 |
\begin{frame}[fragile] |
|
222 |
\frametitle{Using mlab:} |
|
223 |
||
224 |
\begin{lstlisting} |
|
225 |
>>> from enthought.mayavi import mlab |
|
226 |
\end{lstlisting} |
|
227 |
||
228 |
\vspace*{0.5in} |
|
229 |
||
230 |
\myemph{\Large Try these:} |
|
231 |
||
232 |
\vspace*{0.25in} |
|
233 |
||
234 |
\begin{lstlisting} |
|
235 |
>>> mlab.test_<TAB> |
|
236 |
>>> mlab.test_contour3d() |
|
237 |
>>> mlab.test_contour3d?? |
|
238 |
\end{lstlisting} |
|
239 |
\end{frame} |
|
240 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
241 |
\begin{frame} |
22 | 242 |
{Exploring the view} |
243 |
\begin{columns} |
|
244 |
\column{0.6\textwidth} |
|
245 |
\pgfimage[width=3in]{MEDIA/m2/contour3d} |
|
246 |
\column{0.4\textwidth} |
|
247 |
\begin{itemize} |
|
248 |
\item Mouse |
|
249 |
\item Keyboard |
|
250 |
\item Toolbar |
|
251 |
\item Mayavi icon(wait for it...) \pgfimage[width=0.2in]{MEDIA/m2/m2_icon} |
|
252 |
\end{itemize} |
|
253 |
\end{columns} |
|
254 |
\end{frame} |
|
255 |
||
256 |
\begin{frame}[fragile] |
|
257 |
\frametitle{\mlab\ plotting functions} |
|
258 |
\begin{columns} |
|
259 |
\column{0.25\textwidth} |
|
260 |
\myemph{\Large 0D data} |
|
261 |
\column{0.5\textwidth} |
|
262 |
\pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex} |
|
263 |
\end{columns} |
|
264 |
||
265 |
\begin{lstlisting} |
|
266 |
>>> from numpy import * |
|
267 |
>>> t = linspace(0, 2*pi, 50) |
|
268 |
>>> u = cos(t)*pi |
|
269 |
>>> x, y, z = sin(u), cos(u), sin(t) |
|
270 |
\end{lstlisting} |
|
271 |
\emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}} |
|
272 |
\end{frame} |
|
273 |
||
274 |
\begin{frame} |
|
275 |
\begin{columns} |
|
276 |
\column{0.25\textwidth} |
|
277 |
\myemph{\Large 1D data} |
|
278 |
\column{0.5\textwidth} |
|
279 |
\pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
280 |
\end{columns} |
|
281 |
\emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}} |
|
282 |
||
283 |
Plots lines between the points |
|
284 |
||
285 |
\end{frame} |
|
286 |
||
287 |
\begin{frame}[fragile] |
|
288 |
\begin{columns} |
|
289 |
\column{0.25\textwidth} |
|
290 |
\myemph{\Large 2D data} |
|
291 |
\column{0.5\textwidth} |
|
292 |
\pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex} |
|
293 |
\end{columns} |
|
294 |
\begin{lstlisting} |
|
295 |
>>> x = mgrid[-3:3:100j,-3:3:100j] |
|
296 |
>>> z = sin(x*x + y*y) |
|
297 |
\end{lstlisting} |
|
298 |
||
299 |
\emphbar{\PythonCode{>>> mlab.surf(x, y, z)}} |
|
300 |
||
301 |
\alert{Assumes the points are rectilinear} |
|
302 |
||
303 |
\end{frame} |
|
304 |
||
305 |
\begin{frame}[fragile] |
|
306 |
\myemph{\Large 2D data: \texttt{mlab.mesh}} |
|
307 |
\vspace*{0.25in} |
|
308 |
||
309 |
\emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}} |
|
310 |
||
311 |
\alert{Points needn't be regular} |
|
312 |
||
313 |
\vspace*{0.25in} |
|
314 |
\begin{lstlisting} |
|
315 |
>>> phi, theta = numpy.mgrid[0:pi:20j, |
|
316 |
... 0:2*pi:20j] |
|
317 |
>>> x = sin(phi)*cos(theta) |
|
318 |
>>> y = sin(phi)*sin(theta) |
|
319 |
>>> z = cos(phi) |
|
320 |
>>> mlab.mesh(x, y, z, |
|
321 |
... representation='wireframe') |
|
322 |
\end{lstlisting} |
|
323 |
||
324 |
\end{frame} |
|
325 |
||
326 |
\begin{frame}[fragile] |
|
327 |
||
328 |
\begin{columns} |
|
329 |
\column{0.25\textwidth} |
|
330 |
\myemph{\Large 3D data} |
|
331 |
\column{0.5\textwidth} |
|
332 |
\pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\ |
|
333 |
\end{columns} |
|
334 |
\begin{lstlisting} |
|
335 |
>>> x, y, z = ogrid[-5:5:64j, |
|
336 |
... -5:5:64j, |
|
337 |
... -5:5:64j] |
|
338 |
>>> mlab.contour3d(x*x*0.5 + y*y + |
|
339 |
z*z*2) |
|
340 |
\end{lstlisting} |
|
341 |
\end{frame} |
|
342 |
||
343 |
\begin{frame}[fragile] |
|
344 |
||
345 |
\myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}} |
|
346 |
\vspace*{0.25in} |
|
347 |
||
348 |
\pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\ |
|
349 |
||
350 |
\begin{lstlisting} |
|
351 |
>>> mlab.test_quiver3d() |
|
352 |
\end{lstlisting} |
|
353 |
||
354 |
\emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}} |
|
355 |
\inctime{20} |
|
356 |
\end{frame} |
|
357 |
||
358 |
\subsection{Mayavi2.0} |
|
359 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
360 |
\begin{frame} |
22 | 361 |
\frametitle{Introduction to Mayavi} |
362 |
\begin{itemize} |
|
363 |
\item Most scientists not interested in details of visualization |
|
364 |
\item Visualization of data files with a nice UI |
|
365 |
\item Interactive visualization of data (think Matlab) |
|
366 |
\item Embedding visualizations in applications |
|
367 |
\item Customization |
|
368 |
\end{itemize} |
|
369 |
\pause |
|
370 |
\begin{block}{The Goal} |
|
371 |
Provide a \alert{flexible} library/app for every one of these needs! |
|
372 |
\end{block} |
|
373 |
\end{frame} |
|
374 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
375 |
\begin{frame} |
22 | 376 |
{Overview of features} |
377 |
\vspace*{-0.3in} |
|
378 |
\begin{center} |
|
379 |
\hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3} |
|
380 |
\end{center} |
|
381 |
\end{frame} |
|
382 |
||
383 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
384 |
\begin{frame} |
22 | 385 |
\frametitle{Mayavi in applications} |
386 |
\vspace*{-0.3in} |
|
387 |
\begin{center} |
|
388 |
\hspace*{0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage} |
|
389 |
\end{center} |
|
390 |
\end{frame} |
|
391 |
||
392 |
\begin{frame} |
|
393 |
{Exploring the documentation} |
|
394 |
\begin{center} |
|
395 |
\pgfimage[width=4.5in]{MEDIA/m2/m2_ug_doc} |
|
396 |
\end{center} |
|
397 |
\end{frame} |
|
398 |
||
399 |
||
400 |
\begin{frame} |
|
401 |
\frametitle{Summary} |
|
402 |
\begin{itemize} |
|
403 |
\item \url{http://code.enthought.com/projects/mayavi} |
|
404 |
\item Uses VTK (\url{www.vtk.org}) |
|
405 |
\item BSD license |
|
406 |
\item Linux, win32 and Mac OS X |
|
407 |
\item Highly scriptable |
|
408 |
\item Embed in Traits UIs (wxPython and PyQt4) |
|
409 |
\item Envisage Plugins |
|
410 |
\item Debian/Ubuntu/Fedora |
|
411 |
\item \alert{Pythonic} |
|
412 |
\end{itemize} |
|
413 |
||
414 |
\inctime{10} |
|
415 |
||
416 |
\end{frame} |
|
417 |
||
418 |
\begin{frame} |
|
419 |
{Getting hands dirty!} |
|
420 |
||
421 |
\begin{block}{Motivational problem} |
|
422 |
Atmospheric data of temperature over the surface of the earth. |
|
423 |
Let temperature ($T$) vary linearly with height ($z$): |
|
424 |
\begin{center} |
|
425 |
$T = 288.15 - 6.5z$ |
|
426 |
\end{center} |
|
427 |
\end{block} |
|
428 |
\end{frame} |
|
429 |
||
430 |
\begin{frame}[fragile] |
|
431 |
\frametitle{Simple solution} |
|
432 |
||
433 |
\begin{lstlisting} |
|
434 |
lat = linspace(-89, 89, 37) |
|
435 |
lon = linspace(0, 360, 37) |
|
436 |
z = linspace(0, 100, 11) |
|
437 |
\end{lstlisting} |
|
438 |
\pause |
|
439 |
\begin{lstlisting} |
|
440 |
x, y, z = mgrid[0:360:37j,-89:89:37j, |
|
441 |
0:100:11j] |
|
442 |
t = 288.15 - 6.5*z |
|
443 |
mlab.contour3d(x, y, z, t) |
|
444 |
mlab.outline() |
|
445 |
mlab.colorbar() |
|
446 |
\end{lstlisting} |
|
447 |
\end{frame} |
|
448 |
||
449 |
\begin{frame}[fragile] |
|
450 |
\frametitle{Exercise: Lorenz equation} |
|
451 |
\begin{columns} |
|
452 |
\column{0.25\textwidth} |
|
453 |
\begin{eqnarray*} |
|
454 |
\frac{d x}{dt} &=& s (y-x)\\ |
|
455 |
\frac{d y}{d t} &=& rx -y -xz\\ |
|
456 |
\frac{d z}{d t} &=& xy - bz\\ |
|
457 |
\end{eqnarray*} |
|
458 |
\column{0.25\textwidth} |
|
459 |
Let $s=10,$ |
|
460 |
$r=28,$ |
|
461 |
$b=8./3.$ |
|
462 |
\end{columns} |
|
463 |
\structure{\Large Region of interest} |
|
464 |
\begin{lstlisting} |
|
465 |
x, y, z = mgrid[-50:50:20j,-50:50:20j, |
|
466 |
-10:60:20j] |
|
467 |
\end{lstlisting} |
|
468 |
\inctime{20} |
|
469 |
\end{frame} |
|
470 |
||
471 |
\section{Test Driven Approach} |
|
472 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
473 |
\begin{frame} |
22 | 474 |
\frametitle{Testing code with \typ{nosetests}} |
475 |
||
476 |
\begin{itemize} |
|
477 |
\item Writing tests is really simple! |
|
478 |
||
479 |
\item Using nose |
|
480 |
||
481 |
\item Example! |
|
482 |
\end{itemize} |
|
483 |
\end{frame} |
|
484 |
||
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
485 |
\begin{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
486 |
\frametitle{Need of Testing!} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
487 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
488 |
\begin{itemize} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
489 |
\item Quality |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
490 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
491 |
\item Regression |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
492 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
493 |
\item Documentation |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
494 |
\end{itemize} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
495 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
496 |
|
22 | 497 |
\begin{frame}[fragile] |
498 |
\frametitle{Nosetest} |
|
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
499 |
\begin{lstlisting} |
22 | 500 |
def gcd(a, b): |
501 |
"""Returns gcd of a and b, |
|
502 |
handles only positive numbers.""" |
|
503 |
if a%b == 0: return b |
|
504 |
return gcd(b, a%b) |
|
505 |
def lcm(a, b): |
|
506 |
return a*b/gcd(a, b) |
|
507 |
||
508 |
if __name__ == '__main__': |
|
509 |
import nose |
|
510 |
nose.main() |
|
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
511 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
512 |
\inctime{15} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
513 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
514 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
515 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
516 |
\frametitle{Example} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
517 |
\begin{block}{Problem Statement:} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
518 |
Write a function to check whether a given input |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
519 |
string is a palindrome. |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
520 |
\end{block} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
521 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
522 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
523 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
524 |
\frametitle{Function: code.py} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
525 |
\begin{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
526 |
def is_palindrome(input_str): |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
527 |
return input_str == input_str[::-1] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
528 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
529 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
530 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
531 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
532 |
\frametitle{Test for the palindrome: code.py} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
533 |
\begin{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
534 |
from code import is_palindrome |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
535 |
def test_function_normal_words(): |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
536 |
input = "noon" |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
537 |
assert is_palindrome(input) == True |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
538 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
539 |
\end{frame} |
22 | 540 |
|
23
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
541 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
542 |
\frametitle{Running the tests.} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
543 |
\begin{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
544 |
$ nosetests test.py |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
545 |
. |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
546 |
---------------------------------------------- |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
547 |
Ran 1 test in 0.001s |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
548 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
549 |
OK |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
550 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
551 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
552 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
553 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
554 |
\frametitle{Exercise: Including new tests.} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
555 |
\begin{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
556 |
def test_function_ignore_cases_words(): |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
557 |
input = "Noon" |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
558 |
assert is_palindrome(input) == True |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
559 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
560 |
Check |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
561 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
562 |
\PythonCode{$ nosetests test.py} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
563 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
564 |
Tweak the code to pass this test. |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
565 |
\end{frame} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
566 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
567 |
\begin{frame}[fragile] |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
568 |
\frametitle{Exercise: Some more tests.} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
569 |
\begin{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
570 |
def test_function_ignore_spaces_in_text(): |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
571 |
input = "ab raca carba" |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
572 |
assert is_palindrome(input) == True |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
573 |
\end{lstlisting} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
574 |
Check |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
575 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
576 |
\PythonCode{$ nosetests test.py} |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
577 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
578 |
Tweak the code to pass this test. |
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
579 |
|
14c817585247
Added Exercise for testing in Session3.
Shantanu <shantanu@fossee.in>
parents:
22
diff
changeset
|
580 |
\inctime{15} |
22 | 581 |
\end{frame} |
582 |
||
583 |
\end{document} |
|
584 |