Commit d7af8f8a authored by paugier's avatar paugier
Browse files

Remove unittest in 030_functions.ipynb

parent 60942cbb
......@@ -25,13 +25,13 @@
``` python
def print_hello():
"hello printer"
print('hello')
def myprint(s):
def myprint(my_var):
"my hello printer"
print('I print', s)
print('I print', my_var)
# function calls
print_hello()
print_hello()
myprint('First call of myprint')
......@@ -49,26 +49,15 @@
%% Cell type:code id: tags:
``` python
import unittest
def add(arg0, arg1):
"""Print and return the sum of the two arguments (duck typing)."""
result = arg0 + arg1
print('result = ', result)
return result
class TestMyStuff(unittest.TestCase):
def test_add(self):
""" test max_temp computes correctly"""
self.assertEqual(8, add(3, 5))
self.assertEqual("aabb", add("aa", "bb"))
_res = unittest.TextTestRunner(verbosity=2).run(unittest.TestLoader().loadTestsFromTestCase(TestMyStuff0))
```
%% Cell type:code id: tags:
``` python
......@@ -96,31 +85,19 @@
Write a function that returns the sum of the first argument with twice the second argument.
%% Cell type:code id: tags:
``` python
import unittest
def add_second_twice(arg0, arg1):
"""Return the sum of the first argument with twice the second one.
Arguments should be of type that support sum and product by
an integer (e.g. numerical, string, list, ...)
:param arg0: first argument
:param arg1: second argument
:return: arg0 + 2 * arg1
"""
pass
class TestMyStuff0(unittest.TestCase):
def test_add_second_twice(self):
""" test max_temp computes correctly"""
self.assertEqual(13, add_second_twice(3, 5))
self.assertEqual("aabbbb", add_second_twice("aa", "bb"))
self.assertListEqual([1, 2, 3, 4, 3, 4], add_second_twice([1, 2], [3, 4]))
_res = unittest.TextTestRunner(verbosity=2).run(unittest.TestLoader().loadTestsFromTestCase(TestMyStuff0))
```
%% Cell type:markdown id: tags:
### Do it yourself: simple function definition
......@@ -140,21 +117,25 @@
"""
result = arg0 + 2*arg1
print(f'arg0 + 2*arg1 = {arg0} + 2*{arg1} = {result}')
return result
myfunc(4, 6)
assert 13 == add_second_twice(3, 5)
assert "aabbbb" == add_second_twice("aa", "bb")
assert [1, 2, 3, 4, 3, 4] == add_second_twice([1, 2], [3, 4])
add_second_twice(4, 6)
```
%%%% Output: execute_result
16
%% Cell type:code id: tags:
``` python
myfunc('a', 'b')
add_second_twice('a', 'b')
```
%%%% Output: execute_result
'abb'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment