Skip to content

Commit d7d2126

Browse files
committed
minor improvements
1 parent d8ea258 commit d7d2126

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

text/main/classes/dunder/dunder.tex

+8-7
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,8 @@
512512
\FloatBarrier%
513513
\endhsection%
514514
%
515-
\hsection{Debugging}%
516-
%
517-
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction_decimal_str_err.py}{--args format --labels part_6}{dunder:fraction_decimal_str_err:part_6}{%
518-
Part~6 of the \pythonil{Fraction} class: Adding a \pythonil{decimal_str} conversation method.}%
515+
\hsection{Interlude:~Debugging}%
516+
\label{sec:dunde:debugging}%
519517
%
520518
We now want to use mathematics based on our class \pythonil{Fraction} for some \inQuotes{real} computation.
521519
Remember back in \cref{sec:whileLoop}, we implemented the algorithm of Heron to compute the square root using a \pythonil{while}~loop.
@@ -533,6 +531,9 @@
533531
Since some fractions, like~$\frac{1}{3}$ and~$\frac{1}{7}$ have never-ending decimal representations, this function needs a parameter \pythonil{max_frac} specifying the maximum number of fractional digits to generate.
534532
We will set it to 100 by default.
535533

534+
\gitPython{\programmingWithPythonCodeRepo}{09_dunder/fraction_decimal_str_err.py}{--args format --labels part_6}{dunder:fraction_decimal_str_err:part_6}{%
535+
Part~6 of the \pythonil{Fraction} class: Adding a \pythonil{decimal_str} conversation method.}%
536+
536537
In \cref{lst:dunder:fraction_decimal_str_err:part_6} we present the part of our class \pythonil{Fraction} that contains the code converting the fraction to a decimal string.
537538
Like all of our code in \pythonil{Fraction}, it takes the straightforward and probably inefficient route.
538539
The idea is simply to first cut-off the integer part of the fraction and then to produce the fractional digits one-by-one.
@@ -571,7 +572,7 @@
571572
As last digit, we therefore add \pythonil{80 // 16}, which is~\pythonil{5}.
572573
This is the last digit, because \pythonil{80 \% 16} is~0.
573574
Therefore, \pythonil{a == 0} holds after the fifth iteration.
574-
This makes the first part of the the loop condition \pythonil{a != 0} become \pythonil{False} and the loop terminates.
575+
This makes the first part of the the loop condition~(\pythonil{a != 0}) become \pythonil{False} and the loop terminates.
575576

576577
At this point, \pythonil{digits == [11, 1, 8, 7, 5]}.
577578
This is also right, because $\frac{179}{16}=11.1875$.
@@ -596,7 +597,7 @@
596597
If we only have a single digit, then our fraction is an integer number and we can return it as such.
597598
Thus, \pythonil{if len(digits) <= 1}, we convert the single digit to a string (after re-inserting the sign).
598599

599-
Otherwise, we need to have \inQuotes{.} after the first number in \pythonil{digits}.
600+
Otherwise, we need to have a~\inQuotes{.} after the first number in \pythonil{digits}.
600601
We can use \pythonil{digits.insert(1, ".")} to place it there\pythonIdx{list!insert}.
601602
In our original example of~$\frac{-179}{16}$, we first had \pythonil{digits == [11, 1, 8, 7, 5]}.
602603
After this step, we get \pythonil{digits == [11, ".", 1, 8, 7, 5]}.
@@ -684,7 +685,7 @@
684685
\end{figure}%
685686

686687
We want to investigate this very strange error.
687-
First, let us repeat the unit tests by also executing them inside \pycharm\ in \cref{fig:dunder:doctests}.
688+
First, let us repeat the \pglspl{doctest} by also executing them inside \pycharm\ in \cref{fig:dunder:doctests}.
688689
We open our source file and scroll to our function \pythonil{decimal_str}.
689690
With a right mouse click, a context menu is opened.
690691
Here, we then left-click on \menu{Run \inSQuotes{Doctest decimal\_str}}~(\cref{fig:dunder:doctests1}).

text/main/controlFlow/functions/functions.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
\FloatBarrier%
274274
\endhsection%
275275
%
276-
\hsection{Unit Testing}%
276+
\hsection{Interlude:~Unit Testing}%
277277
\label{sec:unitTesting}%
278278
\pythonIdx{function!unit test}%
279279
\pythonIdx{function!testing}%

text/main/controlFlow/iteration/iteration.tex

+4-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
\FloatBarrier%
254254
\endhsection%
255255
%
256-
\hsection{Brief Interlude: doctests}%
256+
\hsection{Interlude: doctests}%
257257
\gitPython{\programmingWithPythonCodeRepo}{07_iteration/list_flatten_iterables.py}{--args format}{iteration:list_flatten_iterables}{%
258258
A function that flattens \pythonilsIdx{list} and other \pythonilsIdx{Iterable} using list comprehension.}%
259259
%
@@ -326,6 +326,9 @@
326326
Since \pglspl{doctest} are usually brief, they are a quick and elegant way to complement more comprehensive unit tests in separate files (see \cref{bp:functionUnitTest}).%
327327
}%
328328
%
329+
While we here execute the \pglspl{doctest} using \pytest\ from the command line, you can also run them directly in~\pycharm.
330+
We do this later in \cref{sec:dunde:debugging}.%
331+
%
329332
\FloatBarrier%
330333
\endhsection%
331334
%

0 commit comments

Comments
 (0)