diff options
author | Kiran Isukapatla | 2012-01-25 13:13:53 +0530 |
---|---|---|
committer | Kiran Isukapatla | 2012-01-25 13:13:53 +0530 |
commit | 65f465db264ce040e534f8db6307bb224c9c8a4b (patch) | |
tree | ad6c086b5fa76f24cb2650846f9e619ffd49228b | |
parent | fcc74360086b4335e937817c1e56d2ea95fa35cd (diff) | |
parent | 2965bf37bb8fc6c6d672d6775612531e4a3074ba (diff) | |
download | sdes-stscripts-65f465db264ce040e534f8db6307bb224c9c8a4b.tar.gz sdes-stscripts-65f465db264ce040e534f8db6307bb224c9c8a4b.tar.bz2 sdes-stscripts-65f465db264ce040e534f8db6307bb224c9c8a4b.zip |
Merge branch 'master' of github.com:FOSSEE/sdes-stscripts
-rw-r--r-- | Latex/Latex2/latex_intro.tex | 131 | ||||
-rw-r--r-- | Latex/Latex2/latex_intro_script.rst | 118 | ||||
-rw-r--r-- | Latex/Latex3/latex_basics.tex | 1 | ||||
-rw-r--r-- | Latex/Latex3/latex_basics_and_structure_script.rst | 155 | ||||
-rw-r--r-- | Latex/Latex6/latex_math2beamer.tex | 449 | ||||
-rw-r--r-- | Latex/Latex6/latex_math_biblo_beamer_script.rst | 272 | ||||
-rw-r--r-- | Latex/images/iitb-logo.png | bin | 0 -> 13756 bytes | |||
-rw-r--r-- | TDD/getting_started_with_tdd/tdd1.tex (renamed from TDD/getting_started_with_tdd/slide.tex) | 262 | ||||
-rwxr-xr-x | TDD/getting_started_with_tdd/tdd1_script.rst | 205 | ||||
-rw-r--r-- | TDD/images/fossee-logo.png | bin | 0 -> 13587 bytes | |||
-rw-r--r-- | TDD/images/iitb-logo.png | bin | 0 -> 13756 bytes | |||
-rw-r--r-- | TDD/math_utils/fibonacci.py | 7 | ||||
-rw-r--r-- | TDD/math_utils/fibonacci_testcases.dat | 8 | ||||
-rw-r--r-- | TDD/math_utils/test_fibonacci.py | 27 | ||||
-rwxr-xr-x | TDD/two_column.py | 84 | ||||
-rw-r--r-- | TDD/using_python_framework_for_tdd/tdd2.tex (renamed from TDD/using_python_frameworks_for_TDD/slide.tex) | 232 | ||||
-rwxr-xr-x | TDD/using_python_framework_for_tdd/tdd2_script.rst | 198 |
17 files changed, 1704 insertions, 445 deletions
diff --git a/Latex/Latex2/latex_intro.tex b/Latex/Latex2/latex_intro.tex index 708467f..2bb0314 100644 --- a/Latex/Latex2/latex_intro.tex +++ b/Latex/Latex2/latex_intro.tex @@ -105,7 +105,7 @@ At the end of this tutorial, you will be able to, \end{frame} \begin{frame}[fragile] - \frametitle{Why \LaTeX?} + \frametitle{Why \LaTeX? \ldots} \begin{itemize} \item {\LaTeX} is a document based mark-up \item Mark-up $\rightarrow$ a system of annotating text, adding extra @@ -119,60 +119,67 @@ At the end of this tutorial, you will be able to, \begin{frame}[fragile] \frametitle{Advantages of using \LaTeX } \begin{itemize} - \item Easy availablity of professional templates. - \item Typesetting complex formulae in a convenient environment. - \item Can start typesetting with very little effort. - \item Presence of a lot of add-on packages. - \item Encourages creation of well structured texts. + \item Easy availablity of professional templates. + \item Typesetting complex formulae in a convenient environment. + \item Can start typesetting with very little effort. + \item Presence of a lot of add-on packages. + \item Encourages creation of well structured texts. \end{itemize} \end{frame} \begin{frame}[fragile] \frametitle{Disadvantages of using \LaTeX } \begin{itemize} - \item Designing whole new layout is difficult. + \item Designing whole new layout is difficult. + \item LaTeX is not a word processor. \end{itemize} \end{frame} \begin{frame}[fragile] \frametitle{\LaTeX \ input file format} \begin{itemize} - \item \LaTeX takes ASCII text file as input. - \item We can compile \LaTeX files into DVI,Postscript or PDF files. - \item \alert{Note:} \typ{latex} vs. \typ{pdflatex} + \item \LaTeX takes ASCII text file as input. + \item We can compile \LaTeX files into DVI,Postscript or PDF files. + \item \alert{Note:} \typ{latex} vs. \typ{pdflatex} \end{itemize} \end{frame} - - \begin{frame}[fragile] - \frametitle{Commands, Comments and Special Characters } + \frametitle{Commands,Comments\&Special Characters } \begin{itemize} - \item {\LaTeX} is case sensetive. - \item Commands begin with a \typ{\\} - \item Environments have a \typ{\\begin} and \typ{\\end} - \item Any content after the \typ{\\end\{document\}} is ignored + \item {\LaTeX} is case sensetive. + \item Commands begin with a \typ{\\} + \item Environments have a \typ{\\begin} and \typ{\\end} + \item Any content after the \typ{\\end\{document\}} is ignored \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Commands,Comments\&Special Characters \ldots} \begin{itemize} - \item Anything that follows a \typ{\%} symbol till end of the line - is a comment - \item Special characters (\typ{\~ \# \$ \^ \& \_ \{ \}}) are escaped by a - \typ{\\} - \item \typ{\\} symbol is inserted using \typ{\\textbackslash} - command + \item Anything that follows a \typ{\%} symbol till end of the line + is a comment + \item Special characters (\typ{\~ \# \$ \^ \& \_ \{ \}}) are escaped by a + \typ{\\} + \item \typ{\\} symbol is inserted using \typ{\\textbackslash} + command + %\item \textbackslash newline or \textbackslash \textbackslash\ is used to insert newlines. + \item \typ{\\newline} or \typ{\\\\} is used to insert newlines. \end{itemize} \end{frame} \begin{frame}[fragile] \frametitle{Typesetting a minimal document} Write the sample code into the file \typ{temp.tex} - \begin{verbatim} - \documentclass{article} - \title{My First LaTeX Document} - \begin{document} - Hello world! - \end{document} - \end{verbatim} + \vspace{8pt} + {\tiny + \begin{verbatim} + \documentclass{article} + \begin{document} + SciPy is open-source software for mathematics, science, and engineering. + \end{document} + \end{verbatim} + } \end{frame} \begin{frame}[fragile] @@ -185,7 +192,10 @@ At the end of this tutorial, you will be able to, \begin{frame}[fragile] \frametitle{Compiling to PDF } \begin{center} - \alert{pdflatex temp.tex} + \alert{pdflatex temp.tex} + \end{center} + \begin{center} + \em Note: Throughout this course, we shall use pdflatex to compile our documents. \end{center} \end{frame} @@ -195,57 +205,60 @@ At the end of this tutorial, you will be able to, In this tutorial, we have learnt, \begin{itemize} -\item About LaTeX. -\item why we prefer LaTeX. -\item about the advantages and disadvantages of typesetting documents using the LaTeX approach. -\item A description, of a typical work flow; which uses LaTeX to typeset documents. -\item The ability to recognize and differentiate between LaTeX commands, LaTeXcomments and special characters, spacing and actual document content. -\item Created and compiled a very simple LaTeX document. + \item About LaTeX. + \item why we prefer LaTeX. + \item about the advantages and disadvantages of typesetting documents using the LaTeX approach. + \item A description, of a typical work flow; which uses LaTeX to typeset documents. + \item The ability to recognize and differentiate between LaTeX commands, LaTeXcomments and special characters, spacing and actual document content. + \item Created and compiled a very simple LaTeX document. \end{itemize} \end{frame} + + \begin{frame}[fragile] \frametitle{Evaluation} \label{sec-9} - - \begin{enumerate} -\item Convert the temp.dvi created during the course of this tutorial to temp\_1.ps using the dvips command. Verify that the two files indeed look the same. -\vspace{8pt} -\item Convert the temp.dvi created during the course of this tutorial to temp\_1.pdf using the dvipdfm command. Verify that the two files indeed look the + \item Convert the temp.dvi created during the course of this tutorial to temp\_1.ps using the dvips command. Verify that the two files indeed look the same. + \vspace{8pt} + \item Convert the temp.dvi created during the course of this tutorial to temp\_1.pdf using the dvipdfm command. Verify that the two files indeed look the same. \end{enumerate} \end{frame} -\begin{frame} - +\begin{frame} \frametitle{Solutions} \label{sec-10} \begin{enumerate} -\item We can use the following command to convert temp.dvi to temp\_1.ps\\ -\begin{center} -dvips -o temp\_1.ps temp.dvi -\end{center} -\vspace{15pt} -\item We can use the following command to convert temp.dvi to temp\_1.pdf\\ -\begin{center} -dvipdfm \-o temp\_1.pdf temp.dvi -\end{center} + \item We can use the following command to convert temp.dvi to temp\_1.ps\\ + \begin{block}{} + \begin{center} + dvips -o temp\_1.ps temp.dvi + \end{center} + \end{block} + \vspace{15pt} + \item We can use the following command to convert temp.dvi to temp\_1.pdf\\ + \begin{block}{} + \begin{center} + dvipdfm -o temp\_1.pdf temp.dvi + \end{center} + \end{block} \end{enumerate} \end{frame} -\begin{frame} + +\begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + \textcolor{blue}{\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} - For more Information, visit our website\\ - \url{http://fossee.in/} + For more Information, visit our website\\ + \url{http://fossee.in/} \end{center} \end{block} \end{frame} -\end{document} - +\end{document} diff --git a/Latex/Latex2/latex_intro_script.rst b/Latex/Latex2/latex_intro_script.rst index bb3b0ad..390f0eb 100644 --- a/Latex/Latex2/latex_intro_script.rst +++ b/Latex/Latex2/latex_intro_script.rst @@ -75,15 +75,16 @@ LaTeX began as TeX, a computer program originally created by Donald E. Knuth. Its was designed mainly to aid typesetting of text and mathematical formulae. -LaTeX is a document preparation system for high quality type -setting. It is based on the TeX typesetting language or certain -extensions. +LaTeX is a typesetting program that produces excellently typeset documents. +Typesetting is placing text onto a page with all the style formatting defined, +so that content looks as intended. It is extensively used for producing high +quality scientific and mathematical documents. It may also be used for +producing other kinds of documents, ranging from simple one page articles to +complete books. LaTeX is pronounced Lah-tech or Lay-tec. TeX is pronounced Tech. TeX is also the first syllable in the Greek word for technology. -LaTeX allows authors to typeset and print their content at the highest -typographical quality, using predefined, professional layouts. .. L5 @@ -128,6 +129,8 @@ of the document. Some of the disadvantages of using LaTeX approach to typesetting is (1) Designing a whole new layout is difficult. +(2) LaTeX is not a word processor, that is the document author is not expected +to worry about presentation details like the size of font, for example. .. L8 @@ -154,66 +157,95 @@ The resultant PDF files can be viewed using standard tools on most platforms .. R9 -LaTeX, like most utilities in Linux is case sensitive. Commands begin with a -backslash.LaTeX environments have a begin and end marker. Any content after -\end{document} is ignored. +LaTeX, like most utilities in Linux, LaTeX is case sensitive. Commands begin +with a backslash.LaTeX environments have a begin and end marker. The begin and +end document commands, mark the beginning and the end of the content of the +LaTeX document. The text in between the begin and end commands is typeset in +the output document.Any content after \end{document} is ignored. The type of +document that is being currently typeset in LaTex, is identified with the +documentclass command. LaTeX then, typesets the document accordingly. -Anything that follows a percentage sign (%) till the end of that line is a -comment. Special characters like tilde or hash,etc have to be escaped by a -backslash. If you have to insert a backslash into a LaTeX output file, you have -to use the LaTeX command \textbackslash. +All the commands in LaTeX begin with a \. An environment begins with a begin +command and ends with an end command. -Normally LaTeX automatically spaces the given input optimally. But, sometimes we -have to insert manual line breaks. This is achieved using the \\ command. +So, as expected LaTeX ignores anything that is written after the \end{document} +command. Essentially, anything written after the \end{document} command turns +out to be a comment. But, how do we write comments with in the document. % is +the character to indicate comments. Anything written after a % symbol in a +line, is ignored. -We can also start a new paragraph using an empty line. +.. L10 -It must be noted that multiple spaces/empty lines are automatically compressed -to a single space/line. -.. L10 +.. R10 + +But what if we wanted to insert the % symbol in the document? We can do so by +escaping it with a \ (backslash). % is one of the many special characters in +LaTeX. The others are, ~ # $ ^ & _ { } \. All of them, except the \ itself, can +be inserted by escaping it with a \. To insert a \ in our document, we use the +command \textbackslash. + +What would happen if we escape a \ with a \? +A double backslash is actually another command. It inserts a new line in the +typeset document. Normally LaTeX automatically spaces the given input optimally. +But, sometimes we have to insert manual line breaks. The \\ command or \newline +command is used to insert a newline in the output document. Line breaks in the +input document, do not translate into line breaks in the output document. A +single line break in the input document, doesn't cause any change in the output. + +A single empty line causes a change in paragraphs in the output. (Multiple +empty lines are equivalent to a single empty line.) Similarly, multiple spaces +are treated as a single space. + +.. L11 {{{ Show slide with exercise 1 }}} -.. R10 +.. R11 Now, we try to create a simple LaTeX document. Pause the tutorial and type the content shown on the screen in a text editor. Save the file as temp.tex -.. L10 +.. L12 {{{continue from paused state}}} -.. R10 +.. R12 Now we compile the commands in the LaTeX input file that is, temp.tex into a -typeset file. -The first alternative is to compile LaTeX input file into a DVI file. We use -the latex command for this purpose. -For compiling the LaTeX input file temp.tex into a DVI file, we use the -following command +typeset file. + +The first alternative is to compile LaTeX input file into a DVI +file. We use the latex command for this purpose. For compiling the LaTeX input +file temp.tex into a DVI file, we use the following command + latex temp.tex. -The output file would be temp.dvi. -On Gnu/Linux use a program like xdvi to view the output file. -.. L11 +The output file would be temp.dvi.On Gnu/Linux use a program like xdvi to view +the output file. + +.. L13 -.. R11 +.. R13 The other alternative is to create PDF files from LaTeX input files. -We use the pdflatex command for this purpose. -For compiling the LaTeX input file temp.tex into a PDF file, we use the -following command +We use the pdflatex command for this purpose. For compiling the LaTeX input +file temp.tex into a PDF file, we use the following command + pdflatex temp.tex -The output file would be temp.pdf -On Gnu/Linux use a program like evince to view the output file. -.. L12 +The output file would be temp.pdf.On Gnu/Linux use a program like evince to +view the output file. + +Please note that, throughout this course we shall be using pdflatex to compile +our documents. + +.. L14 {{{ Show summary slide }}} -.. R12 +.. R14 This brings us to the end of this tutorial. In this tutorial, we have learnt @@ -227,11 +259,11 @@ This brings us to the end of this tutorial. In this tutorial, we have learnt .. comments and special characters, spacing and actual document content. .. #. Created and compiled a very simple LaTeX document. -.. L13 +.. L15 {{{Show self assessment questions slide}}} -.. R13 +.. R15 Here are some self assessment questions for you to solve @@ -242,11 +274,11 @@ using the dvips command. Verify that the two files indeed look the same. temp_1.pdf using the dvipdfm command. Verify that the two files indeed look the same. -.. L14 +.. L16 {{{Show self assessment questions slide}}} -.. R14 +.. R16 And the answers, @@ -256,11 +288,11 @@ dvips -o temp_1.ps temp.dvi 2. We can use the following command to convert temp.dvi to temp_1.pdf dvipdfm -o temp_1.pdf temp.dvi -.. L15 +.. L17 {{{ Show the thank you slide }}} -.. R15 +.. R17 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/Latex/Latex3/latex_basics.tex b/Latex/Latex3/latex_basics.tex index a93d2ad..04e7968 100644 --- a/Latex/Latex3/latex_basics.tex +++ b/Latex/Latex3/latex_basics.tex @@ -296,6 +296,7 @@ beginning of the document and the appendix at the end. \frametitle{\typ{Excercise 1: Solution}} \begin{center} Note: File needs to be compiled twice + TODO: Please uncomment actual example and recompile \end{center} {\tiny \begin{center} diff --git a/Latex/Latex3/latex_basics_and_structure_script.rst b/Latex/Latex3/latex_basics_and_structure_script.rst index 99bede8..968a4ee 100644 --- a/Latex/Latex3/latex_basics_and_structure_script.rst +++ b/Latex/Latex3/latex_basics_and_structure_script.rst @@ -33,8 +33,8 @@ team along with the logo of MHRD }}} .. R1 -Hello friends and welcome to the tutorial on Basics of LaTeX and its document -structure. +Hello friends and welcome to the tutorial titled "Basics of LaTeX and its +document structure". .. L2 @@ -63,11 +63,6 @@ LaTeX and suggest you to complete the tutorial titled "Introduction to LaTeX". .. L4 -{{{ Basic Structure of a LaTeX document }}} -\documentclass{article} -\begin{document} -SAMPLE TEXT -\end{document} .. R4 @@ -76,13 +71,20 @@ single alpha-numeric character, for example. When done so, the resulting document could be described as the shortest possible LaTeX input document, that creates an output file. It consists of 3 LaTeX commands and one line/character of text. + +In our minimal example, document is an environment. Only the text enclosed by +the begin and end commands is effected by the environment. The part of the file +before the \begin{document} command is called the preamble, and is used to +"configure" the LaTeX typesetter and change various parameters for typesetting. + This is processed by a TeX processor that generates an output file. Now, we begin to look into each line in the example in more detail. + + The first line reads .. L5 -\documentclass{article} .. R5 @@ -90,7 +92,6 @@ which more generally can be written as .. L6 -\documentclass [parameters] {DocumentClass} .. R6 @@ -101,7 +102,6 @@ the document, paper size, two sided or single sided printing, etc. .. L7 -\documentclass[12pt,a4paper,draft]{report} .. R7 @@ -116,7 +116,6 @@ with a square in the margin .. L8 -\usepackage[options]{...} .. R8 @@ -128,13 +127,6 @@ command for accessing package documentation. .. L9 :: -\documentclass{article} -\title{My First LaTeX Document} -\author{Harish} -\date -\begin{document} -Hello world! -\end{document} .. R9 @@ -142,17 +134,12 @@ We add the LaTeX commands, that specify the title and the author of the document. When we compile the document shown to an output file and view it we notice that output is, as seen no different from not adding the fields of title and author. We need to add another command to actually show the title author -and date in the output document. We add the command in the following example. +and date in the output document. The part of the file before the +\begin{document} command is called the preamble, and is used to "configure" the +LaTeX typesetter and change various parameters for typesetting. .. L10 -\documentclass{article} -\title{My First LaTeX Document} -\author{Harish} -\begin{document} -\maketitle -Hello world! -\end{document} .. R10 @@ -162,16 +149,6 @@ date is used else today's date is used. .. L11 -\documentclass{article} -\title{My First LaTeX Document} -\author{Harish} -\begin{document} -\maketitle -Hello world! -\begin{abstract} -An Example Abstract -\end{abstract} -\end{document} .. R11 @@ -182,24 +159,6 @@ not book .. L12 -\documentclass{article} -\title{My First LaTeX Document} -\author{Harish} -\begin{document} -\maketitle -Hello world! -\begin{abstract} -An Example Abstract -\end{abstract} -\section{Numbered Section 1} -Section1 Text -\section{Numbered Section 2} -Section2 Text -\section*{Unnumbered Section 1} -Section3 Text -\section*{Unnumbered Section 2} -Section4 Text -\end{document} .. R12 @@ -213,28 +172,6 @@ section or chapter numbering use the part command. .. L13 -\documentclass{book} -\title{My first Book} -\author{Harish} -\date{31-February-2012} -\begin{document} -\maketitle -\chapter{My First Chapter} -Main -\section{Section1} -Section 1 Text -\subsubsection{My First Subsection} -Numbered-Section 1's Subsection Text -\section{Section2} -Numbered-Section 2 Text -\section*{Section3} -First un-numbered Section Text -\section*{Section4} -Second un-numbered Section Text -\chapter{So We say goodbye} -Thank you for reading dear reader -\end{document} - .. R13 Longer documents can use report or book class. We can add a new chapter using @@ -243,7 +180,6 @@ file shown in the slide we notice that subsections are not numbered. .. L14 -\setcounter{secnumdepth}{3} .. R14 We can change this behavior with the command setcounter , calling it as shown @@ -251,7 +187,6 @@ in the slide. .. L15 -\appendix .. R15 @@ -285,10 +220,35 @@ where intro is the text that you want to appear in the Table of contents. .. L18 -{{{ Show summary slide }}} +{{{ Show slide with exercise 1 }}} .. R18 +Write a LaTeX script that creates a document of type article, which contains both +a table of content and an appendix. The table of content should be at the +beginning of the document and the appendix at the end. + +The book should contain two chapters, with the first chapter containing two +numbered and two un-numbered sections. The first un-numbered section should be +present in the table of content. + +Please pause the tutorial and check back for a possible solution + +.. L19 + +{{{continue from paused state}}} +{{{ Show slide with solution to exercise 1 }}} + +.. R19 + +This slide on screen shows a possible valid solution to the given exercise. + +.. L20 + +{{{ Show summary slide }}} + +.. R20 + This brings us to the end of this tutorial. In this tutorial, we have, .. 1. Gained an understanding of the basic structure of a LaTeX document, its @@ -300,42 +260,27 @@ This brings us to the end of this tutorial. In this tutorial, we have, .. #. Created an appendix in a LaTeX document. .. #. Created a table of content in a LaTeX document. -.. L19 +.. L21 {{{Show self assessment questions slide}}} -.. R19 +.. R21 Here are some self assessment questions for you to solve 1. Is the LaTeX code given below a valid input file (File compiles successfully and produces the intended result, that is to produce a book with two chapters and an appendix. -\begin{verbatim} -\documentclass{book} -\title{My first Book} -\author{Harish} -\date{31-February-2012} -\begin{document} -\maketitle -\chapter{My First Chapter} -Main -\chapter{So We say goodbye} -Thank you for reading dear reader -\appendix -\section{First Appendix} -\end{document} -\end{verbatim} - - 2. Does making the subsections placed at any arbitrary level, get numbered by -default using the appropriate setcounter command with secnumdepth parameter -make the subsections appear automatically in the table of content ?? -.. L20 + 2. subsection command can be placed at any arbitrary level. If they get numbered +by default using the appropriate setcounter command and secnumdepth parameter, +do they automatically appear in the table of content ?? + +.. L22 {{{Show self assessment questions slide}}} -.. R20 +.. R22 And the answers, @@ -343,14 +288,14 @@ And the answers, we expected. This is mainly because we are trying to use the section command to create sections in the appendix, for a document whose type is given as a book. -2. No The \tableofcontents command normally shows only numbered section +2. No, the \tableofcontents command normally shows only numbered section headings, and only down to the level defined by the tocdepth counter. -.. L21 +.. L23 {{{ Show the thankyou slide }}} -.. R21 +.. R23 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/Latex/Latex6/latex_math2beamer.tex b/Latex/Latex6/latex_math2beamer.tex new file mode 100644 index 0000000..e0fa3e4 --- /dev/null +++ b/Latex/Latex6/latex_math2beamer.tex @@ -0,0 +1,449 @@ +\documentclass{beamer} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{fixltx2e} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} +\usepackage{amssymb} +\usepackage{hyperref} +\tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{ + language=TeX, + basicstyle=\ttfamily\bfseries, + commentstyle=\ttfamily\color{blue}, + stringstyle=\ttfamily\color{orange}, + showstringspaces=false, + breaklines=true, + postbreak = \space\dots +} + + +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } +\title [{\LaTeX} for mathematics \& beyond] {{\LaTeX} for mathmatical formulae, bibliography and presentations} +\author {FOSSEE} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DOCUMENT STARTS +\begin{document} + + +\begin{frame} + \begin{center} + \vspace{12pt} + \textcolor{blue}{\huge {\LaTeX} for mathmatical formulae, bibliography and presentations} + \end{center} + \vspace{18pt} + \begin{center} + \vspace{10pt} + \includegraphics[scale=0.95]{../images/fossee-logo.png}\\ + \vspace{5pt} + \scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ + \scriptsize Funded by National Mission on Education through ICT\\ + \scriptsize MHRD,Govt. of India\\ + \includegraphics[scale=0.30]{../images/iitb-logo.png}\\ + \end{center} +\end{frame} + +\begin{frame} + \frametitle{Objectives} + \label{sec-2} + At the end of this tutorial, you will be able to, + \begin{itemize} + \item Write and typeset simple mathematical formulae in LaTeX. + \item Write bibliography for a LaTeX document. + \item Make presentations in LaTeX, using beamer. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\LaTeX\ \&\ Mathematics : An Introduction} + \begin{itemize} + \item Math is enclosed in a pair of \lstinline{$} signs or %%$ + \lstinline+\( \)+ + \item Used for typesetting inline Math. + \item \lstinline+\usepackage{amsmath}+ + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Matrices} + \begin{itemize} + \item \lstinline+\bmatrix+ is used to typeset the matrix A + \item It works similar to the tabular environment + \item \lstinline+&+ for demarcating columns + \item \lstinline+\\+ for demarcating rows + \item Other matrix environments + \begin{table} + \center + \begin{tabular}{|l|l|} + \hline + Matrix Type & Border Decoration \\ + \hline + \lstinline+matrix+ & none\\ + \hline + \lstinline+pmatrix+ & \lstinline+(+\\ + \hline + \lstinline+Bmatrix+ & \lstinline+{+\\ + \hline + \lstinline+vmatrix+ & \lstinline+|+\\ + \hline + \lstinline+Vmatrix+ & \lstinline+||+\\ + \hline + \end{tabular} + \end{table} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Matrices \ldots} + \tiny{ + \begin{verbatim} + \documentclass{article} + \usepackage {amsmath} + \begin{document} + Welcome to the world of matrices\\ + $ + \begin{bmatrix} + a & b \\ + c & d \\ + \end{bmatrix} + \begin{vmatrix} + e & f \\ + g & h + \end{vmatrix} + $ + \begin{equation} + \begin{Vmatrix} + i & j & k & l + \end{Vmatrix} + \end{equation} + \begin{equation} + \begin{pmatrix} + m & n & o & p + \end{pmatrix} + \end{equation} + \end{document} + \end{verbatim} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{Superscripts \& Subscripts} + \begin{itemize} + \item \lstinline+^+ for superscripts + \item \lstinline+_+ for subscripts + \item Enclose multiple characters in \lstinline+{ }+ + \end{itemize} + \begin{verbatim} + \documentclass{article} + \begin{document} + $ i^j $ $k_l$ \\ + $ {{{a^b}^c}^d} \\ {z_{y_{x_w}}} $ \\ + \end{document} + \end{verbatim} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Summation \& integration} + \begin{itemize} + \item \lstinline+\sum+ command gives the summation symbol + \item The upper and lower limits are specified using the + \lstinline+^+ and \lstinline+_+ symbols. + \item Similarly the integral symbol is obtained using + \lstinline+\int+ command. + \end{itemize} + \tiny{ + \begin{verbatim} + \documentclass{article} + \usepackage {amsmath} + \begin{document} + We note that \\ + (a) Summations in text style \\ + $ \sum_{1}^{10} a $ \\ + (b) Summations in display style \\ + \begin{equation} + \sum_{1}^{10} a + \end{equation} + look a lot different when rendered.\\ + A similar analogy holds true for integrals, when using \\ + $ \int_{1}^{10} a $ \\ + and \\ + \begin{equation} + \int_{1}^{10} a + \end{equation} + \end{document} + \end{verbatim} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{\lstinline+displayed+ math} + \begin{itemize} + \item Display equations are the other type of displaying math + \item \LaTeX~ or \lstinline+amsmath+ has a number of environments + for ``displaying'' equations, with minor differences. + \item In general, enclose math in \lstinline+\[+ and \lstinline+\]+ + to get displayed math. + \item \lstinline+\begin{equation*}+ is equivalent to this. + \item Use \lstinline+\begin{equation}+ to get numbered + equations. %%\end{equation} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Groups of equations} + \begin{itemize} + \item The \lstinline+equation+ environment allows typesetting of + just 1 equation. + \item \lstinline+eqnarray+ allows typesetting of multiple equations + \item It is similar to the \lstinline+table+ environment + \item The parts of the equation that need to be aligned are + indicated using \& symbol. + \item Each equation is separated by a \lstinline+\newline+ command + \end{itemize} + \tiny{ + \begin{verbatim} + \documentclass{article} + \begin{document} + \begin{eqnarray} + a & = & b + c +d\\ + & = & d + e + \end{eqnarray} + \end{document} + \end{verbatim} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{Fractions \& Surds} + \begin{itemize} + \item Fractions are typeset using \lstinline+\frac+ command + \item \lstinline+\frac{numerator}{denominator}+ is typeset as + $\frac{numerator}{denominator}$ + \item Surds are typeset using \lstinline+\sqrt[n]+ command + \end{itemize} + \tiny{ + \begin{verbatim} + \documentclass{article} + \begin{document} + The glass is $\frac{3}{4}$ full.\\ + \begin{equation} + \frac{3}{4} + \end{equation} + We now move on to square root and cube root of 2 + \begin{eqnarray} + \sqrt{2}\\ + \sqrt[3]{2} + \end{eqnarray} + \end{document} + \end{verbatim} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{Greek characters \& Spacing} + \begin{itemize} + \item Typesetting Greek characters is simple + \item \lstinline+\alpha+, \lstinline+\beta+, \lstinline+\gamma+, + \ldots \lstinline+\Alpha+, \lstinline+\Beta+, \lstinline+\Gamma+ + \ldots + \item To get additional spacing in Math environments --- + \begin{center} + \begin{tabular}{|l|l|l|} + \hline + Abbrev. & Spelled out & Example \\ + \hline + \lstinline+\,+ & \lstinline+\thinspace+ & $A\,B$ \\ + \hline + \lstinline+\:+ & \lstinline+\medspace+ & $A\:B$ \\ + \hline + \lstinline+\;+ & \lstinline+\thickspace+ & $A\;B$ \\ + \hline + & \lstinline+\quad+ & $A \quad B$ \\ + \hline + & \lstinline+\qquad+ & $A \qquad B$ \\ + \hline + \lstinline+\!+ & \lstinline+\negthinspace+ & $A!B$ \\ + \hline + & \lstinline+\negmedspace+ & $A \negmedspace B$ \\ + \hline + & \lstinline+\negthickspace+ & $A \negthickspace B$ \\ + \hline + \end{tabular} + \end{center} + \end{itemize} +\end{frame} + +\section{Bibliography} +\begin{frame}[fragile] + \frametitle{Bibliography} + \begin{itemize} + \scriptsize{ + \item \lstinline+thebibliography+ environment provides a clean and + simple way to add a bibliography to \LaTeX documents. + \item \lstinline+\begin{thebibliography}+ takes as argument the + maximum width of the label that references will have. + \item Each item of the Bibliography is similar to an item in a + list. + \item \lstinline+\bibitem[label]{name}+ followed by the actual + reference info. + \item label replaces auto enumeration numbers + \item \lstinline+\cite{name}+ is used to \lstinline+cite+ the + \lstinline+bibitem+ + \item You will need to compile twice. + } + \end{itemize} + \tiny{ + \begin{verbatim} + \documentclass{article} + \begin{document} + Official Sources~\cite{Official} + indicate that \ldots + \begin{thebibliography}{99} + \bibitem{Official} H.~Partl: + \emph{Dept of Defence Notfication}, + Volume~9, Issue~1 (1988) + \end{thebibliography} + \end{document} + \end{verbatim} + } +\end{frame} + +\section{Presentations - Beamer} +\begin{frame}[fragile] + \frametitle{Beamer} + \begin{itemize} + \item Use beamer since your report's \LaTeX~ would be re-usable. + \item It is recommended to start with one of the beamer templates. + \item \lstinline+\documentclass{beamer}+ tells \LaTeX~ to start a + beamer presentation. + \item A beamer document is very similar to any other \LaTeX~ + document except that content is divided into slides. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Beamer \ldots} + \begin{itemize} + \item \lstinline+\usetheme+ command is used to specify the theme of the + presentation. + \item \lstinline+\usecolortheme+ command is used to specify the color + theme. + \item The content of a slide is enclosed within + \lstinline+\begin{frame}{Title}{Subtitle}+ and + \lstinline+\end{frame}+ + \item If the slide contains \lstinline+verbatim+ + \lstinline+lstlisting+ environments, the \lstinline+\begin{frame}+ + should be passed an additional argument \lstinline+[fragile]+ + \item Overlays can be achieved using the \lstinline+\pause+ + command. + \item To achieve more with beamer, it is highly recommended that you + look at the \texttt{beameruserguide} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Beamer \ldots} + \tiny{ + \begin{verbatim} + \documentclass{beamer} + \usetheme{Warsaw} + \useoutertheme{infolines} + \title{Make a LaTeX presentation using Beamer} + \author{FOSSEE} + \institute{IIT Bombay} + \date{} + \begin{document} + \begin{frame} + \titlepage + \end{frame} + \begin{frame}{Introduction} + This is a short introduction to Beamer class. + \end{frame} + \begin{frame}[fragile] + \frametitle{Introduction to \LaTeX} + Most non trivial \LaTeX documents begins with the following or similar lines + \begin{itemize} + \pause \item \backslash documentclass{foo} + \pause \item \backslash \usepackage{bar} + \end{itemize} + \end{frame} + \end{document} + \end{verbatim} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{\typ{Summary}} + \label{sec-8} + In this tutorial, we have, + \begin{itemize} + \item Written and typeset simple math formulae in LaTeX. + \item Written bibliography for a LaTeX document. + \item Made a sample presentations in LaTeX, using beamer. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\typ{Evaluation}} + \label{sec-9} + {\small + \begin{enumerate} + \item What is the function of useoutertheme command used in the beamer +presentation example shown before ?? what happens when you comment out or +remove the line. + \item Are commands like $ \backslash alpha, \backslash beta, etc $ commands provided by amsmath package ? + \end{enumerate} + } +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{Solutions}} +\label{sec-10} +\begin{enumerate} + \item The outertheme command in beamer is used to customize the amount of +header/footer information shown in each slide. In the example shown below the +useoutertheme command with infolines argument automatically adds more +information to the footer like page number, author and institute,etc. + \item No, commands like alpha, beta, etc are not commands provided by the amsmath +package. +\end{enumerate} +\end{frame} + +\begin{frame} + \begin{block}{} + \begin{center} + \textcolor{blue}{\Large THANK YOU!} + \end{center} + \end{block} + \begin{block}{} + \begin{center} + For more Information, visit our website\\ + \url{http://fossee.in/} + \end{center} + \end{block} +\end{frame} + +\end{document} + + diff --git a/Latex/Latex6/latex_math_biblo_beamer_script.rst b/Latex/Latex6/latex_math_biblo_beamer_script.rst new file mode 100644 index 0000000..ab9e27d --- /dev/null +++ b/Latex/Latex6/latex_math_biblo_beamer_script.rst @@ -0,0 +1,272 @@ +.. Objectives +.. ---------- + +.. By the end of this tutorial, you will be able to + +.. 1. Write and typeset simple mathematical formulae in LaTeX. +.. #. Write bibliography for a LaTeX document. +.. #. Make presentations in LaTeX, using beamer. + +.. Prerequisites +.. ------------- + +.. 1. latex_intro +.. Author : Harish Badrinath < harish [at] fossee [dot] in > + Internal Reviewer : + External Reviewer : + Langauge Reviewer : + Checklist OK? : <put date stamp here, if OK> + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and welcome to the tutorial on basics of typesetting mathematical +formulae, bibliography and presentations, using LaTeX. + +.. L2 + +{{{ Show the objectives slide }}} + +.. R2 + +.. By the end of this tutorial, you will be able to + +.. 1. Write and typeset simple mathematical formulae in LaTeX. +.. #. Write bibliography for a LaTeX document. +.. #. Make presentations in LaTeX, using beamer. + +.. L3 + +{{{ Switch to the pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you complete the tutorials titled +"Introduction to LaTeX","Basics of LaTeX and its document structure","Basics of +LaTeX and its documents structure" and "Typesetting LaTeX text". + +.. L4 + +.. R4 + +Math formulae can be embedded in two ways. One is inline, and the other way is + to enclose them in a dedicated environment as and when required. +The first method is also called text style and second method is also called +displayed style. + +In-lining is done by enclosing the required command and text withing two dollar +signs or between an backslash opening bracket and backslash closing bracket. + +The most common LaTeX environment used to typeset mathematical formulae is +from equation family. Its use is given in more detail, further in the tutorial. + +It must be noted that amsmath is included in the base distribution of LaTex, in +most recent versions. + +.. L5 + + +.. R5 + +An environment like bmatrix for example, is used to render a matrix. The syntax +for specifying a matrix is similar to that used in the tabular environment. The +& symbol is used for demarcating columns and \\ is used to demarcate rows. + +Various types of matrix have different/no type of border decorations. A table + +showing the data is being shown on the screen. The matrix and its allied +environments are defined by the amsmath package. + +.. L6 + + +.. R6 + +The screen shows the an example, that renders different types of matrices using +LaTeX. +It also shows the two ways in which mathmatical formulae can be embedded into +LaTeX documents. The second method of embedding mathamtical formula will be +explained in detail, later in the tutorial. Please pause the tutorial and go through the example shown on the screen. + +.. L7 + +{{{continue from paused state}}} + +.. R7 + +Charet is used to render text in superscript, while underscore is used to +render text in subscript. +Multiple characters and ambiguity is resolved by grouping them using opening +and closing curly brackets. + +.. L8 + + +.. R8 + +sum and int commands are used to show summation and integration in the rendered +document respectively. We can specify the upper and lower limits for these +commands using charet and underscore respectively. + +.. L9 + + +.. R9 + +As mention earlier, we can display mathematical formulas in either one of two +ways. The first was mentioned earlier, now we use the equation environment +to render mathematical formulae, which are numbered. The equation star +environment is used to render unnumbered equations. + +Backslash and opening square bracket and its counterpart the backslash +closing square bracket is a short hand for \begin equation star environment. +There is no similar shorthand for equation environment (i.e, the numbered +equation environment). + +.. L10 + + +.. R10 + +The equation and its allied environments allows only one equation at a time. +To come around this requirement, we can use eqnarray environment to group +multiple equations. + +The eqnarray environment provides additional convenience like auto alignment +using the ampersand command, auto numbering of equations, etc. + +Each distinct equation in the group needs to be separated by a newline command. + +.. L11 + + +.. R11 + +We typeset fractions using the frac command. We can also render surds using +sqrt command. +Please note that there is a special command dfrac, that can be used to render +fractions as if its placed in display mode and is meant to be used even in +inline mode. + +.. L12 + +.. R12 + +There are appropriately named commands for inserting greek alphabets. +There are also commands for inserting spaces as required and is intended to be +used mainly for mathematical formulae. The relevant commands are shown on the +screen, in the table. + +.. L13 + +.. R13 + +We can easily produce a bibliography with the bibliography environment. +Each entry is added in the bibliography environment with the bibitem command. +The marker used in the bibitem command is used to cite the source at the place +required. +If you do not use the label parameter to manually specify an index, the entries +get enumerated automatically. Please pause the tutorial and go through the +example shown on the screen. + +.. L14 + +{{{continue from paused state}}} + +.. R14 + +It is highly recommended to use beamer to create presentations, especially when +you are using LaTeX for your report. This is mainly because, it would be really +easy to reuse the original content for your presentation. + +We begin a beamer presentation with the command document with an argument +with the value beamer. This tells LaTeX to start a beamer presentation. + +A beamer document is very similar to other LaTeX documents, with the exception +that content is divided into slides. + +.. L15 + +.. R15 + +The usetheme command is used to specify the theme to be used for the current +presentation. The usecolor theme command is used to specify the color theme to +be used in the current presentation. The contents of a slide are enclosed +within the begin frame and end frame environment. + +If we have to use the the verbatim environment inside a slide, then we have to +pass an additional argument to begin frame, which is fragile. + +Overlays and simple animation can be achieved using the pause command. + +We recommend you look at the beamer user guide, to get more acquainted with +this marvelous utility. + +.. L16 + +.. R16 + +This screen shows a very basic LaTeX presentation done using beamer. We use the +warsaw theme. There are three slides in the actual document definition, but we +see more than 3 slides in the output document. This is because of the overlay +we created in the last slide. Please pause the tutorial and go through the +example shown on the screen. + +.. L17 + +{{{continue from paused state}}} +{{{ Show summary slide }}} + +.. R17 + +This brings us to the end of this tutorial. In this tutorial, we have, + +.. 1. Written and typeset simple math formulae in LaTeX. +.. #. Written bibliography for a LaTeX document. +.. #. Made a sample presentations in LaTeX, using beamer. + +.. L18 + +{{{Show self assessment questions slide}}} + +.. R18 + +Here are some self assessment questions for you to solve + + 1. What is the function of useoutertheme command used in the beamer +presentation example shown before ?? what happens when you comment out or +remove the line. + + 2. Are commands like \alpha, \beta ,etc commands provided by amsmath package ? + +.. L19 + +{{{Show self assessment questions slide}}} + +.. R19 + +And the answers, + +1. The outertheme command in beamer is used to customize the amount of +header/footer information shown in each slide. In the example shown below the +useoutertheme command with infolines argument automatically adds more +information to the footer like page number, author and institute,etc. + +2. No, commands like alpha, beta, etc are not commands provided by the amsmath +package. + +.. L20 + +{{{ Show the thankyou slide }}} + +.. R20 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! diff --git a/Latex/images/iitb-logo.png b/Latex/images/iitb-logo.png Binary files differnew file mode 100644 index 0000000..38ec17e --- /dev/null +++ b/Latex/images/iitb-logo.png diff --git a/TDD/getting_started_with_tdd/slide.tex b/TDD/getting_started_with_tdd/tdd1.tex index 54875f9..f056ce5 100644 --- a/TDD/getting_started_with_tdd/slide.tex +++ b/TDD/getting_started_with_tdd/tdd1.tex @@ -22,68 +22,58 @@ commentstyle=\color{red}\itshape, stringstyle=\color{green}, showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} -\title{Getting started with TDD} +\title{SEES: Test Driven Development} \author{FOSSEE} -\institute{IIT Bombay} \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} -\AtBeginSection[] -{ - \begin{frame}<beamer> - \frametitle{Outline} - \tableofcontents[currentsection] - \end{frame} -} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + \begin{document} \begin{frame} - \begin{center} \vspace{12pt} -\textcolor{blue}{\huge Getting started with Test Driven Development} +\textcolor{blue}{\huge Test Driven Development \\Part I} \end{center} \vspace{18pt} \begin{center} \vspace{10pt} -\includegraphics[scale=0.95]{../../images/fossee-logo.png}\\ +\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ \vspace{5pt} \scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ \scriptsize Funded by National Mission on Education through ICT\\ \scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../../images/iitb-logo.png}\\ +\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ \end{center} \end{frame} - -\begin{frame} -\frametitle{Outline} -\setcounter{tocdepth}{3} -\tableofcontents -\end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Introduction} \begin{frame} \frametitle{Objectives} - At the end of this section, you will be able to: + At the end of this tutorial, you will be able to, \begin{itemize} - \item Understand the concept of Test Driven Development. - \item Write your code using the TDD paradigm. + \item Know what is TDD. + \item Understand the use of test cases. + \item Write simple tests for a function. + \end{itemize} \end{frame} - - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Pre-requisite} \label{sec-3} -Spoken tutorial on Basic Python +Spoken tutorial on - \begin{itemize} -\item Topic of tutorial here +\item Getting started with functions. \end{itemize} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{What is TDD?} @@ -99,106 +89,107 @@ Spoken tutorial on Basic Python \item Refactor the code you've just written -- optimize the algorithm, remove duplication, add documentation, etc. \item Run the tests again, to see that all the tests still pass. - \item Go back to 1. + \end{enumerate} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{First Test} \begin{frame}[fragile] - \frametitle{First Test -- GCD} + \frametitle{First Test -- fibonacci} \begin{itemize} - \item simple program -- GCD of two numbers + \item simple program -- Returns nth fibonacci number \item What are our code units? \begin{itemize} - \item Only one function \texttt{gcd} - \item Takes two numbers as arguments - \item Returns one number, which is their GCD + \item Only one function \texttt{fibonacci} + \item Takes one number as argument + \item Returns one number, which is the nth number of fibonacci series. \end{itemize} \begin{lstlisting} -c = gcd(44, 23) +c = fibonacci(3) \end{lstlisting} - \item c will contain the GCD of the two numbers. + \item c will contain 3rd number of fibonacci series,counting from 0. \end{itemize} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Test Cases} \begin{itemize} \item Important to have test cases and expected outputs even before writing the first test! - \item $a=48$, $b=48$, $GCD=48$ - \item $a=44$, $b=19$, $GCD=1$ + \item $n=3$, $fibonacci=2$ + \item $n=4$, $fibonacci=3$ \item Tests are just a series of assertions \item True or False, depending on expected and actual behavior \end{itemize} - \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Test Cases -- Code} \begin{lstlisting} -tc1 = gcd(48, 64) -if tc1 != 16: - print "Failed for a=48, b=64. Expected 16. \ +tc1 = fibonacci(3) +if tc1 != 2: + print "Failed for n=3. Expected 2. \ Obtained %d instead." % tc1 exit(1) -tc2 = gcd(44, 19) -if tc2 != 1: - print "Failed for a=44, b=19. Expected 1. \ +tc2 = fibonacci(4) +if tc2 != 3: + print "Failed for n=4. Expected 3. \ Obtained %d instead." % tc2 exit(1) print "All tests passed!" \end{lstlisting} \begin{itemize} -\item The function \texttt{gcd} doesn't even exist! +\item The function \texttt{fibonacci} doesn't even exist! \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Stubs} \begin{itemize} - \item First write a very minimal definition of \texttt{gcd} + \item First write a very minimal definition of \texttt{fibonacci} \begin{lstlisting} -def gcd(a, b): +def fibonacci(a): pass \end{lstlisting} \item Written just, so that the tests can run \item Obviously, the tests are going to fail \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{\texttt{gcd.py}} + \frametitle{\texttt{fibonacci.py}} \begin{lstlisting} -def gcd(a, b): +def fibonacci(n): pass if __name__ == '__main__': - tc1 = gcd(48, 64) - if tc1 != 16: - print "Failed for a=48 and b=64. \ - Expected 16. Obtained %d instead." % tc1 + tc1 = fibonacci(3) + if tc1 != 2: + print "Failed for n=3. \ + Expected 2. Obtained %d instead." % tc1 exit(1) - tc2 = gcd(44, 19) - if tc2 != 1: - print "Failed for a=44 and b=19. \ - Expected 1. Obtained %d instead." % tc2 + tc2 = fibonacci(4) + if tc2 != 3: + print "Failed for n=4. \ + Expected 3. Obtained %d instead." % tc2 exit(1) print "All tests passed!" \end{lstlisting} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{First run} \begin{lstlisting} -$ python gcd.py +$ python fibonacci.py Traceback (most recent call last): - File "gcd.py", line 7, in <module> - print "Failed for a=48 and b=64. Expected 16. + File "fibonacci.py", line 8, in <module> + print "Failed for n=3. Expected 2. Obtained %d instead." % tc1 TypeError: %d format: a number is required, not NoneType @@ -209,130 +200,90 @@ a number is required, not NoneType \item The next step is to write code, so that the test just passes. \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Euclidean Algorithm} \begin{itemize} - \item Modify the \texttt{gcd} stub function + \item Modify the \texttt{fibonacci} stub function \item Then, run the script to see if the tests pass. \end{itemize} \begin{lstlisting} -def gcd(a, b): - if a == 0: - return b - while b != 0: - if a > b: - a = a - b - else: - b = b - a +def fibonacci(n): + a, b = 0, 1 + for i in range(n): + a, b = b, a + b return a + \end{lstlisting} \begin{lstlisting} -$ python gcd.py +$ python fibonacci.py All tests passed! \end{lstlisting} %$ \begin{itemize} \item \alert{Success!} \end{itemize} \end{frame} - - -\begin{frame}[fragile] - \frametitle{Euclidean Algorithm -- Modulo} - \begin{itemize} - \item Repeated subtraction can be replaced by a modulo - \item modulo of \texttt{a\%b} is always less than b - \item when \texttt{a < b}, \texttt{a\%b} equals \texttt{a} - \item Combine these two observations, and modify the code -\begin{lstlisting} -def gcd(a, b): - while b != 0: - a, b = b, a % b - return a -\end{lstlisting} - \item Check that the tests pass again - \end{itemize} -\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Euclidean Algorithm -- Recursive} \begin{itemize} - \item Final improvement -- make \texttt{gcd} recursive + \item Final improvement -- make \texttt{fibonacci} recursive \item More readable and easier to understand \begin{lstlisting} -def gcd(a, b): - if b == 0: - return a - return gcd(b, a%b) +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) + \end{lstlisting} \item Check that the tests pass again \end{itemize} \end{frame} -\begin{frame}[fragile] - \frametitle{Document \texttt{gcd}} - \begin{itemize} - \item Undocumented function is as good as unusable - \item Let's add a docstring \& We have our first test! - \end{itemize} -\begin{lstlisting} -def gcd(a, b): - """Returns the Greatest Common Divisor of the - two integers passed as arguments. - - Args: - a: an integer - b: another integer - - Returns: Greatest Common Divisor of a and b - """ - if b == 0: - return a - return gcd(b, a%b) -\end{lstlisting} -\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Summary} +\label{sec-8} -\begin{frame}[fragile] - \frametitle{Persistent Test Cases} - \begin{itemize} - \item Tests should be pre-determined and written, before the code - \item Test Data is repeatedly used; Hence, saved in persistent - format - \item Let's save data for GCD tests in a text file. - \item The file shall have multiple lines of test data - \item Each line corresponds to a single test case - \item Each line consists of three comma separated values -- - \begin{itemize} - \item First two coloumns are the integers for which the GCD has to be - computed - \item Third coloumn is the expected GCD to the preceding two - numbers. - \end{itemize} - \item Let us call our data file \texttt{gcd\_testcases.dat} - \end{itemize} + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Undestand the basic steps involved in Test driven development. +\item Design a TDD approach for a given \texttt{fibonacci} function. + +\end{itemize} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{Modify \texttt{gcd.py}} -\begin{lstlisting} -if __name__ == '__main__': - for line in open('gcd_testcases.dat'): - values = line.split(', ') - a = int(values[0]) - b = int(values[1]) - g = int(values[2]) - - tc = gcd(a, b) - if tc != g: - print "Failed for a=%d and b=%d.\ - Expected %d. Obtained %d instead."\ - % (a, b, g, tc) - exit(1) +\frametitle{Evaluation} +\label{sec-9} - print "All tests passed!" -\end{lstlisting} + +\begin{enumerate} +\item ? +\vspace{8pt} +\item ? +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item +\vspace{15pt} +\item +\end{enumerate} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} @@ -349,4 +300,5 @@ if __name__ == '__main__': \end{block} \end{frame} + \end{document} diff --git a/TDD/getting_started_with_tdd/tdd1_script.rst b/TDD/getting_started_with_tdd/tdd1_script.rst new file mode 100755 index 0000000..9da1613 --- /dev/null +++ b/TDD/getting_started_with_tdd/tdd1_script.rst @@ -0,0 +1,205 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Know what is TDD. + .. 2. Understand the use of test cases. + .. 3. Write simple tests for a function. + +.. Prerequisites +.. ------------- + +.. 1. Getting started with functions + + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and Welcome to the tutorial on +'Test driven development - Part 1'. + +.. L2 + +{{{ Show slide with objectives }}} + +.. R2 + +At the end of this tutorial, you will be able to, + + 1. understand basics of Test Driven Development. + #. understand the use test cases. + #. write simple tests for a function. + +.. L3 + +{{{ Switch to the slide3, pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +tutorial on "Getting started with functions". + +.. R4 + +Test-driven development is a software development +process that relies on the repetition of a very short +development cycle. +In TDD,one writes a failing automated test case that +defines a desired improvement or new function, then produces +code to pass that test and finally refactors the new code to +acceptable standards. + + +.. L4 + +{{{ Switch to slide4 ,What is TDD?}}} + + +.. R5 + +To illustrate TDD, lets take a simple program. Consider a +function ``fibonacci``, that takes one argument and returns +the nth number of ``fibonacci`` series. + +.. L5 + +{{{ Switch to slide5, First test- fibonacci }}} + +.. R6 + +To test ``fibonacci`` function, we need test +cases. +As shown in this slide, +test cases are expected outputs for a given set of inputs. + + +.. L6 + +{{{ Switch to slide6, Test cases }}} + +.. R7 + +The sample code for test cases is shown here. Observe that if +any ``if`` statement is executed, test aborts after printing the +error message. + +.. L7 + +{{{ Switch to slide7, Test cases-Code }}} + +.. R8 + +The ``fibonacci`` function is written just enough so that +test can run. + + +.. L8 + +{{{ switch to slide8, Stubs }}} + +.. R9 + +Combine the function and test cases and put them together in +``fibonacci.py`` file.Add the test cases after name=main idiom. + +.. L9 + +{{{ Switch to slide9, fibonacci.py }}} + +.. R10 + +Lets run fibonacci.py by typing ``python fibonacci.py``. +As we haven't written any meaningful code in our ``fibonacci`` +function, it fails immediately. +Our next step is to write just minimum code to pass our tests. + +.. L10 + +{{{ Run the fibonacci.py in terminal and show the error output.}}} +:: + + python fibonacci.py + +.. R11 + +Modify the fibonacci stub function with given code. +Save and run it again as `` python fibonacci.py``. +{{{ pause }}} +Observe that, there will be no errors, as +the test passes successfully. + +.. L11 + +{{{ switch to slide-11, Euclidean Algorithm }}} +Switch to terminal and modify fibonacci function in ``nano`` +editor and run. +:: + + python fibonacci.py + +.. R12 + +The same ``fibonacci`` function is modified to make it more readable +and easy to understand using recursion. +Pause this video here.Replace the ``fibonacci`` function with recursive one. +Run the modified ``fibonacci.py`` file. The test should pass again +without any errors. +After successfully achieving this result, you can resume the video. + +.. L12 + +{{{ Show slide12, Euclidean Algorithm- Recursive}}} + + +.. R13 + +This brings us to the end of the tutorial.In this tutorial, + we have learnt to, + + 1. Undestand the basic steps involved in Test driven development. + #. Design a Test driven approach for a given ``fibonacci`` function. + + +.. L13 + +{{{ switch to slide-13,Summary }}} + +.. R14 + +Here are some self assessment questions for you to solve + 1. + + 2. + +.. L14 + +{{{ switch to slide-14, Evaluation }}} + +.. R15 + +And the answers are, + 1. + + 2. + +.. L15 + +{{{ switch to slide-15 ,Solutions}}} + +.. R16 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! + +.. L16 + +{{{ Switch to slide-16, Thankyou}}} + diff --git a/TDD/images/fossee-logo.png b/TDD/images/fossee-logo.png Binary files differnew file mode 100644 index 0000000..49d1797 --- /dev/null +++ b/TDD/images/fossee-logo.png diff --git a/TDD/images/iitb-logo.png b/TDD/images/iitb-logo.png Binary files differnew file mode 100644 index 0000000..38ec17e --- /dev/null +++ b/TDD/images/iitb-logo.png diff --git a/TDD/math_utils/fibonacci.py b/TDD/math_utils/fibonacci.py new file mode 100644 index 0000000..0f454d6 --- /dev/null +++ b/TDD/math_utils/fibonacci.py @@ -0,0 +1,7 @@ +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) diff --git a/TDD/math_utils/fibonacci_testcases.dat b/TDD/math_utils/fibonacci_testcases.dat new file mode 100644 index 0000000..c5dae1a --- /dev/null +++ b/TDD/math_utils/fibonacci_testcases.dat @@ -0,0 +1,8 @@ +0, 0 +1, 1 +2, 1 +3, 2 +4, 3 +5, 5 +6, 8 +7, 13 diff --git a/TDD/math_utils/test_fibonacci.py b/TDD/math_utils/test_fibonacci.py new file mode 100644 index 0000000..ee3393f --- /dev/null +++ b/TDD/math_utils/test_fibonacci.py @@ -0,0 +1,27 @@ +import fibonacci +import unittest + +class TestFibonacciFunction(unittest.TestCase): + + def setUp(self): + self.test_file = open('fibonacci_testcases.dat') + self.test_cases = [] + for line in self.test_file: + values = line.split(', ') + n = int(values[0]) + a = int(values[1]) + + self.test_cases.append([n, a]) + + def test_fibonacci(self): + for case in self.test_cases: + n = case[0] + a = case[1] + self.assertEqual(fibonacci.fibonacci(n),a) + + def tearDown(self): + self.test_file.close() + del self.test_cases + +if __name__ == '__main__': + unittest.main() diff --git a/TDD/two_column.py b/TDD/two_column.py new file mode 100755 index 0000000..4134b2e --- /dev/null +++ b/TDD/two_column.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# This script generates two column format from the script file. +import re, optparse + +num = 0 +content = {} + +def parse_script(script): + """Parse the file, and get each cell's content into a dictionary.""" + where = 'HEAD' + txt = '' + global num + for line in open(script): + if line.startswith('..'): + loc = re.findall(".. ((L|R)(\d+))", line) + if loc: + # Next cell has been found + # Save previous cell data + content[where] = txt + + txt = '' + where = loc[0][0] + num = int(loc[0][2]) if int(loc[0][2]) > num else num + continue + else: + pass + txt += line + content[where] = txt # Saving the content of the last cell. + +def write_two_col(content, two_col): + """ Write the content to a file, in two column format.""" + f = open(two_col, 'w') + f.write('%s' %content['HEAD']) + + f.write("\n\n+%s+%s+\n" %('-'*82, '-'*82)) + for i in range(1, num+1): + l = '%s%s' %('L', i) + r = '%s%s' %('R', i) + + # Split each side text into individual lines + if l in content: + ltext = content[l].strip().splitlines() + else: + ltext = [''] + if r in content: + rtext = content[r].strip().splitlines() + else: + rtext = [''] + + # Ensure that both sides have the same number of lines + ltext.extend(['']*(len(rtext) - len(ltext))) + rtext.extend(['']*(len(ltext) - len(rtext))) + + # Write each of the lines in respective columns + for k in range(len(ltext)): + f.write("| %-80s | %-80s |\n" %(ltext[k], rtext[k])) + + # Horizontal division + f.write("+%s+%s+\n" %('-'*82, '-'*82)) + + f.close() + +if __name__ == '__main__': + parser = optparse.OptionParser() + parser.add_option("-i", default="script.rst", dest="input", + help="Input file. 'script.rst' is used by default.") + parser.add_option("-o", default="script2col.rst", dest="output", + help="Output file. script2col.rst is used by default.") + + parser.description = """Converts a script file into two column format.""" + + parser.epilog = \ + """Make sure that you check the validity of the formatting of both +the INPUT and the OUTPUT files, using rst2html. Also, Make sure that +each line, in the INPUT file, is less than 80 chars long.""" + + (options, args) = parser.parse_args() + + script, two_col = options.input, options.output + + parse_script(script) + write_two_col(content, two_col) + + print "Converted %s to 2 column format and saved as %s" %(script, two_col) diff --git a/TDD/using_python_frameworks_for_TDD/slide.tex b/TDD/using_python_framework_for_tdd/tdd2.tex index a6308c4..561f4a2 100644 --- a/TDD/using_python_frameworks_for_TDD/slide.tex +++ b/TDD/using_python_framework_for_tdd/tdd2.tex @@ -22,61 +22,98 @@ commentstyle=\color{red}\itshape, stringstyle=\color{green}, showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} -\title{Getting started with TDD} +\title{SEES: Test Driven Development} \author{FOSSEE} -\institute{IIT Bombay} \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} -\AtBeginSection[] -{ - \begin{frame}<beamer> - \frametitle{Outline} - \tableofcontents[currentsection] - \end{frame} -} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + \begin{document} -\begin{frame} +\begin{frame} \begin{center} \vspace{12pt} -\textcolor{blue}{\huge Using Python Testing Frameworks} +\textcolor{blue}{\huge Test Driven Development \\Part II} \end{center} \vspace{18pt} \begin{center} \vspace{10pt} -\includegraphics[scale=0.95]{../../images/fossee-logo.png}\\ +\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ \vspace{5pt} \scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ \scriptsize Funded by National Mission on Education through ICT\\ \scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../../images/iitb-logo.png}\\ +\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ \end{center} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Introduction} \begin{frame} \frametitle{Objectives} - At the end of this section, you will be able to: + At the end of this tutorial, you will be able to, \begin{itemize} - \item Use doctests to test your Python code. - \item Use unittests to test your Python code. - \item Use the nose module to test your code. + \item Know what are persistent test cases. + \item Write doctest \& unittest for any given function. + \item Understand the use of nosetest. + \end{itemize} -\end{frame} + \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Pre-requisite} \label{sec-3} -Spoken tutorial on Basic Python +Spoken tutorial on - \begin{itemize} -\item Topic of tutorial here +\item Test Driven Development -- Part I \end{itemize} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - +\begin{frame}[fragile] + \frametitle{Persistent Test Cases} + \begin{itemize} + \item Tests should be pre-determined and written, before the code + \item Test Data is repeatedly used; Hence, saved in persistent + format + \item Let's save data for fibonacci tests in a text file. + \item The file shall have multiple lines of test data + \item Each line corresponds to a single test case + \item Each line consists of two comma separated values -- + \begin{itemize} + \item First coloumn is the integer which has to be + passed to the function. + \item Second coloumn is the return value from the function. + \end{itemize} + \item Let us call our data file \texttt{fibonacci\_testcases.dat} + \end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[fragile] + \frametitle{Modify \texttt{fibonacci.py}} +\begin{lstlisting} +if __name__ == '__main__': + for line in open('fibonacci_testcases.dat'): + values = line.split(', ') + n = int(values[0]) + a = int(values[1]) + + tc = fibonacci(n) + if tc != a: + print "Failed for n=%d.\ + Expected %d. Obtained %d instead."\ + % (n, a, tc) + exit(1) + + print "All tests passed!" +\end{lstlisting} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Python Testing Frameworks} \begin{frame}[fragile] @@ -90,7 +127,7 @@ Spoken tutorial on Basic Python \end{itemize} \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{\texttt{doctest} module} \begin{frame}[fragile] @@ -104,32 +141,33 @@ Spoken tutorial on Basic Python \item \texttt{doctest} module picks up all such interactive examples \item Executes them and determines if the code runs, as documented \end{itemize} - Let's use the \texttt{doctest} module for our \texttt{gcd} function + Let's use the \texttt{doctest} module for our \texttt{fibonacci} function \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{doctest for \texttt{gcd.py}} + \frametitle{doctest for \texttt{fibonacci.py}} \begin{tiny} \begin{lstlisting} -def gcd(a, b): - """Returns the Greatest Common Divisor of the two integers - passed as arguments. +def fibonacci(n): + """Returns the nth fibonacci number. Args: - a: an integer - b: another integer - - Returns: Greatest Common Divisor of a and b - - >>> gcd(48, 64) - 16 - >>> gcd(44, 19) - 1 + n: an integer + + + >>> fibonacci(3) + 2 + >>> fibonacci(4) + 3 """ - if b == 0: - return a - return gcd(b, a%b) + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) \end{lstlisting} \end{tiny} \begin{itemize} @@ -137,9 +175,9 @@ def gcd(a, b): \item Now we need to tell the \texttt{doctest} module to execute \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{doctest for \texttt{gcd.py} \ldots} + \frametitle{doctest for \texttt{fibonacci.py} \ldots} \begin{lstlisting} if __name__ == "__main__": import doctest @@ -152,18 +190,18 @@ if __name__ == "__main__": \item Complains only when one or more tests fail. \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{\texttt{doctest} -- Execution} \begin{itemize} - \item Run the doctests by running \texttt{gcd.py} + \item Run the doctests by running \texttt{fibonacci.py} \begin{lstlisting} -$ python gcd.py +$ python fibonacci.py \end{lstlisting} %$ \item All the tests pass, and doctest gives no output \item For a more detailed report we can run with -v argument \begin{lstlisting} -$ python gcd.py -v +$ python fibonacci.py -v \end{lstlisting} %$ \item If the output contains a blank line, use \texttt{<BLANKLINE>} \item To see a failing test case, replace \texttt{return a} with \texttt{b} @@ -171,7 +209,7 @@ $ python gcd.py -v \end{frame} \subsection{\texttt{unittest} framework} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{\texttt{unittest}} \begin{itemize} @@ -184,57 +222,43 @@ $ python gcd.py -v \item Easily aggregate tests into collections and improved reporting \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{\texttt{unittest}} - \begin{itemize} - \item It won't be long, before we complain about the power of - \texttt{doctest} - \item \texttt{unittest} framework can efficiently automate tests - \item Easily initialize code and data for executing the specific - tests - \item Cleanly shut them down once the tests are executed - \item Easily aggregate tests into collections and improved reporting - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{unittest}ing \texttt{gcd.py}} + \frametitle{\texttt{unittest}ing \texttt{fibonacci.py}} \begin{itemize} \item Subclass the \texttt{TestCase} class in \texttt{unittest} \item Place all the test code as methods of this class - \item Use the test cases present in \texttt{gcd\_testcases.dat} - \item Place the code in \texttt{test\_gcd.py} + \item Use the test cases present in \texttt{fibonacci\_testcases.dat} + \item Place the code in \texttt{test\_fibonacci.py} \end{itemize} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile,allowframebreaks] - \frametitle{\texttt{test\_gcd.py}} + \frametitle{\texttt{test\_fibonacci.py}} \small \begin{lstlisting} -import gcd +import fibonacci import unittest -class TestGcdFunction(unittest.TestCase): +class TestFibonacciFunction(unittest.TestCase): def setUp(self): - self.test_file = open('gcd_testcases.dat') + self.test_file = \ + open('fibonacci_testcases.dat') self.test_cases = [] for line in self.test_file: values = line.split(', ') - a = int(values[0]) - b = int(values[1]) - g = int(values[2]) - - self.test_cases.append([a, b, g]) + n = int(values[0]) + a = int(values[1]) + + self.test_cases.append([n, a]) - def test_gcd(self): + def test_fibonacci(self): for case in self.test_cases: - a = case[0] - b = case[1] - g = case[2] - self.assertEqual(gcd.gcd(a, b), g) + n = case[0] + a = case[1] + self.assertEqual(fibonacci.fibonacci(n),a) def tearDown(self): self.test_file.close() @@ -244,22 +268,22 @@ if __name__ == '__main__': unittest.main() \end{lstlisting} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] - \frametitle{\texttt{test\_gcd.py}} + \frametitle{\texttt{test\_fibonacci.py}} \begin{itemize} \item \texttt{setUp} -- we read all the test data and store it in a list \item \texttt{tearDown} -- delete the data to free up memory and close open file - \item \texttt{test\_gcd} -- actual test code + \item \texttt{test\_fibonacci} -- actual test code \item \texttt{assertEqual} -- compare actual result with expected one \item Write documentation for above code. \end{itemize} \end{frame} \section{\texttt{nose}} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{\texttt{nose} tests} \begin{itemize} @@ -281,6 +305,47 @@ $ nosetests \end{itemize} \end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Use of persistent test cases for better control. +\item Undestand the use of doctest \& unittest. +\item Understand the use of nosetest . + +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[fragile] +\frametitle{Evaluation} +\label{sec-9} + + +\begin{enumerate} +\item ? +\vspace{8pt} +\item ? +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item +\vspace{15pt} +\item +\end{enumerate} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \begin{block}{} @@ -296,4 +361,5 @@ $ nosetests \end{block} \end{frame} + \end{document} diff --git a/TDD/using_python_framework_for_tdd/tdd2_script.rst b/TDD/using_python_framework_for_tdd/tdd2_script.rst new file mode 100755 index 0000000..85c96d5 --- /dev/null +++ b/TDD/using_python_framework_for_tdd/tdd2_script.rst @@ -0,0 +1,198 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Know what is TDD. + .. 2. Understand the use of test cases. + .. 3. Write simple tests for a function. + +.. Prerequisites +.. ------------- + +.. 1. Test driven development - Part 1 + + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and Welcome to the tutorial on +'Test driven development - Part 2'. + +.. L2 + +{{{ Show slide with objectives }}} + +.. R2 + +At the end of this tutorial, you will be able to, + + 1. understand use of persistent test cases. + #. write doctest and unittest for any given function. + #. and understand the use of nosetest. + +.. L3 + +{{{ Switch to the slide3, pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +tutorial on "Test driven development-part 1". + +.. R4 + + + +.. L4 + +{{{ Switch to slide4 ,Persistent test cases}}} + + +.. R5 + +To illustrate TDD, lets take a simple program. Consider a +function ``fibonacci``, that takes one argument and returns +the nth number of ``fibonacci`` series. + +.. L5 + +{{{ Switch to slide5, First test- fibonacci }}} + +.. R6 + +To test ``fibonacci`` function, we need test +cases. +As shown in this slide, +test cases are expected outputs for a given set of inputs. + + +.. L6 + +{{{ Switch to slide6, Test cases }}} + +.. R7 + +The sample code for test cases is shown here. Observe that if +any ``if`` statement is executed, test aborts after printing the +error message. + +.. L7 + +{{{ Switch to slide7, Test cases-Code }}} + +.. R8 + +The ``fibonacci`` function is written just enough so that +test can run. + + +.. L8 + +{{{ switch to slide8, Stubs }}} + +.. R9 + +Combine the function and test cases and put them together in +``fibonacci.py`` file.Add the test cases after name=main idiom. + +.. L9 + +{{{ Switch to slide9, fibonacci.py }}} + +.. R10 + +Lets run fibonacci.py by typing ``python fibonacci.py``. +As we haven't written any meaningful code in our ``fibonacci`` +function, it fails immediately. +Our next step is to write just minimum code to pass our tests. + +.. L10 + +{{{ Run the fibonacci.py in terminal and show the error output.}}} +:: + + python fibonacci.py + +.. R11 + +Modify the fibonacci stub function with given code. +Save and run it again as `` python fibonacci.py``. +{{{ pause }}} +Observe that, there will be no errors, as +the test passes successfully. + +.. L11 + +{{{ switch to slide-11, Euclidean Algorithm }}} +Switch to terminal and modify fibonacci function in ``nano`` +editor and run. +:: + + python fibonacci.py + +.. R12 + +The same ``fibonacci`` function is modified to make it more readable +and easy to understand using recursion. +Pause this video here.Replace the ``fibonacci`` function with recursive one. +Run the modified ``fibonacci.py`` file. The test should pass again +without any errors. +After successfully achieving this result, you can resume the video. + +.. L12 + +{{{ Show slide12, Euclidean Algorithm- Recursive}}} + + +.. R13 + +This brings us to the end of the tutorial.In this tutorial, + we have learnt to, + + 1. Undestand the basic steps involved in Test driven development. + #. Design a Test driven approach for a given ``fibonacci`` function. + + +.. L13 + +{{{ switch to slide-13,Summary }}} + +.. R14 + +Here are some self assessment questions for you to solve + 1. + + 2. + +.. L14 + +{{{ switch to slide-14, Evaluation }}} + +.. R15 + +And the answers are, + 1. + + 2. + +.. L15 + +{{{ switch to slide-15 ,Solutions}}} + +.. R16 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! + +.. L16 + +{{{ Switch to slide-16, Thankyou}}} + |