#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [presentation]
#+BEAMER_FRAME_LEVEL: 1
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [presentation]
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
#+LaTeX_HEADER: \usepackage{listings}
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{red},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
#+TITLE: Testing and debugging
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE: en
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
* Outline
- What software Testing is?
- Learn to test simple functions for their functionality.
- Learn how to automate tests.
- Need for coding style and some of the standards followed by the Python Community.
- Handling Errors and Exceptions.
* gcd function
- Create gcd.py file with:
#+begin_LaTeX
\begin{lstlisting}[language=python]
def gcd(a, b):
if a % b == 0:
return b
return gcd(b, a%b)
\end{lstlisting}
#+end_LaTeX
* Test for gcd.py
- Edit gcd.py file
#+begin_LaTeX
\begin{lstlisting}[language=python]
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_LaTeX
* Automating tests
#+begin_LaTeX
\begin{lstlisting}[language=python]
if __name=__='__main__':
for line in open('numbers.txt'):
numbers = line.split()
x = int(numbers[0])
y = int(numbers[1])
result = int(numbers[2])
if gcd(x, y) != result:
print "Failed gcd test
for", x, y
\end{lstlisting}
#+end_LaTeX