day2/session4.tex
branchscipy2010
changeset 432 13e5d0e2cd40
parent 389 aa392117454f
child 433 af45c8da1d5d
equal deleted inserted replaced
431:9126059d6b37 432:13e5d0e2cd40
   200   \item \texttt{python gcd.py}
   200   \item \texttt{python gcd.py}
   201   \item \texttt{python lcm.py}
   201   \item \texttt{python lcm.py}
   202   \end{itemize}
   202   \end{itemize}
   203 \end{frame}
   203 \end{frame}
   204 
   204 
       
   205 
       
   206 \begin{frame}[fragile]
       
   207   \frametitle{Automating tests}
       
   208   \begin{lstlisting}
       
   209   
       
   210 def gcd(a, b):
       
   211     if a % b == 0:
       
   212         return b
       
   213     return gcd(b, a % b)
       
   214 
       
   215 if __name__ == '__main__':
       
   216     assert gcd(15, 65) == 5
       
   217     assert gcd(16, 76) == 4
       
   218 
       
   219   \end{lstlisting}  
       
   220 \end{frame}
       
   221 
   205 \begin{frame}[fragile]
   222 \begin{frame}[fragile]
   206   \frametitle{Automating tests}
   223   \frametitle{Automating tests}
   207   \begin{lstlisting}
   224   \begin{lstlisting}
   208 if __name__ == '__main__':
   225 if __name__ == '__main__':
   209     for line in open('numbers.txt'):
   226     for line in open('numbers.txt'):
   213         result = int(numbers[2])
   230         result = int(numbers[2])
   214         if gcd(x, y) != result:
   231         if gcd(x, y) != result:
   215             print "Failed gcd test
   232             print "Failed gcd test
   216                           for", x, y
   233                           for", x, y
   217   \end{lstlisting}  
   234   \end{lstlisting}  
       
   235 \end{frame}
       
   236 
       
   237 \begin{frame}[fragile]
       
   238   \frametitle{Python Test Packages}
       
   239     \begin{itemize}
       
   240 
       
   241 \item Python's \typ{unittest}:\linebreak
       
   242   \url{http://docs.python.org/library/unittest.html}
       
   243 \linebreak
       
   244 \item \typ{nose}:\linebreak
       
   245   \url{http://code.google.com/p/python-nose/}
       
   246   \end{itemize}
   218 \end{frame}
   247 \end{frame}
   219 
   248 
   220 \section{Coding Style}
   249 \section{Coding Style}
   221 \begin{frame}{Readability and Consistency}
   250 \begin{frame}{Readability and Consistency}
   222     \begin{itemize}
   251     \begin{itemize}