You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the practical details of including tests in your code here.</p>
622
622
<p>There are a number of Python packages which support code testing. The
623
623
concepts are largely similar so rather than get bogged down in the
624
-
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.0.1.dev152+g91dbdb60)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
624
+
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.0.1.dev168+g4df39e3a)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
625
625
<divclass="section" id="pytest-tests">
626
626
<h3><spanclass="section-number">2.7.1. </span>Pytest tests<aclass="headerlink" href="#pytest-tests" title="Permalink to this headline">¶</a></h3>
627
627
<p>A Pytest test is simply a function whose name starts with <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">test_</span></code>. In
Copy file name to clipboardExpand all lines: 4_abstract_data_types.html
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@
50
50
<divclass="body" role="main">
51
51
52
52
<divclass="section" id="abstract-data-types">
53
-
<h1><spanclass="section-number">5. </span>Abstract data types<aclass="headerlink" href="#abstract-data-types" title="Permalink to this headline">¶</a></h1>
53
+
<spanid="id1"></span><h1><spanclass="section-number">5. </span>Abstract data types<aclass="headerlink" href="#abstract-data-types" title="Permalink to this headline">¶</a></h1>
54
54
<p>In <aclass="reference internal" href="2_objects.html#objects"><spanclass="std std-numref">Section 3</span></a>, we introduced the concept of <aclass="reference internal" href="2_objects.html#term-type"><spanclass="xref std std-term">type</span></a> as an
55
55
<aclass="reference internal" href="2_objects.html#term-abstraction"><spanclass="xref std std-term">abstraction</span></a> comprising a set of possible values, and a set of
56
56
operations. All types in Python are abstractions in this sense
@@ -59,7 +59,7 @@ <h1><span class="section-number">5. </span>Abstract data types<a class="headerli
59
59
define purely mathematical types, distinct from their concrete
60
60
realisation in code. Indeed, there are typically multiple possible
61
61
concrete realisations of a mathematical idea.</p>
62
-
<divclass="proof proof-type-definition" id="id2">
62
+
<divclass="proof proof-type-definition" id="id3">
63
63
64
64
<divclass="proof-title">
65
65
<spanclass="proof-type">Definition 5.1</span>
@@ -72,7 +72,7 @@ <h1><span class="section-number">5. </span>Abstract data types<a class="headerli
72
72
</div></div><p>That said, it will frequently be helpful in understanding abstract
73
73
data types to refer to the ways in which they might be implemented.</p>
74
74
<divclass="section" id="stacks">
75
-
<spanid="id1"></span><h2><spanclass="section-number">5.1. </span>Stacks<aclass="headerlink" href="#stacks" title="Permalink to this headline">¶</a></h2>
75
+
<spanid="id2"></span><h2><spanclass="section-number">5.1. </span>Stacks<aclass="headerlink" href="#stacks" title="Permalink to this headline">¶</a></h2>
76
76
<p>Possibly the simplest abstract data type which is not synonymous with
77
77
a Python type is the <aclass="reference internal" href="#term-stack"><spanclass="xref std std-term">stack</span></a>. A stack is a sequence of objects
78
78
in which only the most recently added object is accessible. The image
<spanid="rpcalc"></span><divclass="code-block-caption"><spanclass="caption-number">Listing 5.1 </span><spanclass="caption-text">Pseudocode for a reverse Polish calculator implemented
205
-
using a <aclass="reference internal" href="#term-stack"><spanclass="xref std std-term">stack</span></a></span><aclass="headerlink" href="#id3" title="Permalink to this code">¶</a></div>
205
+
using a <aclass="reference internal" href="#term-stack"><spanclass="xref std std-term">stack</span></a></span><aclass="headerlink" href="#id4" title="Permalink to this code">¶</a></div>
<caption><spanclass="caption-number">Table 5.1 </span><spanclass="caption-text">Evaluation of the reverse Polish expression
223
223
<codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">6</span><spanclass="pre">2</span><spanclass="pre">/</span><spanclass="pre">2</span><spanclass="pre">4</span><spanclass="pre">**</span><spanclass="pre">+</span></code> using a stack
224
-
(equivalent to <spanclass="math notranslate nohighlight">\(6/2 + 2^4 = 3 + 16 = 19\)</span>).</span><aclass="headerlink" href="#id4" title="Permalink to this table">¶</a></caption>
224
+
(equivalent to <spanclass="math notranslate nohighlight">\(6/2 + 2^4 = 3 + 16 = 19\)</span>).</span><aclass="headerlink" href="#id5" title="Permalink to this table">¶</a></caption>
225
225
<colgroup>
226
226
<colstyle="width: 46%" />
227
227
<colstyle="width: 15%" />
@@ -274,10 +274,10 @@ <h3><span class="section-number">5.1.2. </span>Implementing stacks in Python<a c
274
274
<p>While it is strictly true that Python does not have a stack type, the
275
275
<aclass="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.8)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">list</span></code></a> class functions as a perfectly good stack. The
276
276
relationship between the two is shown in <aclass="reference internal" href="#list-stack"><spanclass="std std-numref">Table 5.2</span></a>.</p>
<divclass="code-block-caption"><spanclass="caption-number">Listing 5.3 </span><spanclass="caption-text">A poorly designed stack implementation in which push and pop cost
398
398
<spanclass="math notranslate nohighlight">\(O(n)\)</span> operations, where <spanclass="math notranslate nohighlight">\(n\)</span> is the current
399
-
number of objects on the stack.</span><aclass="headerlink" href="#id7" title="Permalink to this code">¶</a></div>
399
+
number of objects on the stack.</span><aclass="headerlink" href="#id8" title="Permalink to this code">¶</a></div>
iteration. <aclass="reference internal" href="#iterating-linked-list"><spanclass="std std-numref">Listing 5.4</span></a> shows the code. The helper
768
768
class <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">LinkIterator</span></code> is never seen by the user, it’s just there
<spanid="iterating-linked-list"></span><divclass="code-block-caption"><spanclass="caption-number">Listing 5.4 </span><spanclass="caption-text">A simple linked list implementation that supports the iterator protocol.</span><aclass="headerlink" href="#id8" title="Permalink to this code">¶</a></div>
<spanid="iterating-linked-list"></span><divclass="code-block-caption"><spanclass="caption-number">Listing 5.4 </span><spanclass="caption-text">A simple linked list implementation that supports the iterator protocol.</span><aclass="headerlink" href="#id9" title="Permalink to this code">¶</a></div>
0 commit comments