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