author | Puneeth Chaganti <punchagan@fossee.in> |
Thu, 05 Nov 2009 14:56:52 +0530 | |
changeset 279 | e7ce6f9d7e15 |
parent 263 | 8a4a1e5aec85 |
child 288 | c4e25269a86c |
permissions | -rw-r--r-- |
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}} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
239
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 |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
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} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
103 |
\date[] {1 November, 2009\\Day 2, Session 3} |
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> |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
112 |
\frametitle{Outline} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
113 |
\Large |
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 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
143 |
\section{Tests: Getting started} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
144 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
145 |
\frametitle{gcd revisited!} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
146 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
147 |
\item Open gcd.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
148 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
149 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
150 |
def gcd(a, b): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
151 |
if a % b == 0: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
152 |
return b |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
153 |
return gcd(b, a%b) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
154 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
155 |
print gcd(15, 65) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
156 |
print gcd(16, 76) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
157 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
158 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
159 |
\item python gcd.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
160 |
\end{itemize} |
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 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
163 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
164 |
\frametitle{Find lcm using our gcd module} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
165 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
166 |
\item Open lcm.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
167 |
\item $lcm = \frac{a*b}{gcd(a,b)}$ |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
168 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
169 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
170 |
from gcd import gcd |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
171 |
def lcm(a, b): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
172 |
return (a * b) / gcd(a, b) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
173 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
174 |
print lcm(14, 56) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
175 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
176 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
177 |
\item python lcm.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
178 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
179 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
180 |
5 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
181 |
4 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
182 |
56 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
183 |
\end{lstlisting} |
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 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
186 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
187 |
\frametitle{Writing stand-alone module} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
188 |
Edit gcd.py file to: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
189 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
190 |
def gcd(a, b): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
191 |
if a % b == 0: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
192 |
return b |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
193 |
return gcd(b, a%b) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
194 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
195 |
if __name__ == "__main__": |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
196 |
print gcd(15, 65) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
197 |
print gcd(16, 76) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
198 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
199 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
200 |
\item python gcd.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
201 |
\item python lcm.py |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
202 |
\end{itemize} |
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 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
205 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
206 |
\frametitle{More use of main} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
207 |
For automating tests. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
208 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
209 |
if __name__ == '__main__': |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
210 |
for line in open('numbers.txt'): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
211 |
numbers = line.split() |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
212 |
x = int(numbers[0]) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
213 |
y = int(numbers[1]) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
214 |
result = (int(numbers[2])) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
215 |
assert gcd(x, y) == result |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
216 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
217 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
218 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
219 |
\section{Coding Style} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
220 |
\begin{frame}{Readability and Consistency} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
221 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
222 |
\item Readability Counts!\\Code is read more often than its written. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
223 |
\item Consistency! |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
224 |
\item Know when to be inconsistent. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
225 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
226 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
227 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
228 |
\begin{frame}[fragile] \frametitle{A question of good style} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
229 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
230 |
amount = 12.68 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
231 |
denom = 0.05 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
232 |
nCoins = round(amount/denom) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
233 |
rAmount = nCoins * denom |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
234 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
235 |
\pause |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
236 |
\begin{block}{Style Rule \#1} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
237 |
Naming is 80\% of programming |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
238 |
\end{block} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
239 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
240 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
241 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
242 |
\frametitle{Code Layout} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
243 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
244 |
\item Indentation |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
245 |
\item Tabs or Spaces?? |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
246 |
\item Maximum Line Length |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
247 |
\item Blank Lines |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
248 |
\item Encodings |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
249 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
250 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
251 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
252 |
\begin{frame}{Whitespaces in Expressions} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
253 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
254 |
\item When to use extraneous whitespaces?? |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
255 |
\item When to avoid extra whitespaces?? |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
256 |
\item Use one statement per line |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
257 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
258 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
259 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
260 |
\begin{frame}{Comments} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
261 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
262 |
\item No comments better than contradicting comments |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
263 |
\item Block comments |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
264 |
\item Inline comments |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
265 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
266 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
267 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
268 |
\begin{frame}{Docstrings} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
269 |
\begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
270 |
\item When to write docstrings? |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
271 |
\item Ending the docstrings |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
272 |
\item One liner docstrings |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
273 |
\end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
274 |
More information at PEP8: http://www.python.org/dev/peps/pep-0008/ |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
275 |
\inctime{5} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
276 |
\end{frame} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
277 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
278 |
\section{Debugging} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
279 |
\subsection{Errors and Exceptions} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
280 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
281 |
\frametitle{Errors} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
282 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
283 |
In []: while True print 'Hello world' |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
284 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
285 |
\pause |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
286 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
287 |
File "<stdin>", line 1, in ? |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
288 |
while True print 'Hello world' |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
289 |
^ |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
290 |
SyntaxError: invalid syntax |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
291 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
292 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
293 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
294 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
295 |
\frametitle{Exceptions} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
296 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
297 |
In []: print spam |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
298 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
299 |
\pause |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
300 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
301 |
Traceback (most recent call last): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
302 |
File "<stdin>", line 1, in <module> |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
303 |
NameError: name 'spam' is not defined |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
304 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
305 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
306 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
307 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
308 |
\frametitle{Exceptions} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
309 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
310 |
In []: 1 / 0 |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
311 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
312 |
\pause |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
313 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
314 |
Traceback (most recent call last): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
315 |
File "<stdin>", line 1, in <module> |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
316 |
ZeroDivisionError: integer division |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
317 |
or modulo by zero |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
318 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
319 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
320 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
321 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
322 |
\frametitle{Handling Exceptions} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
323 |
Python uses \typ{try} and \typ{except} clause. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
324 |
%%Revisiting the raw\_input |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
325 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
326 |
a = raw_input('Enter number(Q to quit):') |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
327 |
try: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
328 |
num = int(a) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
329 |
print num |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
330 |
except: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
331 |
if a == 'Q': |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
332 |
print 'Exiting...' |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
333 |
else: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
334 |
print 'Wrong input!' |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
335 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
336 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
337 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
338 |
\end{frame} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
339 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
340 |
%% \begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
341 |
%% \frametitle{Solving it with \typ{try} and \typ{except}} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
342 |
%% \vspace{-0.2in} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
343 |
%% \begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
344 |
%% highest = 0 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
345 |
%% for record in open('sslc1.txt'): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
346 |
%% fields = record.split(';') |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
347 |
%% try: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
348 |
%% total = 0 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
349 |
%% for score_str in fields[3:8]: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
350 |
%% score = int(score_str) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
351 |
%% total += score |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
352 |
%% if total > highest: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
353 |
%% highest = total |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
354 |
%% except: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
355 |
%% pass |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
356 |
%% print highest |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
357 |
%% \end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
358 |
%% \end{frame} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
359 |
\subsection{Strategy} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
360 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
361 |
\frametitle{Debugging effectively} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
362 |
\begin{itemize} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
239
diff
changeset
|
363 |
\item \typ{print} based strategy |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
364 |
\item Process: |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
365 |
\end{itemize} |
220
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
366 |
\begin{center} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
367 |
\pgfimage[interpolate=true,width=5cm,height=5cm]{DebugginDiagram.png} |
220
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
368 |
\end{center} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
369 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
370 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
371 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
372 |
\frametitle{Debugging effectively} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
373 |
\begin{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
374 |
\item Using \typ{\%debug} in IPython |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
375 |
\end{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
376 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
377 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
378 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
379 |
\frametitle{Debugging in IPython} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
380 |
\small |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
381 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
382 |
In []: import mymodule |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
383 |
In []: mymodule.test() |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
384 |
--------------------------------------------- |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
385 |
NameError Traceback (most recent call last) |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
386 |
<ipython console> in <module>() |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
387 |
mymodule.py in test() |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
388 |
1 def test(): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
389 |
----> 2 print spam |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
390 |
NameError: global name 'spam' is not defined |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
391 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
392 |
In []: %debug |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
393 |
> mymodule.py(2)test() |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
394 |
0 print spam |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
395 |
ipdb> |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
396 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
397 |
\inctime{15} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
398 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
399 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
400 |
\subsection{Exercise} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
401 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
402 |
\frametitle{Debugging: Exercise} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
403 |
\small |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
404 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
405 |
science = {} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
406 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
407 |
for record in open('sslc1.txt'): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
408 |
fields = record.split(';') |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
409 |
region_code = fields[0].strip() |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
410 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
411 |
score_str = fields[6].strip() |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
412 |
score = int(score_str) if score_str != 'AA' |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
413 |
else 0 |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
414 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
415 |
if score > 90: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
416 |
science[region_code] += 1 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
417 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
418 |
pie(science.values(), labels=science.keys()) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
419 |
savefig('science.png') |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
420 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
421 |
\inctime{10} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
422 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
423 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
424 |
%% \begin{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
425 |
%% \frametitle{Testing} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
426 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
427 |
%% \begin{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
428 |
%% \item Writing tests is really simple! |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
429 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
430 |
%% \item Using nose. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
431 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
432 |
%% \item Example! |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
433 |
%% \end{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
434 |
%% \end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
435 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
436 |
\section{Test Driven Approach} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
437 |
\begin{frame} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
438 |
\frametitle{Need for Testing!} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
439 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
440 |
\begin{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
441 |
\item Quality |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
442 |
\item Regression |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
443 |
\item Documentation |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
444 |
\end{itemize} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
445 |
%% \vspace*{0.25in} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
446 |
%% \emphbar{It is to assure that section of code is working as it is supposed to work} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
447 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
448 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
449 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
450 |
\frametitle{Example} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
451 |
\begin{block}{Problem Statement} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
452 |
Write a function to check whether a given input |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
453 |
string is a palindrome. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
454 |
\end{block} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
455 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
456 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
457 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
458 |
\frametitle{Function: palindrome.py} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
459 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
460 |
def is_palindrome(input_str): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
461 |
return input_str == input_str[::-1] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
462 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
463 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
464 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
465 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
466 |
\frametitle{Test for the palindrome: palindrome.py} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
467 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
468 |
def test_function_normal_words(): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
469 |
input = "noon" |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
470 |
assert is_palindrome(input) == True |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
471 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
472 |
if __name__ == "main'': |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
473 |
test_function_normal_words() |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
474 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
475 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
476 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
477 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
478 |
\frametitle{Running the tests.} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
479 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
480 |
$ nosetests palindrome.py |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
481 |
. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
482 |
---------------------------------------------- |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
483 |
Ran 1 test in 0.001s |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
484 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
485 |
OK |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
486 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
487 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
488 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
489 |
\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
490 |
\frametitle{Exercise: Including new tests.} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
491 |
\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
492 |
def test_function_ignore_cases_words(): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
493 |
input = "Noon" |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
494 |
assert is_palindrome(input) == True |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
495 |
\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
496 |
\vspace*{0.25in} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
497 |
Check\\ |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
498 |
\PythonCode{$ nosetests palindrome.py} \\ |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
499 |
\begin{block}{Task} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
500 |
Tweak the code to pass this test. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
501 |
\end{block} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
502 |
\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
503 |
|
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
504 |
%\begin{frame}[fragile] |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
505 |
% \frametitle{Lets write some test!} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
506 |
%\begin{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
507 |
%#for form of equation y=mx+c |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
508 |
%#given m and c for two equation, |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
509 |
%#finding the intersection point. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
510 |
%def intersect(m1,c1,m2,c2): |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
511 |
% x = (c2-c1)/(m1-m2) |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
512 |
% y = m1*x+c1 |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
513 |
% return (x,y) |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
514 |
%\end{lstlisting} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
515 |
% |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
516 |
%Create a simple test for this |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
517 |
% |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
518 |
%function which will make it fail. |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
519 |
% |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
520 |
%\inctime{15} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
521 |
%\end{frame} |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
522 |
% |
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
523 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
524 |
%% \begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
525 |
%% \frametitle{Exercise} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
526 |
%% Based on Euclid's algorithm: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
527 |
%% \begin{center} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
528 |
%% $gcd(a,b)=gcd(b,b\%a)$ |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
529 |
%% \end{center} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
530 |
%% gcd function can be written as: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
531 |
%% \begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
532 |
%% def gcd(a, b): |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
533 |
%% if a%b == 0: return b |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
534 |
%% return gcd(b, a%b) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
535 |
%% \end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
536 |
%% \vspace*{-0.15in} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
537 |
%% \begin{block}{Task} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
538 |
%% \begin{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
539 |
%% \item Write at least |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
540 |
%% two tests for above mentioned function. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
541 |
%% \item Write a non recursive implementation |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
542 |
%% of gcd(), and test it using already |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
543 |
%% written tests. |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
544 |
%% \end{itemize} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
545 |
%% \end{block} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
546 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
547 |
%% \inctime{15} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
548 |
%% \end{frame} |
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
549 |
|
220
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
550 |
\begin{frame} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
551 |
\frametitle{Summary} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
552 |
We have coverd: |
220
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
553 |
\begin{itemize} |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
554 |
\item Following and Resolving Error Messages. |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
555 |
\item Exceptions. |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
256
diff
changeset
|
556 |
\item Handling exceptions |
220
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
557 |
\item Approach for Debugging. |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
558 |
\item Writting and running tests. |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
559 |
\end{itemize} |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
560 |
\end{frame} |
15306dad3b81
Corrections to day1 Session1, day2 Session 3 and 4.
Shantanu <shantanu@fossee.in>
parents:
219
diff
changeset
|
561 |
|
219
f6725f6bee41
Session 4, Debugging and Testing.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
562 |
\end{document} |