forked from uchicago-cs/python-practice-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegate_list.py
More file actions
54 lines (36 loc) · 1.52 KB
/
negate_list.py
File metadata and controls
54 lines (36 loc) · 1.52 KB
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
def negate_list(lst):
"""
Produce a *new* list with its values negated
"""
### EXERCISE 6 -- YOUR CODE GOES HERE
# Replace the following line with your code.
# After running your code, variable n should contain the value
# we ask you to compute in this exercise
new_lst = None
### DO NOT MODIFY THE FOLLOWING LINE!
return new_lst
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
sys.path.append('../')
import test_utils as utils
def do_test_negate_list(lst, expected):
recreate_msg = utils.gen_recreate_msg("negate_list", *(lst,))
lst_copy = lst[:]
actual = negate_list(lst)
utils.check_none(actual, recreate_msg)
utils.check_type(actual, expected, recreate_msg)
utils.check_equals(actual, expected, recreate_msg)
utils.check_list_unmodified("lst", before=lst_copy, after=lst)
def test_negate_list_1():
do_test_negate_list(lst=[1, 2, 3, 4], expected=[-1, -2, -3, -4])
def test_negate_list_2():
do_test_negate_list(lst=[-1, -2, -3, -4], expected=[1, 2, 3, 4])
def test_negate_list_3():
do_test_negate_list(lst=[-1, 2, -3, 4], expected=[1, -2, 3, -4])
def test_negate_list_4():
do_test_negate_list(lst=[], expected=[])