% Created 2011-07-19 Tue 16:14
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage[english]{babel} \usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
\usepackage{listings}
\lstset{language=Python, basicstyle=\ttfamily\bfseries,
commentstyle=\color{red}\itshape, stringstyle=\color{red},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}

\title{}
\author{FOSSEE}
\date{}

\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}











\begin{frame}

\begin{center}
\vspace{12pt}
\textcolor{blue}{\huge Testing and Debugging}
\end{center}
\vspace{18pt}
\begin{center}
\vspace{10pt}
\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
\vspace{5pt}
\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ 
\scriptsize Funded by National Mission on Education through ICT\\
\scriptsize  MHRD,Govt. of India\\
\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
\end{center}
\end{frame}
\begin{frame}
\frametitle{Objectives}
\label{sec-2}

  At the end of the tutorial, you will be able to,


\begin{itemize}
\item Understand what is software testing.
\item Test simple functions for their functionality.
\item Automate tests.
\item Understand the need for coding style
\item Learn  some of the standards followed by the Python Community.
\item Handle Errors and Exceptions.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Pre-requisite}
\label{sec-3}

Spoken tutorial on -

\begin{itemize}
\item Getting started with functions.
\item Advanced Features of functions.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{gcd function}
\label{sec-4}


\begin{itemize}
\item Create gcd.py file with:
\lstset{language=Python}
\begin{lstlisting}
def gcd(a, b):
      if a % b == 0: 
          return b
      return gcd(b, a%b)
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Test for gcd.py}
\label{sec-5}


\begin{itemize}
\item Edit gcd.py file
\lstset{language=Python}
\begin{lstlisting}
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

if __name__=='__main__':
    result = gcd(48, 64)
    if result != 16:
        print "Test failed"
    print "Test Passed"
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Idiom}
\label{sec-6}

if \_\_name\_\_ == `\_\_main\_\_':
\end{frame}
\begin{frame}
\frametitle{Exercise 1}
\label{sec-7}


\begin{itemize}
\item Write code for gcd and write tests for it
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Structure of file}
\label{sec-8}


\begin{center}
\begin{tabular}{|l|c|c|c}
\hline
   12    &   28     &  4  \\
\hline   
   18    &   36     &  18  \\
\hline   
   4678  &   39763  &  2339  \\
\hline 
\end{tabular}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Exercise 2}
\label{sec-9}


\begin{itemize}
\item For the same inputs as gcd write automated tests for LCM.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Solution 2}
\label{sec-10}

\lstset{language=Python}
\begin{lstlisting}
def gcd(a, b):
    if a % b == 0: 
        return b
    return gcd(b, a%b)
def lcm(a, b):
    return (a * b) / gcd(a, b)
if __name__ == '__main__':
    for line in open('lcmtestcases.txt'):
        numbers = line.split()
        x = int(numbers[0])
        y = int(numbers[1])
        result = int(numbers[2])
        if lcm(x, y) != result:
            print "Failed lcm test for", x, y
        else:
            print "Test passed", result
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Meaning full names}
\label{sec-11}

\lstset{language=Python}
\begin{lstlisting}

amount = 12.68
denom = 0.05
nCoins = round(amount / denom)
rAmount = nCoins * denom
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Code style}
\label{sec-12}


\begin{itemize}
\item Four Space Indentation
\item 79 character limit on a line
\item Funtions should be seperated by 
   blank line
\item Use Docstring
\item White space around operators
\begin{itemize}
\item l = 32 \% 4
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Exercise 3}
\label{sec-13}


\begin{itemize}
\item Give meaningful names to the variables in following
     code
\begin{itemize}
\item c = a / b
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Solution 3}
\label{sec-14}

\lstset{language=Python}
\begin{lstlisting}

quotient = dividend / divisor
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Using idb}
\label{sec-15}

\small
\begin{lstlisting}
In []: import mymodule
In []: mymodule.test()
---------------------------------------------
NameError   Traceback (most recent call last)
<ipython console> in <module>()
mymodule.py in test()
      1 def test():
      2     total=1+1
----> 3     print spam
NameError: global name 'spam' is not defined

In []: %debug
> mymodule.py(2)test()
      0     print spam
ipdb> total
2
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Summary}
\label{sec-16}

 In this tutorial, we have learnt to, 
        

\begin{itemize}
\item Create simple tests for a function.
\item Automate tests using many predefined test cases.
\item Use the python coding standards.
\item Differentiate between syntax error and exception.
\item Handle exception using ``try'' and ``except''.
\item Use ``\%debug'' for debugging on ipython.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Evaluation}
\label{sec-17}


\begin{enumerate}
\item What is proper indentation for python code according to style guidelines?
\begin{itemize}
\item two space identation
\item three space identation
\item four Space Indentation
\item no Indentation
\end{itemize}
\vspace{3pt}
\item How do you start the debugger on ipython?
\begin{itemize}
\item debug
\item \%debug
\item \%debugger
\item start debugger
\end{itemize}
\vspace{3pt}
\item What is the idiom used for running python scripts in a standalone manner?
\end{enumerate}
\end{frame}
\begin{frame}
\frametitle{Solutions}
\label{sec-18}


\begin{enumerate}
\item Four Space Indentation
\vspace{12pt}
\item \%debug
\vspace{12pt}
\item if \_\_name\_\_ == `\_\_main\_\_':
\end{enumerate}
\end{frame}
\begin{frame}

  \begin{block}{}
  \begin{center}
  \textcolor{blue}{\Large THANK YOU!} 
  \end{center}
  \end{block}
\begin{block}{}
  \begin{center}
    For more Information, visit our website\\
    \url{http://fossee.in/}
  \end{center}  
  \end{block}
\end{frame}

\end{document}