forked from rajnathani/bacon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_invert_actor_dict.py
78 lines (59 loc) · 2.93 KB
/
test_invert_actor_dict.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import nose
import bacon_functions
from test_parse_actor_data import sort_dict_values
def test_empty_dict():
'''Test with an empty dictionary.
'''
program_output = bacon_functions.invert_actor_dict({})
assert program_output == {},\
'Empty dictionary test'
def test_empty_dict_value():
'''Test with a single key dictionary mapping onto
the empty list (value).
'''
program_output = bacon_functions.invert_actor_dict({'cake': []})
assert program_output == {},\
'Empty dictionary value test'
def test_single_key_single_value_dict():
'''Test with a single key dictionary which is the
empty string.
'''
program_output = bacon_functions.invert_actor_dict({'tart': ['sugar']})
assert program_output == {'sugar': ['tart']},\
'Empty string key (dictionary) test'
def test_single_key_multiple_values_dict():
'''Test with a dictionary containing a single key, with multiple
items in the list (value) which it maps to.
'''
program_output = bacon_functions.invert_actor_dict({'cake': ['icing','cherry']})
correct_output = { 'icing': ['cake'], 'cherry': ['cake'] }
assert program_output == correct_output,\
'Single key multiple value list dictionary test'
def test_multiple_key_multiple_unique_values_dict():
'''Test with a dictionary containing multiple keys, with multiple
distinct items in the list (value) which they map to.
'''
D = { 'salad': ['lettuce','dressing','broccoli'], 'sandwich': [ 'ham', 'cheese'] }
program_output = bacon_functions.invert_actor_dict(D)
correct_output = { 'lettuce': ['salad'], 'dressing': ['salad'], 'broccoli':
['salad'], 'ham': ['sandwich'], 'cheese': ['sandwich'] }
assert program_output == correct_output,\
'Multiple key multiple (distinct) value list dictionary test'
def test_multiple_key_multiple_overlapping_values_dict():
'''Test with a dictionary containing multiple keys, with multiple
overlapping items in the list (value) which they map to.
'''
D = { 'modern warfare': ['brutal','entertaining','addictive'],
'angry birds': [ 'awesome', 'addictive'], 'counter-strike': ['brutal',
'awesome','addictive','entertaining'] }
program_output = bacon_functions.invert_actor_dict(D)
correct_output = { 'awesome': ['angry birds','counter-strike'],
'brutal': ['counter-strike','modern warfare'],
'addictive': ['modern warfare','angry birds','counter-strike'],
'entertaining': ['counter-strike','modern warfare'] }
sort_dict_values(program_output)
sort_dict_values(correct_output)
assert program_output == correct_output,\
'Multiple key multiple (overlapping) value list dictionary test'
if __name__ == '__main__':
nose.runmodule()