day2/session3.tex
changeset 23 14c817585247
parent 22 492017122355
child 46 63704b5650f1
equal deleted inserted replaced
22:492017122355 23:14c817585247
    45 
    45 
    46 \definecolor{darkgreen}{rgb}{0,0.5,0}
    46 \definecolor{darkgreen}{rgb}{0,0.5,0}
    47 
    47 
    48 \usepackage{listings}
    48 \usepackage{listings}
    49 \lstset{language=Python,
    49 \lstset{language=Python,
    50   commentstyle=\color{red}\itshape,
    50     basicstyle=\ttfamily\bfseries,
       
    51     commentstyle=\color{red}\itshape,
    51   stringstyle=\color{darkgreen},
    52   stringstyle=\color{darkgreen},
    52   showstringspaces=false,
    53   showstringspaces=false,
    53   keywordstyle=\color{blue}\bfseries}
    54   keywordstyle=\color{blue}\bfseries}
    54 
    55 
    55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   192 
   193 
   193 \section{Tools at your disposal:}
   194 \section{Tools at your disposal:}
   194 
   195 
   195 \subsection{mlab}
   196 \subsection{mlab}
   196 
   197 
   197 \begin{frame}[fragile]
   198 \begin{frame}
   198     {Overview}
   199     {Overview}
   199     \Large
   200     \Large
   200     \begin{itemize}
   201     \begin{itemize}
   201         \item Simple
   202         \item Simple
   202         \item Convenient
   203         \item Convenient
   235 >>> mlab.test_contour3d()
   236 >>> mlab.test_contour3d()
   236 >>> mlab.test_contour3d??
   237 >>> mlab.test_contour3d??
   237     \end{lstlisting}
   238     \end{lstlisting}
   238 \end{frame}
   239 \end{frame}
   239 
   240 
   240 \begin{frame}[fragile]
   241 \begin{frame}
   241     {Exploring the view}
   242     {Exploring the view}
   242     \begin{columns}
   243     \begin{columns}
   243         \column{0.6\textwidth}
   244         \column{0.6\textwidth}
   244     \pgfimage[width=3in]{MEDIA/m2/contour3d}
   245     \pgfimage[width=3in]{MEDIA/m2/contour3d}
   245         \column{0.4\textwidth}
   246         \column{0.4\textwidth}
   354 \inctime{20}
   355 \inctime{20}
   355 \end{frame}
   356 \end{frame}
   356 
   357 
   357 \subsection{Mayavi2.0}
   358 \subsection{Mayavi2.0}
   358 
   359 
   359 \begin{frame}[fragile]
   360 \begin{frame}
   360   \frametitle{Introduction to Mayavi}
   361   \frametitle{Introduction to Mayavi}
   361   \begin{itemize}
   362   \begin{itemize}
   362   \item Most scientists not interested in details of visualization
   363   \item Most scientists not interested in details of visualization
   363   \item Visualization of data files with a nice UI
   364   \item Visualization of data files with a nice UI
   364   \item Interactive visualization of data (think Matlab)
   365   \item Interactive visualization of data (think Matlab)
   369   \begin{block}{The Goal}
   370   \begin{block}{The Goal}
   370       Provide a \alert{flexible} library/app for every one of these needs!
   371       Provide a \alert{flexible} library/app for every one of these needs!
   371   \end{block}
   372   \end{block}
   372 \end{frame}
   373 \end{frame}
   373 
   374 
   374 \begin{frame}[fragile]
   375 \begin{frame}
   375     {Overview of features}
   376     {Overview of features}
   376       \vspace*{-0.3in}
   377       \vspace*{-0.3in}
   377   \begin{center}    
   378   \begin{center}    
   378     \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3}
   379     \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3}
   379   \end{center}    
   380   \end{center}    
   380 \end{frame}
   381 \end{frame}
   381 
   382 
   382 
   383 
   383 \begin{frame}[fragile]
   384 \begin{frame}
   384     \frametitle{Mayavi in applications}
   385     \frametitle{Mayavi in applications}
   385       \vspace*{-0.3in}
   386       \vspace*{-0.3in}
   386   \begin{center}    
   387   \begin{center}    
   387     \hspace*{0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage}
   388     \hspace*{0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage}
   388   \end{center}
   389   \end{center}
   467 \inctime{20}
   468 \inctime{20}
   468 \end{frame}
   469 \end{frame}
   469 
   470 
   470 \section{Test Driven Approach}
   471 \section{Test Driven Approach}
   471 
   472 
   472 \begin{frame}[fragile]
   473 \begin{frame}
   473     \frametitle{Testing code with \typ{nosetests}}
   474     \frametitle{Testing code with \typ{nosetests}}
   474    
   475    
   475     \begin{itemize}
   476     \begin{itemize}
   476         \item Writing tests is really simple!
   477         \item Writing tests is really simple!
   477 
   478 
   479 
   480 
   480         \item Example!
   481         \item Example!
   481     \end{itemize}
   482     \end{itemize}
   482 \end{frame}
   483 \end{frame}
   483 
   484 
       
   485 \begin{frame}
       
   486     \frametitle{Need of Testing!}
       
   487    
       
   488     \begin{itemize}
       
   489         \item Quality
       
   490 
       
   491         \item Regression
       
   492 
       
   493         \item Documentation
       
   494     \end{itemize}
       
   495 \end{frame}
       
   496 
   484 \begin{frame}[fragile]
   497 \begin{frame}[fragile]
   485     \frametitle{Nosetest}
   498     \frametitle{Nosetest}
   486 \begin{lstlisting}
   499   \begin{lstlisting}
   487 def gcd(a, b):
   500 def gcd(a, b):
   488     """Returns gcd of a and b, 
   501     """Returns gcd of a and b, 
   489      handles only positive numbers."""
   502      handles only positive numbers."""
   490     if a%b == 0: return b
   503     if a%b == 0: return b
   491     return gcd(b, a%b)
   504     return gcd(b, a%b)
   493     return a*b/gcd(a, b)
   506     return a*b/gcd(a, b)
   494 
   507 
   495 if __name__ == '__main__':
   508 if __name__ == '__main__':
   496     import nose
   509     import nose
   497     nose.main()
   510     nose.main()
       
   511   \end{lstlisting}
       
   512 \inctime{15}
       
   513 \end{frame}
       
   514 
       
   515 \begin{frame}[fragile]
       
   516     \frametitle{Example}
       
   517     \begin{block}{Problem Statement:}
       
   518       Write a function to check whether a given input
       
   519       string is a palindrome.
       
   520     \end{block}
       
   521 \end{frame}
       
   522 
       
   523 \begin{frame}[fragile]
       
   524     \frametitle{Function: code.py}
       
   525 \begin{lstlisting}    
       
   526 def is_palindrome(input_str):
       
   527   return input_str == input_str[::-1]
       
   528 \end{lstlisting}    
       
   529 \end{frame}
       
   530 
       
   531 \begin{frame}[fragile]
       
   532     \frametitle{Test for the palindrome: code.py}
       
   533 \begin{lstlisting}    
       
   534 from code import is_palindrome
       
   535 def test_function_normal_words():
       
   536   input = "noon"
       
   537   assert is_palindrome(input) == True
       
   538 \end{lstlisting}    
       
   539 \end{frame}
       
   540 
       
   541 \begin{frame}[fragile]
       
   542     \frametitle{Running the tests.}
       
   543 \begin{lstlisting}    
       
   544 $ nosetests test.py 
       
   545 .
       
   546 ----------------------------------------------
       
   547 Ran 1 test in 0.001s
       
   548 
       
   549 OK
       
   550 \end{lstlisting}    
       
   551 \end{frame}
       
   552 
       
   553 \begin{frame}[fragile]
       
   554     \frametitle{Exercise: Including new tests.}
       
   555 \begin{lstlisting}    
       
   556 def test_function_ignore_cases_words():
       
   557   input = "Noon"
       
   558   assert is_palindrome(input) == True
   498 \end{lstlisting}
   559 \end{lstlisting}
   499 
   560 Check
   500     \inctime{10} 
   561 
       
   562 \PythonCode{$ nosetests test.py} 
       
   563 
       
   564 Tweak the code to pass this test.
       
   565 \end{frame}
       
   566 
       
   567 \begin{frame}[fragile]
       
   568     \frametitle{Exercise: Some more tests.}
       
   569 \begin{lstlisting}    
       
   570 def test_function_ignore_spaces_in_text():
       
   571     input = "ab raca carba"
       
   572     assert is_palindrome(input) == True
       
   573 \end{lstlisting}
       
   574 Check
       
   575 
       
   576 \PythonCode{$ nosetests test.py} 
       
   577 
       
   578 Tweak the code to pass this test.
       
   579 
       
   580 \inctime{15} 
   501 \end{frame}
   581 \end{frame}
   502 
   582 
   503 \end{document}
   583 \end{document}
   504 
   584