day2/session4.tex
author Christopher Burns <chris.d.burns@gmail.com>
Tue, 29 Jun 2010 00:59:26 -0500
branchscipy2010
changeset 432 13e5d0e2cd40
parent 389 aa392117454f
child 433 af45c8da1d5d
permissions -rw-r--r--
DOC: Add more slides on testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     2
% Tutorial slides on Python.
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     3
%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     4
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     5
% Copyright (c) 2005-2009, Prabhu Ramachandran
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     7
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     8
\documentclass[compress,14pt]{beamer}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     9
% \documentclass[handout]{beamer}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    10
% \usepackage{pgfpages}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    11
% \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    12
\usepackage{tikz}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    13
\newcommand{\hyperlinkmovie}{}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    14
%\usepackage{movie15}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    15
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    16
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    17
% Note that in presentation mode 
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    18
% \paperwidth  364.19536pt
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    19
% \paperheight 273.14662pt
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    20
% h/w = 0.888
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    21
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    22
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    23
\mode<presentation>
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    24
{
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    25
  \usetheme{Warsaw}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    26
  %\usetheme{Boadilla}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    27
  %\usetheme{default}
239
8953675dc056 Added slide numbers.
Puneeth Chaganti <punchagan@fossee.in>
parents: 220
diff changeset
    28
  \useoutertheme{infolines}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    29
  \setbeamercovered{transparent}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    30
}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    31
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    32
% To remove navigation symbols
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    33
\setbeamertemplate{navigation symbols}{}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    34
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    35
\usepackage{amsmath}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    36
\usepackage[english]{babel}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    37
\usepackage[latin1]{inputenc}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    38
\usepackage{times}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    39
\usepackage[T1]{fontenc}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    40
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    41
% Taken from Fernando's slides.
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    42
\usepackage{ae,aecompl}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    43
\usepackage{mathpazo,courier,euler}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    44
\usepackage[scaled=.95]{helvet}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    45
\usepackage{pgf}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    46
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    47
\definecolor{darkgreen}{rgb}{0,0.5,0}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    48
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    49
\usepackage{listings}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    50
\lstset{language=Python,
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    51
    basicstyle=\ttfamily\bfseries,
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    52
    commentstyle=\color{red}\itshape,
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    53
  stringstyle=\color{darkgreen},
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    54
  showstringspaces=false,
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    55
  keywordstyle=\color{blue}\bfseries}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    56
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    57
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    58
% My Macros
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    59
\setbeamercolor{postit}{bg=yellow,fg=black}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    60
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    61
\newcommand{\emphbar}[1]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    62
{\begin{beamercolorbox}[rounded=true]{emphbar} 
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    63
      {#1}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    64
 \end{beamercolorbox}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    65
}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    66
%{\centerline{\fcolorbox{gray!50} {blue!10}{
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    67
%\begin{minipage}{0.9\linewidth}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    68
%    {#1} 
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    69
%\end{minipage}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    70
%    }}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    71
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    72
\newcommand{\myemph}[1]{\structure{\emph{#1}}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    73
\newcommand{\PythonCode}[1]{\lstinline{#1}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    74
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    75
\newcommand{\tvtk}{\texttt{tvtk}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    76
\newcommand{\mlab}{\texttt{mlab}}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
    77
\newcommand{\typ}[1]{\lstinline{#1}}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    78
\newcounter{time}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    79
\setcounter{time}{0}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    80
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    81
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    82
\newcommand\BackgroundPicture[1]{%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    83
  \setbeamertemplate{background}{%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    84
      \parbox[c][\paperheight]{\paperwidth}{%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    85
      \vfill \hfill
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    86
 \hfill \vfill
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    87
}}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    88
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    89
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    90
% Configuring the theme
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    91
%\setbeamercolor{normal text}{fg=white}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    92
%\setbeamercolor{background canvas}{bg=black}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    93
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    94
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    95
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    96
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    97
% Title page
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
    98
\title[Python Development]{Python Development}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    99
220
15306dad3b81 Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents: 219
diff changeset
   100
\author[FOSSEE] {FOSSEE}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   101
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   102
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
389
aa392117454f Changed dates for MVIT workshop.
Puneeth Chaganti <punchagan@gmail.com>
parents: 385
diff changeset
   103
\date[] {1 May, 2010\\Day 2, Session 4}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   104
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   105
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   106
%\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   107
%\logo{\pgfuseimage{iitblogo}}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   108
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   109
\AtBeginSection[]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   110
{
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   111
  \begin{frame}<beamer>
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   112
    \frametitle{Outline}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   113
      \Large
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   114
    \tableofcontents[currentsection,currentsubsection]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   115
  \end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   116
}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   117
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   118
%% Delete this, if you do not want the table of contents to pop up at
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   119
%% the beginning of each subsection:
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   120
\AtBeginSubsection[]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   121
{
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   122
  \begin{frame}<beamer>
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   123
    \frametitle{Outline}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   124
    \tableofcontents[currentsection,currentsubsection]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   125
  \end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   126
}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   127
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   128
\AtBeginSection[]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   129
{
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   130
  \begin{frame}<beamer>
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   131
    \frametitle{Outline}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   132
    \tableofcontents[currentsection,currentsubsection]
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   133
  \end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   134
}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   135
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   136
% DOCUMENT STARTS
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   137
\begin{document}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   138
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   139
\begin{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   140
  \maketitle
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   141
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   142
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   143
\section{Tests: Getting started}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   144
\begin{frame}[fragile] 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   145
  \frametitle{gcd revisited!}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   146
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   147
  \item Open \texttt{gcd.py}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   148
  \end{itemize}  
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   149
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   150
    def gcd(a, b):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   151
        if a % b == 0: 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   152
            return b
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   153
        return gcd(b, a%b)
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   154
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   155
    print gcd(15, 65)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   156
    print gcd(16, 76)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   157
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   158
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   159
  \item \texttt{python gcd.py}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   160
  \end{itemize}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   161
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   162
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   163
\begin{frame}[fragile] 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   164
  \frametitle{Find lcm using our gcd module}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   165
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   166
  \item Open \texttt{lcm.py}  
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   167
  \item $lcm = \frac{a * b}{gcd(a,b)}$
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   168
  \end{itemize}  
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   169
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   170
    from gcd import gcd    
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   171
    def lcm(a, b):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   172
        return (a * b) / gcd(a, b)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   173
    
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   174
    print lcm(14, 56)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   175
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   176
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   177
  \item \texttt{python lcm.py}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   178
  \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   179
  \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   180
5
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   181
4
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   182
56
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   183
  \end{lstlisting}    
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   184
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   185
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   186
\begin{frame}[fragile] 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   187
  \frametitle{Writing stand-alone module}  
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   188
Edit \texttt{gcd.py} file to:
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   189
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   190
    def gcd(a, b):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   191
        if a % b == 0: 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   192
            return b
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   193
        return gcd(b, a%b)
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   194
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   195
    if __name__ == "__main__":        
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   196
        print gcd(15, 65)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   197
        print gcd(16, 76)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   198
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   199
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   200
  \item \texttt{python gcd.py}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   201
  \item \texttt{python lcm.py}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   202
  \end{itemize}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   203
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   204
432
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   205
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   206
\begin{frame}[fragile]
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   207
  \frametitle{Automating tests}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   208
  \begin{lstlisting}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   209
  
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   210
def gcd(a, b):
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   211
    if a % b == 0:
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   212
        return b
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   213
    return gcd(b, a % b)
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   214
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   215
if __name__ == '__main__':
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   216
    assert gcd(15, 65) == 5
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   217
    assert gcd(16, 76) == 4
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   218
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   219
  \end{lstlisting}  
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   220
\end{frame}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   221
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   222
\begin{frame}[fragile]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   223
  \frametitle{Automating tests}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   224
  \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   225
if __name__ == '__main__':
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   226
    for line in open('numbers.txt'):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   227
        numbers = line.split()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   228
        x = int(numbers[0])
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   229
        y = int(numbers[1])
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   230
        result = int(numbers[2])
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   231
        if gcd(x, y) != result:
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   232
            print "Failed gcd test
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   233
                          for", x, y
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   234
  \end{lstlisting}  
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   235
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   236
432
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   237
\begin{frame}[fragile]
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   238
  \frametitle{Python Test Packages}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   239
    \begin{itemize}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   240
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   241
\item Python's \typ{unittest}:\linebreak
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   242
  \url{http://docs.python.org/library/unittest.html}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   243
\linebreak
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   244
\item \typ{nose}:\linebreak
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   245
  \url{http://code.google.com/p/python-nose/}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   246
  \end{itemize}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   247
\end{frame}
13e5d0e2cd40 DOC: Add more slides on testing
Christopher Burns <chris.d.burns@gmail.com>
parents: 389
diff changeset
   248
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   249
\section{Coding Style}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   250
\begin{frame}{Readability and Consistency}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   251
    \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   252
        \item Readability Counts!\\Code is read more often than its written.
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   253
        \item Consistency!
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   254
        \item Know when to be inconsistent.
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   255
      \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   256
\end{frame}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   257
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   258
\begin{frame}[fragile] \frametitle{A question of good style}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   259
  \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   260
    amount = 12.68
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   261
    denom = 0.05
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   262
    nCoins = round(amount/denom)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   263
    rAmount = nCoins * denom
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   264
  \end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   265
  \pause
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   266
  \begin{block}{Style Rule \#1}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   267
    Naming is 80\% of programming
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   268
  \end{block}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   269
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   270
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   271
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   272
  \frametitle{Code Layout}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   273
  \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   274
        \item Indentation
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   275
        \item Tabs or Spaces?
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   276
        \item Maximum Line Length
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   277
        \item Blank Lines
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   278
        \item Encodings
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   279
   \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   280
\end{frame}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   281
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   282
\begin{frame}{Whitespaces in Expressions}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   283
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   284
        \item When to use extraneous whitespaces?
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   285
        \item When to avoid extra whitespaces?
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   286
        \item Use one statement per line
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   287
   \end{itemize}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   288
\end{frame}
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   289
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   290
\begin{frame}{Comments}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   291
  \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   292
        \item No comments better than contradicting comments
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   293
        \item Block comments
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   294
        \item Inline comments
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   295
   \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   296
\end{frame}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   297
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   298
\begin{frame}{Docstrings}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   299
  \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   300
        \item When to write docstrings?
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   301
        \item Ending the docstrings
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   302
        \item One liner docstrings
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   303
   \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   304
More information at PEP8: http://www.python.org/dev/peps/pep-0008/
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   305
\inctime{5}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   306
\end{frame}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   307
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   308
\section{Debugging}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   309
\subsection{Errors and Exceptions}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   310
\begin{frame}[fragile]
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   311
 \frametitle{Errors}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   312
 \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   313
In []: while True print 'Hello world'
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   314
 \end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   315
\pause
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   316
  \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   317
  File "<stdin>", line 1, in ?
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   318
    while True print 'Hello world'
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   319
                   ^
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   320
SyntaxError: invalid syntax
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   321
\end{lstlisting}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   322
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   323
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   324
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   325
 \frametitle{Exceptions}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   326
 \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   327
In []: print spam
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   328
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   329
\pause
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   330
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   331
Traceback (most recent call last):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   332
  File "<stdin>", line 1, in <module>
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   333
NameError: name 'spam' is not defined
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   334
\end{lstlisting}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   335
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   336
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   337
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   338
 \frametitle{Exceptions}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   339
 \begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   340
In []: 1 / 0
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   341
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   342
\pause
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   343
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   344
Traceback (most recent call last):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   345
  File "<stdin>", line 1, in <module>
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   346
ZeroDivisionError: integer division 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   347
or modulo by zero
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   348
\end{lstlisting}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   349
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   350
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   351
\begin{frame}[fragile]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   352
  \frametitle{Processing user input}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   353
  \begin{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   354
prompt = 'Enter a number(Q to quit): '
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   355
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   356
a = raw_input(prompt)
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   357
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   358
num = int(a) if a != 'Q' else 0
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   359
  \end{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   360
  \emphbar{What if the user enters some other alphabet?}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   361
\end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   362
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   363
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   364
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   365
  \frametitle{Handling Exceptions}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   366
  Python provides \typ{try} and \typ{except} clause.
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   367
  \begin{lstlisting}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   368
prompt = 'Enter a number(Q to quit): '
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   369
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   370
a = raw_input(prompt)
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   371
try:
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   372
    num = int(a)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   373
    print num
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   374
except:
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   375
    if a == 'Q':
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   376
        print "Exiting ..."
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   377
    else:
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   378
        print "Wrong input ..."
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   379
  \end{lstlisting}  
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   380
\end{frame}
263
8a4a1e5aec85 Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents: 256
diff changeset
   381
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   382
\subsection{Strategy}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   383
\begin{frame}[fragile]
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   384
    \frametitle{Debugging effectively}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   385
    \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   386
        \item \typ{print} based strategy
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   387
        \item Process:
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   388
    \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   389
\begin{center}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   390
\pgfimage[interpolate=true,width=5cm,height=5cm]{DebugginDiagram.png}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   391
\end{center}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   392
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   393
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   394
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   395
    \frametitle{Debugging effectively}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   396
    \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   397
      \item Using \typ{\%debug} in IPython
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   398
    \end{itemize}
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   399
\end{frame}
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   400
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   401
\begin{frame}[fragile]
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   402
\frametitle{Debugging in IPython}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   403
\small
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   404
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   405
In []: import mymodule
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   406
In []: mymodule.test()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   407
---------------------------------------------
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   408
NameError   Traceback (most recent call last)
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   409
<ipython console> in <module>()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   410
mymodule.py in test()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   411
      1 def test():
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   412
----> 2     print spam
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   413
NameError: global name 'spam' is not defined
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 263
diff changeset
   414
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   415
In []: %debug
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   416
> mymodule.py(2)test()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   417
      0     print spam
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   418
ipdb> 
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 263
diff changeset
   419
\end{lstlisting}
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   420
\inctime{15} 
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 263
diff changeset
   421
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 263
diff changeset
   422
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   423
\subsection{Exercise}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   424
\begin{frame}[fragile]
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   425
\frametitle{Debugging: Exercise}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   426
\small
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   427
\begin{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   428
science = {}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 263
diff changeset
   429
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   430
for record in open('sslc1.txt'):
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   431
    fields = record.split(';')
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   432
    region_code = fields[0].strip()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   433
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   434
    score_str = fields[6].strip()
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   435
    score = int(score_str) if score_str != 'AA' 
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   436
                           else 0
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   437
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   438
    if score > 90:
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   439
        science[region_code] += 1
219
f6725f6bee41 Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
   440
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   441
pie(science.values(), labels=science.keys())
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   442
savefig('science.png')
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   443
\end{lstlisting}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   444
\inctime{10}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   445
\end{frame}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   446
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   447
\begin{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   448
  \frametitle{Summary}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   449
We have covered:
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   450
  \begin{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   451
  \item Following and Resolving Error Messages.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   452
  \item Exceptions.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   453
  \item Handling exceptions
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   454
  \item Approach for Debugging.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   455
%  \item Writting and running tests.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   456
  \end{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   457
\end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   458
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   459
\end{document}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   460
344
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   461
%% \begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   462
%%     \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   463
%%     Consider a module called \lstinline+gcd.py+ looking like this:
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   464
%%     \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   465
%% def gcd(a, b):
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   466
%%    ...
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   467
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   468
%% if __name__ == '__main__':
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   469
%%     print gcd(10, 25)
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   470
%%     \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   471
%% If this module is imported, will it print the gcd of 10 and 25?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   472
%% \end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   473
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   474
%% \begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   475
%%     \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   476
%%   \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   477
%% In [1]: print hello 
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   478
%%   \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   479
%%   Exactly what exception will you get if you run this on a fresh
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   480
%%   interpreter?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   481
%% \end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   482
289
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   483
%% \begin{frame}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   484
%%     \frametitle{Testing}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   485
   
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   486
%%     \begin{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   487
%%         \item Writing tests is really simple!
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   488
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   489
%%         \item Using nose.
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   490
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   491
%%         \item Example!
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   492
%%     \end{itemize}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   493
%% \end{frame}
884d42eff66d Reorganized last 3 sessions of day 2 again.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   494
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   495
% \section{Test Driven Approach}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   496
% \begin{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   497
%     \frametitle{Need for Testing!}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   498
%    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   499
%     \begin{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   500
%         \item Quality
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   501
%         \item Regression
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   502
%         \item Documentation
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   503
%     \end{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   504
%     %% \vspace*{0.25in}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   505
%     %% \emphbar{It is to assure that section of code is working as it is supposed to work}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   506
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   507
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   508
% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   509
%     \frametitle{Example}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   510
%     \begin{block}{Problem Statement}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   511
%       Write a function to check whether a given input
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   512
%       string is a palindrome.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   513
%     \end{block}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   514
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   515
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   516
% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   517
%     \frametitle{Function: palindrome.py}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   518
% \begin{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   519
% def is_palindrome(input_str):
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   520
%   return input_str == input_str[::-1]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   521
% \end{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   522
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   523
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   524
% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   525
%     \frametitle{Test for the palindrome: palindrome.py}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   526
% \begin{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   527
% def test_function_normal_words():
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   528
%   input = "noon"
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   529
%   assert is_palindrome(input) == True
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   530
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   531
% if __name__ == "main'':
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   532
%   test_function_normal_words()
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   533
% \end{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   534
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   535
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   536
% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   537
%     \frametitle{Running the tests.}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   538
% \begin{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   539
% $ nosetests palindrome.py 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   540
% .
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   541
% ----------------------------------------------
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   542
% Ran 1 test in 0.001s
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   543
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   544
% OK
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   545
% \end{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   546
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   547
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   548
% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   549
%     \frametitle{Exercise: Including new tests.}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   550
% \begin{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   551
% def test_function_ignore_cases_words():
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   552
%   input = "Noon"
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   553
%   assert is_palindrome(input) == True
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   554
% \end{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   555
%      \vspace*{0.25in}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   556
%      Check\\
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   557
%      \PythonCode{$ nosetests palindrome.py} \\
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   558
%      \begin{block}{Task}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   559
%      Tweak the code to pass this test.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   560
%      \end{block}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   561
% \end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   562
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   563
% %\begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   564
% %    \frametitle{Lets write some test!}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   565
% %\begin{lstlisting}    
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   566
% %#for form of equation y=mx+c
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   567
% %#given m and c for two equation,
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   568
% %#finding the intersection point.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   569
% %def intersect(m1,c1,m2,c2):
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   570
% %    x = (c2-c1)/(m1-m2)
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   571
% %    y = m1*x+c1
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   572
% %    return (x,y)
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   573
% %\end{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   574
% %
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   575
% %Create a simple test for this
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   576
% %
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   577
% %function which will make it fail.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   578
% %
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   579
% %\inctime{15} 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   580
% %\end{frame}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   581
% %
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   582
% 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   583
% %% \begin{frame}[fragile]
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   584
% %%     \frametitle{Exercise}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   585
% %%     Based on Euclid's algorithm:
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   586
% %%     \begin{center}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   587
% %%     $gcd(a,b)=gcd(b,b\%a)$
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   588
% %%     \end{center}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   589
% %%     gcd function can be written as:
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   590
% %%     \begin{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   591
% %%     def gcd(a, b):
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   592
% %%       if a%b == 0: return b
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   593
% %%       return gcd(b, a%b)
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   594
% %%     \end{lstlisting}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   595
% %%     \vspace*{-0.15in}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   596
% %%     \begin{block}{Task}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   597
% %%       \begin{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   598
% %%       \item Write at least 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   599
% %%         two tests for above mentioned function.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   600
% %%       \item Write a non recursive implementation
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   601
% %%       of gcd(), and test it using already 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   602
% %%       written tests.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   603
% %%       \end{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   604
% %%     \end{block}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   605
%     
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 289
diff changeset
   606
% %% \inctime{15} 
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 297
diff changeset
   607
% %% \end{frame}