Skip to content

Commit 0e65621

Browse files
committed
Fix a few typos and one case of bad indentation
1 parent 496df5b commit 0e65621

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

01-testing-exceptions.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<h2 class="subtitle">Exceptions</h2>
3131
<section class="objectives panel panel-warning">
3232
<div class="panel-heading">
33-
<h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
33+
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
3434
</div>
3535
<div class="panel-body">
3636
<ul>
@@ -194,7 +194,7 @@ <h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></spa
194194
<span class="kw">except</span> <span class="ot">ValueError</span>:
195195
<span class="kw">return</span> numpy.array([])
196196
<span class="kw">except</span> <span class="ot">TypeError</span>:
197-
<span class="kw">raise</span> <span class="ot">TypeError</span>(<span class="st">&#39;Can only re-scale numerical data.&#39;</span>)
197+
<span class="kw">raise</span> <span class="ot">TypeError</span>(<span class="st">&#39;Can only re-scale numerical data.&#39;</span>)
198198
data_max = numpy.<span class="dt">max</span>(data)
199199
<span class="kw">if</span> not data_max &gt; data_min:
200200
<span class="kw">raise</span> <span class="ot">ValueError</span>(<span class="st">&#39;Cannot rescale data: all values are identical.&#39;</span>)
@@ -241,15 +241,15 @@ <h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></spa
241241
TypeError: Can only re-scale numerical data.</code></pre>
242242
<section class="challenge panel panel-success">
243243
<div class="panel-heading">
244-
<h2 id="catch-all"><span class="glyphicon glyphicon-pencil"></span>Catch all</h2>
244+
<h2><span class="glyphicon glyphicon-pencil"></span>Catch all</h2>
245245
</div>
246246
<div class="panel-body">
247247
<p>Sometimes it is not obvious what type of exception to catch and an easy solution seems to be to catch <em>any</em> exception with <code>except Exception</code>. Why is this not a good idea?</p>
248248
</div>
249249
</section>
250250
<section class="challenge panel panel-success">
251251
<div class="panel-heading">
252-
<h2 id="checking-or-trying"><span class="glyphicon glyphicon-pencil"></span>Checking or trying?</h2>
252+
<h2><span class="glyphicon glyphicon-pencil"></span>Checking or trying?</h2>
253253
</div>
254254
<div class="panel-body">
255255
<p>What is the advantage of using <code>try</code>/<code>except</code> over an explicit type check? Compare these two functions that return the minimum and maximum as a tuple:</p>

01-testing-exceptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def rescale(data, lower=0.0, upper=1.0):
244244
except ValueError:
245245
return numpy.array([])
246246
except TypeError:
247-
raise TypeError('Can only re-scale numerical data.')
247+
raise TypeError('Can only re-scale numerical data.')
248248
data_max = numpy.max(data)
249249
if not data_max > data_min:
250250
raise ValueError('Cannot rescale data: all values are identical.')

03-testing-units.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<h2 class="subtitle">Unit Tests</h2>
3131
<section class="objectives panel panel-warning">
3232
<div class="panel-heading">
33-
<h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
33+
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
3434
</div>
3535
<div class="panel-body">
3636
<ul>
@@ -46,14 +46,14 @@ <h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></spa
4646
<li>We are still not sure the result is actually correct! We cannot test the correctness of the solution in the function itself, because for that we’d need a solution for all possible inputs – if we already had this, we’d not need the function in the first place…</li>
4747
<li>We do not know whether the code works before we actually run it. The assertions might guard us against incorrect results (which is already great) but it would be better to have some more confidence in our code before we, say, run it overnight to analyse our data.</li>
4848
</ol>
49-
<p>This is where unit tests come in. Unit tests are so called because they exercise the functionality of the code by interrogating individual functions and methods. Fuctions and methods can often be considered the atomic units of software because they are indivisble. However, what is considered to be the smallest code <em>unit</em> is subjective. The body of a function can be long or short, and shorter functions are arguably more unit-like than long ones.</p>
49+
<p>This is where unit tests come in. Unit tests are so called because they exercise the functionality of the code by interrogating individual functions and methods. Functions and methods can often be considered the atomic units of software because they are indivisible. However, what is considered to be the smallest code <em>unit</em> is subjective. The body of a function can be long or short, and shorter functions are arguably more unit-like than long ones.</p>
5050
<p>Thus what reasonably constitutes a code unit typically varies from project to project and language to language. A good guideline is that if the code cannot be made any simpler logically (you cannot split apart the addition operator) or practically (a function is self-contained and well defined), then it is a unit.</p>
5151
<aside class="callout panel panel-info">
5252
<div class="panel-heading">
53-
<h2 id="functions-are-like-paragraphs"><span class="glyphicon glyphicon-pushpin"></span>Functions are Like Paragraphs</h2>
53+
<h2><span class="glyphicon glyphicon-pushpin"></span>Functions are Like Paragraphs</h2>
5454
</div>
5555
<div class="panel-body">
56-
<p>Recall that humans can only hold a few ideas in our heads at once. Paragraphs in books, for example, become unwieldy after a few lines. Functions, generaly, shouldn’t be longer than paragraphs. Robert C. Martin, the author of “Clean Code” said : “The first rule of functions is that <em>they should be small</em>. The second rule of functions is that <em>they should be smaller than that</em>.”</p>
56+
<p>Recall that humans can only hold a few ideas in our heads at once. Paragraphs in books, for example, become unwieldy after a few lines. Functions, generally, shouldn’t be longer than paragraphs. Robert C. Martin, the author of “Clean Code” said : “The first rule of functions is that <em>they should be small</em>. The second rule of functions is that <em>they should be smaller than that</em>.”</p>
5757
</div>
5858
</aside>
5959
<p>The desire to unit test code often has the effect of encouraging both the code and the tests to be as small, well-defined, and modular as possible.<br />In Python, unit tests typically take the form of test functions that call and make assertions about methods and functions in the code base. To run these test functions, a test framework is often required to collect them together. For now, we’ll write some tests for the rescale function and simply run them individually to see whether they fail. In the next session, we’ll use a test framework to collect and run them.</p>
@@ -69,7 +69,7 @@ <h2 id="unit-tests-are-just-functions">Unit Tests Are Just Functions</h2>
6969
<p>When writing such unit tests, special care should be taken to test <em>edge cases</em>, i.e. what happens at the boundaries of the input space. A function may assume a positive value for one of its argument, but what happens if it is 0? Or negative? Another typical edge case is an empty list or array as an argument. Often you will think about those cases only when writing the tests which then forces you to make a decision about how to handle the edge case (which you should then of course include in your function documentation). For example, what should <code>rescale</code> do for an empty array, should it raise an error or should it maybe rather return another empty array?</p>
7070
<section class="challenge panel panel-success">
7171
<div class="panel-heading">
72-
<h2 id="write-a-file-full-of-tests"><span class="glyphicon glyphicon-pencil"></span>Write a File Full of Tests</h2>
72+
<h2><span class="glyphicon glyphicon-pencil"></span>Write a File Full of Tests</h2>
7373
</div>
7474
<div class="panel-body">
7575
<ol style="list-style-type: decimal">

03-testing-units.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ run it overnight to analyse our data.
2727

2828
This is where unit tests come in.
2929
Unit tests are so called because they exercise the functionality of the code by
30-
interrogating individual functions and methods. Fuctions and methods can often
31-
be considered the atomic units of software because they are indivisble.
30+
interrogating individual functions and methods. Functions and methods can often
31+
be considered the atomic units of software because they are indivisible.
3232
However, what is considered to be the smallest code _unit_ is subjective. The
3333
body of a function can be long or short, and shorter functions are arguably
3434
more unit-like than long ones.
@@ -41,7 +41,7 @@ practically (a function is self-contained and well defined), then it is a unit.
4141
> ## Functions are Like Paragraphs {.callout}
4242
>
4343
> Recall that humans can only hold a few ideas in our heads at once. Paragraphs
44-
> in books, for example, become unwieldy after a few lines. Functions, generaly,
44+
> in books, for example, become unwieldy after a few lines. Functions, generally,
4545
> shouldn't be longer than paragraphs.
4646
> Robert C. Martin, the author of "Clean Code" said : "The first rule of
4747
> functions is that _they should be small_. The second rule of functions is that

0 commit comments

Comments
 (0)