Skip to content

Commit 51febae

Browse files
committed
remove test part
1 parent a6105fb commit 51febae

File tree

3 files changed

+111
-70
lines changed

3 files changed

+111
-70
lines changed

05_functions.ipynb

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
{
2222
"cell_type": "code",
2323
"execution_count": null,
24-
"metadata": {},
24+
"metadata": {
25+
"collapsed": true
26+
},
2527
"outputs": [],
2628
"source": [
2729
"# This line does not belong to the function \n",
@@ -36,7 +38,9 @@
3638
{
3739
"cell_type": "code",
3840
"execution_count": null,
39-
"metadata": {},
41+
"metadata": {
42+
"collapsed": true
43+
},
4044
"outputs": [],
4145
"source": [
4246
"def grow(height):\n",
@@ -72,7 +76,9 @@
7276
{
7377
"cell_type": "code",
7478
"execution_count": null,
75-
"metadata": {},
79+
"metadata": {
80+
"collapsed": true
81+
},
7682
"outputs": [],
7783
"source": [
7884
"def subtract(a, b):\n",
@@ -91,7 +97,9 @@
9197
{
9298
"cell_type": "code",
9399
"execution_count": null,
94-
"metadata": {},
100+
"metadata": {
101+
"collapsed": true
102+
},
95103
"outputs": [],
96104
"source": [
97105
"spam = 10\n",
@@ -102,7 +110,9 @@
102110
{
103111
"cell_type": "code",
104112
"execution_count": null,
105-
"metadata": {},
113+
"metadata": {
114+
"collapsed": true
115+
},
106116
"outputs": [],
107117
"source": [
108118
"a = 10\n",
@@ -137,7 +147,9 @@
137147
{
138148
"cell_type": "code",
139149
"execution_count": null,
140-
"metadata": {},
150+
"metadata": {
151+
"collapsed": true
152+
},
141153
"outputs": [],
142154
"source": [
143155
"def issue_fine(amount = 750):\n",
@@ -159,7 +171,9 @@
159171
{
160172
"cell_type": "code",
161173
"execution_count": null,
162-
"metadata": {},
174+
"metadata": {
175+
"collapsed": true
176+
},
163177
"outputs": [],
164178
"source": [
165179
"def what_happens_after_return():\n",
@@ -185,7 +199,9 @@
185199
{
186200
"cell_type": "code",
187201
"execution_count": null,
188-
"metadata": {},
202+
"metadata": {
203+
"collapsed": true
204+
},
189205
"outputs": [],
190206
"source": [
191207
"import requests\n",
@@ -200,66 +216,6 @@
200216
"for case in cases:\n",
201217
" #your code here"
202218
]
203-
},
204-
{
205-
"cell_type": "markdown",
206-
"metadata": {},
207-
"source": [
208-
"## Test Functions\n",
209-
"\n",
210-
"We can use test functions to check that our functions work.\n",
211-
"If everything works, the test function is *quiet*, printing nothing. But if a test fails, the test function yields an `Error`, like `AssertionError`.\n",
212-
"\n",
213-
"\n",
214-
"```\n",
215-
"def f(x):\n",
216-
" y = ...\n",
217-
" return y\n",
218-
"\n",
219-
"def test_f():\n",
220-
" x_value = ...\n",
221-
" expected = ...\n",
222-
" computed = f(x_value)\n",
223-
" tol = 1e-12\n",
224-
" success = abs(expected - computed) < tol\n",
225-
" assert success\n",
226-
"\n",
227-
"test_f()\n",
228-
"```\n",
229-
"\n",
230-
"The test function has the *same* name as the function to be tested, with the *prefix* `test_`.\n",
231-
"A test function does *not* have any parameters, nor does it return anything. It uses `assert` to test that the function behaves as it should.\n",
232-
"\n",
233-
"### `expected` \n",
234-
"`expected` is the correct value that the function should return. *Never* use the function to be tested to find `expected`, since that would defeat the purpose of the test.\n",
235-
"\n",
236-
"### `computed`\n",
237-
"`computed` is *always* calculated by the function you are testing. Call the function with the parameters it needs.\n",
238-
"\n",
239-
"### `success`\n",
240-
"`success` is a `Boolean`, that is `True` eller `False`. \n",
241-
"Here we compare the `expected` value with the `computed` result.\n",
242-
"If the function returns a `float`, we must check that `expected` and `computed` are within a small tolerance, because floating-point values are imprecise. We will not get into that here.\n",
243-
"\n",
244-
"### `assert`\n",
245-
"`assert` checks that something is `True`.\n",
246-
"If the expression after `assert` is `True`, nothing happens and the test passes.\n",
247-
"If the expression is `False`, we get an `AssertionError`, and the test fails.\n",
248-
"You can have several assertions in the same function.\n"
249-
]
250-
},
251-
{
252-
"cell_type": "code",
253-
"execution_count": null,
254-
"metadata": {
255-
"scrolled": true
256-
},
257-
"outputs": [],
258-
"source": [
259-
"assert True, \"This will not be printed, as you are asserting True\"\n",
260-
"assert False, \"This will be printed, as you are asserting False\"\n",
261-
"print(\"This will not be printed, as the line above will terminate the program.\")"
262-
]
263219
}
264220
],
265221
"metadata": {
@@ -278,7 +234,7 @@
278234
"name": "python",
279235
"nbconvert_exporter": "python",
280236
"pygments_lexer": "ipython3",
281-
"version": "3.6.8"
237+
"version": "3.6.3"
282238
}
283239
},
284240
"nbformat": 4,

originals/Python_03_functions.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@
397397
"name": "python",
398398
"nbconvert_exporter": "python",
399399
"pygments_lexer": "ipython3",
400-
"version": "3.6.8"
400+
"version": "3.6.3"
401401
}
402402
},
403403
"nbformat": 4,

x0_test.ipynb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Test Functions\n",
8+
"\n",
9+
"We can use test functions to check that our functions work.\n",
10+
"If everything works, the test function is *quiet*, printing nothing. But if a test fails, the test function yields an `Error`, like `AssertionError`.\n",
11+
"\n",
12+
"\n",
13+
"```\n",
14+
"def f(x):\n",
15+
" y = ...\n",
16+
" return y\n",
17+
"\n",
18+
"def test_f():\n",
19+
" x_value = ...\n",
20+
" expected = ...\n",
21+
" computed = f(x_value)\n",
22+
" tol = 1e-12\n",
23+
" success = abs(expected - computed) < tol\n",
24+
" assert success\n",
25+
"\n",
26+
"test_f()\n",
27+
"```\n",
28+
"\n",
29+
"The test function has the *same* name as the function to be tested, with the *prefix* `test_`.\n",
30+
"A test function does *not* have any parameters, nor does it return anything. It uses `assert` to test that the function behaves as it should.\n",
31+
"\n",
32+
"### `expected` \n",
33+
"`expected` is the correct value that the function should return. *Never* use the function to be tested to find `expected`, since that would defeat the purpose of the test.\n",
34+
"\n",
35+
"### `computed`\n",
36+
"`computed` is *always* calculated by the function you are testing. Call the function with the parameters it needs.\n",
37+
"\n",
38+
"### `success`\n",
39+
"`success` is a `Boolean`, that is `True` eller `False`. \n",
40+
"Here we compare the `expected` value with the `computed` result.\n",
41+
"If the function returns a `float`, we must check that `expected` and `computed` are within a small tolerance, because floating-point values are imprecise. We will not get into that here.\n",
42+
"\n",
43+
"### `assert`\n",
44+
"`assert` checks that something is `True`.\n",
45+
"If the expression after `assert` is `True`, nothing happens and the test passes.\n",
46+
"If the expression is `False`, we get an `AssertionError`, and the test fails.\n",
47+
"You can have several assertions in the same function."
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {
54+
"collapsed": true
55+
},
56+
"outputs": [],
57+
"source": [
58+
"assert True, \"This will not be printed, as you are asserting True\"\n",
59+
"assert False, \"This will be printed, as you are asserting False\"\n",
60+
"print(\"This will not be printed, as the line above will terminate the program.\")"
61+
]
62+
}
63+
],
64+
"metadata": {
65+
"kernelspec": {
66+
"display_name": "Python 3",
67+
"language": "python",
68+
"name": "python3"
69+
},
70+
"language_info": {
71+
"codemirror_mode": {
72+
"name": "ipython",
73+
"version": 3
74+
},
75+
"file_extension": ".py",
76+
"mimetype": "text/x-python",
77+
"name": "python",
78+
"nbconvert_exporter": "python",
79+
"pygments_lexer": "ipython3",
80+
"version": "3.6.3"
81+
}
82+
},
83+
"nbformat": 4,
84+
"nbformat_minor": 2
85+
}

0 commit comments

Comments
 (0)