-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathcount_greater_than_val.py
56 lines (36 loc) · 1.72 KB
/
count_greater_than_val.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
56
def count_greater_than_val(lst, val):
"""
Count the number of numbers in the list that are strictly greater than the value of val.
"""
### EXERCISE 5 -- 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.
n = None
### DO NOT MODIFY THE FOLLOWING LINE!
return n
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
sys.path.append('../')
import test_utils as utils
def do_test_count_greater_than_val(lst, val, expected):
recreate_msg = utils.gen_recreate_msg("count_greater_than_val", *(lst, val))
actual = count_greater_than_val(lst, val)
utils.check_none(actual, recreate_msg)
utils.check_type(actual, expected, recreate_msg)
utils.check_equals(actual, expected, recreate_msg)
def test_count_greater_than_val_1():
do_test_count_greater_than_val(lst=[1, 2, 3, 4], val=0, expected=4)
def test_count_greater_than_val_2():
do_test_count_greater_than_val(lst=[-1, -2, -3, -4], val=0, expected=0)
def test_count_greater_than_val_3():
do_test_count_greater_than_val(lst=[-1, 2, -3, 4], val=0, expected=2)
def test_count_greater_than_val_4():
do_test_count_greater_than_val(lst=[1, 10, 11, 2, 12, 13], val=10, expected=3)
def test_count_greater_than_val_5():
do_test_count_greater_than_val(lst=[], val=10, expected=0)