|
787 | 787 | \centering% |
788 | 788 | % |
789 | 789 | \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}.% |
791 | 791 | \label{fig:dunder:debug07}% |
792 | 792 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug07}}}% |
793 | 793 | % |
794 | 794 | \strut\hfill\strut% |
795 | 795 | % |
796 | 796 | \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.% |
798 | 799 | \label{fig:dunder:debug08}% |
799 | 800 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug08}}}% |
800 | 801 | % |
801 | 802 | \\[10pt]% |
802 | 803 | % |
803 | 804 | \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}.% |
805 | 807 | \label{fig:dunder:debug09}% |
806 | 808 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug09}}}% |
807 | 809 | % |
808 | 810 | \strut\hfill\strut% |
809 | 811 | % |
810 | 812 | \subfloat[][% |
811 | | -Using the \debugger\ in \pycharm.% |
| 813 | +The fourth \pgls{doctest} case~$\frac{-101001}{100000000}$ can be skipped as well.% |
812 | 814 | \label{fig:dunder:debug10}% |
813 | 815 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug10}}}% |
814 | 816 | % |
815 | 817 | \\[10pt]% |
816 | 818 | % |
817 | 819 | \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.% |
819 | 821 | \label{fig:dunder:debug11}% |
820 | 822 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug11}}}% |
821 | 823 | % |
822 | 824 | \strut\hfill\strut% |
823 | 825 | % |
824 | 826 | \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}.% |
826 | 829 | \label{fig:dunder:debug12}% |
827 | 830 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug12}}}% |
828 | 831 | % |
829 | 832 | \caption{Using the \debugger\ in \pycharm.}% |
830 | 833 | \label{fig:dunder:debugB}% |
831 | 834 | \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% |
833 | 850 | % |
834 | 851 | \begin{figure}% |
835 | 852 | \ContinuedFloat% |
836 | 853 | \centering% |
837 | 854 | % |
838 | 855 | \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\_\_}.% |
840 | 858 | \label{fig:dunder:debug13}% |
841 | 859 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug13}}}% |
842 | 860 | % |
843 | 861 | \strut\hfill\strut% |
844 | 862 | % |
845 | 863 | \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}.% |
847 | 866 | \label{fig:dunder:debug14}% |
848 | 867 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug14}}}% |
849 | 868 | % |
850 | 869 | \\[10pt]% |
851 | 870 | % |
852 | 871 | \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.% |
854 | 874 | \label{fig:dunder:debug15}% |
855 | 875 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug15}}}% |
856 | 876 | % |
857 | 877 | \strut\hfill\strut% |
858 | 878 | % |
859 | 879 | \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}.% |
861 | 882 | \label{fig:dunder:debug16}% |
862 | 883 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug16}}}% |
863 | 884 | % |
864 | 885 | \\[10pt]% |
865 | 886 | % |
866 | 887 | \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.% |
868 | 890 | \label{fig:dunder:debug17}% |
869 | 891 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug17}}}% |
870 | 892 | % |
871 | 893 | \strut\hfill\strut% |
872 | 894 | % |
873 | 895 | \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.% |
875 | 898 | \label{fig:dunder:debug18}% |
876 | 899 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug18}}}% |
877 | 900 | % |
|
880 | 903 | \label{fig:dunder:debugC}% |
881 | 904 | \end{figure}% |
882 | 905 | % |
| 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}% |
883 | 914 | % |
| 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 | + |
884 | 933 | \begin{figure}% |
885 | 934 | \ContinuedFloat% |
886 | 935 | \centering% |
887 | 936 | % |
888 | 937 | \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}.% |
890 | 940 | \label{fig:dunder:debug19}% |
891 | 941 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug19}}}% |
892 | 942 | % |
893 | 943 | \strut\hfill\strut% |
894 | 944 | % |
895 | 945 | \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.% |
897 | 948 | \label{fig:dunder:debug20}% |
898 | 949 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug20}}}% |
899 | 950 | % |
900 | 951 | \\[10pt]% |
901 | 952 | % |
902 | 953 | \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.% |
904 | 957 | \label{fig:dunder:debug21}% |
905 | 958 | ]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/debug21}}}% |
906 | 959 | % |
|
927 | 980 | % |
928 | 981 | \caption{Using the \debugger\ in \pycharm.}% |
929 | 982 | \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 | + |
933 | 1000 | \begin{figure}% |
934 | 1001 | \ContinuedFloat% |
935 | 1002 | \centering% |
|
0 commit comments