Skip to content

Commit 13ce19d

Browse files
committed
more steps into debugging
1 parent 160bd4f commit 13ce19d

File tree

6 files changed

+92
-19
lines changed

6 files changed

+92
-19
lines changed
1.95 KB
Binary file not shown.
Loading
1.95 KB
Binary file not shown.
+1
Loading

styles/keys.sty

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
%
2121
%% the PyCharm python console menu key
2222
\protected\gdef\pycharmConsole{\raisebox{-1.75pt}{\includegraphics[width=1em,keepaspectratio]{styles/icons/pycharmPythonConsole}}}%
23+
%% the pycharm debugger resume command
24+
\protected\gdef\pycharmDebuggerResume{\raisebox{-1.75pt}{\includegraphics[width=1em,keepaspectratio]{styles/icons/pycharmDebuggerResumeProgram}}}%
25+
%% the pycharm debugger step over command
26+
\protected\gdef\pycharmDebuggerStepOver{\raisebox{-1.75pt}{\includegraphics[width=1em,keepaspectratio]{styles/icons/pycharmDebuggerStepOver}}}%
2327
%
2428
%% Include a pdf with chinese characters
2529
%% the pdf should have 0.2pt space around the characters of height 11pt, font should be KaiTi

text/main/classes/dunder/dunder.tex

