Skip to content

Commit d7aa945

Browse files
committed
added examples for Fraction class and for debugging
1 parent 2b80207 commit d7aa945

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

text/main/classes/dunder/dunder.tex

+50-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
\endhsection%
164164
%
165165
%
166-
\hsection{\texttt{\_\_hash\_\_}, \texttt{\_\_eq\_\_} and \texttt{dict} and \texttt{set}}%
166+
\hsection{Objects in Sets and as Keys in Dictionaries:~\texttt{\_\_hash\_\_}, \texttt{\_\_eq\_\_}}%
167167
\label{sec:hashDunder}%
168168
%
169169
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/point_with_hash.py}{--args format}{dunder:point_with_hash}{%
@@ -322,4 +322,53 @@
322322
\FloatBarrier%
323323
\endhsection%
324324
%
325+
\hsection{Arithmetic Dunder and Ordering}%
326+
%
327+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_1}{dunder:fraction:part_1}{%
328+
Part~1 of the \pythonil{Fraction} class: The initializer \pythonilIdx{\_\_init\_\_} and global constants.}%
329+
%
330+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_2}{dunder:fraction:part_2}{%
331+
Part~2 of the \pythonil{Fraction} class: Addition (via \pythonilIdx{\_\_add\_\_}) and subtraction (via \pythonilIdx{\_\_sub\_\_}).}%
332+
%
333+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_3}{dunder:fraction:part_3}{%
334+
Part~3 of the \pythonil{Fraction} class: Multiplication (via \pythonilIdx{\_\_mul\_\_}) and division (via \pythonilIdx{\_\_truediv\_\_})}%
335+
%
336+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_4}{dunder:fraction:part_4}{%
337+
Part~4 of the \pythonil{Fraction} class: All order-related dunder methods\pythonIdx{\_\_eq\_\_}\pythonIdx{\_\_ne\_\_}\pythonIdx{\_\_lt\_\_}\pythonIdx{\_\_le\_\_}\pythonIdx{\_\_gt\_\_}\pythonIdx{\_\_ge\_\_}.}%
338+
%
339+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_5}{dunder:fraction:part_5}{%
340+
Part~5 of the \pythonil{Fraction} class: String representation via \pythonilIdx{\_\_str\_\_} and \pythonilIdx{\_\_repr\_\_}.}%
341+
%
342+
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/pytest_doctest.sh 09_dunder fraction.py}{dunder:fraction:doctest}{%
343+
The output of \pytest\ executing the \pglspl{doctest} for our \pythonil{Fraction} class.}%
344+
%
345+
\FloatBarrier%
346+
\endhsection%
347+
%
348+
\hsection{Debugging}%
349+
%
350+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction_decimal_str_err_1.py}{--args format --labels part_6}{dunder:fraction_decimal_str_err_1:part_6}{%
351+
Part~6 of the \pythonil{Fraction} class: Adding a \pythonil{decimal_str} conversation method.}%
352+
%
353+
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/pytest_doctest.sh 09_dunder fraction_decimal_str_err_1.py}{dunder:fraction_decimal_str_err_1:doctest}{%
354+
The output of \pytest\ executing the \pglspl{doctest} for our \pythonil{Fraction} class with the \pythonil{decimal_str} method from \cref{lst:dunder:fraction_decimal_str_err_1:part_6}: It fails!}%
355+
%
356+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction_decimal_str_err_2.py}{--args format --labels part_6}{dunder:fraction_decimal_str_err_2:part_6}{%
357+
Part~7 of the \pythonil{Fraction} class: A hopefully improved \pythonil{decimal_str} method.}%
358+
%
359+
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/pytest_doctest.sh 09_dunder fraction_decimal_str_err_2.py}{dunder:fraction_decimal_str_err_2:doctest}{%
360+
The output of \pytest\ executing the \pglspl{doctest} for our \pythonil{Fraction} class with the improved \pythonil{decimal_str} method from \cref{lst:dunder:fraction_decimal_str_err_2:part_6}: It fails!}%
361+
%
362+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction.py}{--args format --labels part_6}{dunder:fraction:part_6}{%
363+
Part~8 of the \pythonil{Fraction} class: A correct \pythonil{decimal_str} method.}%
364+
%
365+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction_sqrt.py}{--args format}{dunder:fraction_sqrt}{%
366+
Using the \pythonil{Fraction} class to compute square roots.}%
367+
%
368+
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/pytest_doctest.sh 09_dunder fraction_sqrt.py}{dunder:fraction_sqrt:doctest}{%
369+
The (successful) output of \pytest\ executing the \pglspl{doctest} for our \pythonil{sqrt} function from~\cref{lst:dunder:fraction_sqrt} working on instances of the \pythonil{Fraction} class.}%
370+
%
371+
\FloatBarrier%
372+
\endhsection%
373+
%
325374
\endhsection%

0 commit comments

Comments
 (0)