-
Notifications
You must be signed in to change notification settings - Fork 283
/
add_one_and_multiply.py
55 lines (34 loc) · 1.5 KB
/
add_one_and_multiply.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def add_one_and_multiply(a, x):
""" Add 1 to a, and multiply by x"""
### YOUR CODE GOES HERE
# Replace "None" with the correct expression
r = None
### DO NOT MODIFY THE FOLLOWING LINE!
return r
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
sys.path.append('../')
import test_utils as utils
def do_test_add_one_and_multiply(a, x, expected):
recreate_msg = utils.gen_recreate_msg("add_one_and_multiply", *(a, x))
actual = add_one_and_multiply(a, x)
utils.check_none(actual, recreate_msg)
utils.check_type(actual, expected, recreate_msg)
utils.check_equals(actual, expected, recreate_msg)
def test_add_one_and_multiply_1():
do_test_add_one_and_multiply(a=0, x=0, expected=0)
def test_add_one_and_multiply_2():
do_test_add_one_and_multiply(a=5, x=2, expected=12)
def test_add_one_and_multiply_3():
do_test_add_one_and_multiply(a=5, x=0, expected=0)
def test_add_one_and_multiply_4():
do_test_add_one_and_multiply(a=9, x=1, expected=10)
def test_add_one_and_multiply_5():
do_test_add_one_and_multiply(a=9, x=-2, expected=-20)
def test_add_one_and_multiply_6():
do_test_add_one_and_multiply(a=-11, x=2, expected=-20)