+86-19
Original file line numberDiff line numberDiff line change
@@ -787,91 +787,114 @@
787787
\centering%
788788
%
789789
\subfloat[][%
790-
Using the \debugger\ in \pycharm.%
790+
The first \pgls{doctest} case~$\frac{124}{2}$ is uninteresting, so we continue the program execution by clicking \pycharmDebuggerResume\ or hitting \keys{F9}.%
791791
\label{fig:dunder:debug07}%
792792
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug07}}}%
793793
%
794794
\strut\hfill\strut%
795795
%
796796
\subfloat[][%
797-
Using the \debugger\ in \pycharm.%
797+
The second \pgls{doctest} case~$\frac{1}{2}$ is also uninteresting. %
798+
We continue the program execution by clicking \pycharmDebuggerResume.%
798799
\label{fig:dunder:debug08}%
799800
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug08}}}%
800801
%
801802
\\[10pt]%
802803
%
803804
\subfloat[][%
804-
Using the \debugger\ in \pycharm.%
805+
The third \pgls{doctest} case, where the fraction is~$\frac{1}{3}$ and \pythonil{max_frac} is~\pythonil{10}. %
806+
We again skip over it by pressing~\keys{F9}.%
805807
\label{fig:dunder:debug09}%
806808
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug09}}}%
807809
%
808810
\strut\hfill\strut%
809811
%
810812
\subfloat[][%
811-
Using the \debugger\ in \pycharm.%
813+
The fourth \pgls{doctest} case~$\frac{-101001}{100000000}$ can be skipped as well.%
812814
\label{fig:dunder:debug10}%
813815
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug10}}}%
814816
%
815817
\\[10pt]%
816818
%
817819
\subfloat[][%
818-
Using the \debugger\ in \pycharm.%
820+
The test case~$\frac{1235}{1000}$, normalized to~$\frac{247}{200}$, also was successful and can be skipped by pressing~\pycharmDebuggerResume.%
819821
\label{fig:dunder:debug11}%
820822
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug11}}}%
821823
%
822824
\strut\hfill\strut%
823825
%
824826
\subfloat[][%
825-
Using the \debugger\ in \pycharm.%
827+
The last one of the uninteresting \pgls{doctest} cases:~\pythonil{Fraction(99995, 100000)}. %
828+
We again press~\keys{F9}.%
826829
\label{fig:dunder:debug12}%
827830
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug12}}}%
828831
%
829832
\caption{Using the \debugger\ in \pycharm.}%
830833
\label{fig:dunder:debugB}%
831834
\end{figure}%
832-
%
835+
836+
This test case is already successful, so we are not interested in it.
837+
Among the symbols in \menu{Debug} register, we click \pycharmDebuggerResume, which will let the program continue its execution~(\cref{fig:dunder:debug07}).
838+
Alternatively, we can hit \keys{F9}, which has the same effect.
839+
The execution of the \pglspl{doctest} is resumed, but again pauses at our \pgls{breakpoint}~(\cref{fig:dunder:debug08}).
840+
This time, we can see that we have arrived at the beginning of the second \pgls{doctest} case with \pythonil{Fraction(1, 2)}.
841+
We again continue by clicking \pycharmDebuggerResume\ or pressing~\keys{F9}.
842+
This takes us to the beginning of the third \pgls{doctest} case, where the fraction is~$\frac{1}{3}$ and \pythonil{max_frac} is~\pythonil{10}~(\cref{fig:dunder:debug09}).
843+
We can skip it as well by pressing~\keys{F9}.
844+
The next time we reach the \pgls{breakpoint} is for the fourth \pgls{doctest} case, $\frac{-101001}{100000000}$~(\cref{fig:dunder:debug10}), which we skip, too.
845+
When the debugger arrives at the fifth test case, \pythonil{Fraction(1235, 1000)}, we find that this fraction has been normalized correctly to~$\frac{247}{200}$.
846+
Nonetheless, we can skip this test case via \keys{F9}, too, because we know that it will succeed~(\cref{fig:dunder:debug11}).
847+
This takes us to the last successful \pgls{doctest} case, \pythonil{Fraction(99995, 100000)}, which corresponds to~$\frac{19999}{20000}$ in \cref{fig:dunder:debug12}.
848+
After skipping it by pressing~\pycharmDebuggerResume, we will finally arrive at the cases that did fail and which we hence want to investigate step-by-step.%
849+
\clearpage%
833850
%
834851
\begin{figure}%
835852
\ContinuedFloat%
836853
\centering%
837854
%
838855
\subfloat[][%
839-
Using the \debugger\ in \pycharm.%
856+
We arrive at the beginning of the failing \pgls{doctest} case \pythonil{Fraction(91995, 100000).decimal_str(3)}. %
857+
The \pythonil{max_frac} parameter has value~\pythonil{3}, \pythonil{self.a} is \pythonil{18399} and \pythonil{self.b} is \pythonil{20000}, because the fraction was normalized in \pythonil{\_\_init\_\_}.%
840858
\label{fig:dunder:debug13}%
841859
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug13}}}%
842860
%
843861
\strut\hfill\strut%
844862
%
845863
\subfloat[][%
846-
Using the \debugger\ in \pycharm.%
864+
We now execute the first line of the \pythonil{decimal_str} function where the \pgls{debugger} has paused. %
865+
This is done by either pressing the \pycharmDebuggerStepOver~button or by hitting~\keys{F8}.%
847866
\label{fig:dunder:debug14}%
848867
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug14}}}%
849868
%
850869
\\[10pt]%
851870
%
852871
\subfloat[][%
853-
Using the \debugger\ in \pycharm.%
872+
The execution of the assignment \pythonil{a = self.a} creates a new local variable~\pythonil{a} with value~\pythonil{18399}. %
873+
We press \keys{F8} to continue the execution.%
854874
\label{fig:dunder:debug15}%
855875
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug15}}}%
856876
%
857877
\strut\hfill\strut%
858878
%
859879
\subfloat[][%
860-
Using the \debugger\ in \pycharm.%
880+
The condition for the \pythonil{if} is not met, so the execution jumps over its body and the next line after the \pythonil{if} is marked. %
881+
We execute it by pressing~\pythonil{F8}.%
861882
\label{fig:dunder:debug16}%
862883
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug16}}}%
863884
%
864885
\\[10pt]%
865886
%
866887
\subfloat[][%
867-
Using the \debugger\ in \pycharm.%
888+
The new local variable~\pythonil{negative} with value~\pythonil{False} appears. %
889+
The next line of code is marked and we execute it by pressing~\pycharmDebuggerStepOver.%
868890
\label{fig:dunder:debug17}%
869891
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug17}}}%
870892
%
871893
\strut\hfill\strut%
872894
%
873895
\subfloat[][%
874-
Using the \debugger\ in \pycharm.%
896+
\pythonil{a = abs(a)} has no effect, since \pythonil{a} is already positive.
897+
We press \keys{F8} to continue.%
875898
\label{fig:dunder:debug18}%
876899
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug18}}}%
877900
%
@@ -880,27 +903,57 @@
880903
\label{fig:dunder:debugC}%
881904
\end{figure}%
882905
%
906+
\begin{sloppypar}%
907+
\Cref{fig:dunder:debug13} shows that we now arrived at the beginning of the failing \pgls{doctest} case \pythonil{Fraction(91995, 100000).decimal_str(3)}.
908+
The fraction~$\frac{91995}{100000}$ got normalized to~$\frac{18399}{20000}$ in the initializer~\pythonil{\_\_init\_\_}.
909+
The parameter \pythonil{max_frac} of \pythonil{decimal_str} has the value~\pythonil{3}, as we can see in the \menu{Threads \& Variables} window.
910+
We now want to execute the \pythonil{decimal_str} method step-by-step.
911+
Right now, the \pgls{debugger} has paused the execution right at the very first line of this function.
912+
This line has not yet been executed.%
913+
\end{sloppypar}%
883914
%
915+
In \cref{fig:dunder:debug14}, we execute this line of code, either by pressing the \pycharmDebuggerStepOver~button or by hitting~\keys{F8}.
916+
We can see in \cref{fig:dunder:debug15} that now a new variable has appeared in the \menu{Threads \& Variables} window.
917+
Since we executed \pythonil{a = self.a}, the local variable~\pythonil{a} now exists and has value~\pythonil{18399}.
918+
Now, the next line of code that can be executed is marked with blue color.
919+
920+
By pressing \keys{F8}, the \pythonil{if a == 0:} is executed.
921+
Since \pythonil{a == 0} is not \pythonil{True}, the body of the \pythonil{if} is not executed.
922+
The program jumps right over it.
923+
The next line after the \pythonil{if} is marked~\cref{fig:dunder:debug16}.
924+
We execute it by pressing~\keys{F8}.
925+
926+
The local variable \pythonil{negative} is created.
927+
Since \pythonil{a < 0} is \pythonil{False}, \pythonil{negative} is \pythonil{False}, too.
928+
The next line of code is marked and we press~\pycharmDebuggerStepOver\ to execute it~(\cref{fig:dunder:debug17}).
929+
930+
\pythonil{a = abs(a)} has no effect, since \pythonil{a} is already positive.
931+
We press \keys{F8} to continue~(\cref{fig:dunder:debug18}).
932+
884933
\begin{figure}%
885934
\ContinuedFloat%
886935
\centering%
887936
%
888937
\subfloat[][%
889-
Using the \debugger\ in \pycharm.%
938+
After executing \pythonil{b = self.b}, the new local variable \pythonil{b} with value \pythonil{20000} comes into existence. %
939+
We continue debugging by pressing~\keys{F8}.%
890940
\label{fig:dunder:debug19}%
891941
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug19}}}%
892942
%
893943
\strut\hfill\strut%
894944
%
895945
\subfloat[][%
896-
Using the \debugger\ in \pycharm.%
946+
The empty list \pythonil{digits} has been created. %
947+
By pressing~\keys{F8}, the executing \pythonil{while} loop will begin by checking its condition.%
897948
\label{fig:dunder:debug20}%
898949
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug20}}}%
899950
%
900951
\\[10pt]%
901952
%
902953
\subfloat[][%
903-
Using the \debugger\ in \pycharm.%
954+
The condition of the \pythonil{while} loop is met. %
955+
The first line of the loop's body is marked. %
956+
We press~\pycharmDebuggerStepOver\ to execute it.%
904957
\label{fig:dunder:debug21}%
905958
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug21}}}%
906959
%
@@ -927,9 +980,23 @@
927980
%
928981
\caption{Using the \debugger\ in \pycharm.}%
929982
\label{fig:dunder:debugD}%
930-
\end{figure}%
931-
%
932-
%
983+
\end{figure}
984+
985+
This executes \pythonil{b = self.b}.
986+
Thus, the new local variable \pythonil{b} with value \pythonil{20000} is created in~\cref{fig:dunder:debug19}.
987+
We are now at the last line of \inQuotes{trivial setup} of our \pythonil{decimal_str} method, the creation of the list~\pythonil{digits}.
988+
We continue debugging by pressing~\keys{F8}.
989+
990+
The new variable~\pythonil{digits} has indeed appeared in~\cref{fig:dunder:debug20}.
991+
It is an empty list~\pythonil{[]}.
992+
We arrived at the beginning the \pythonil{while} loop.
993+
We press \keys{F8}, which will cause the condition of the loop being checked.
994+
995+
In \cref{fig:dunder:debug21}, we find that now the first line of the loop's body is marked.
996+
This means that \pythonil{a != 0} and \pythonil{len(digits) <= max_frac} are both~\pythonil{True}.
997+
And they should be, since \pythonil{a} is \pythonil{18399}, \pythonil{len(digits)} if~0, and \pythonil{max_frac} is~3.
998+
We press~\pycharmDebuggerStepOver.
999+
9331000
\begin{figure}%
9341001
\ContinuedFloat%
9351002
\centering%

0 commit comments

Comments
 (0)