-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_shepherd.py
119 lines (65 loc) · 2.29 KB
/
test_shepherd.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import shepherd
import unittest
import example
from multiprocessing import Pool
class TestShepherd(unittest.TestCase):
def setUp(self):
pass
def test_default_map_reduce(self):
expected = {0:'Hello World'}
result = shepherd.run(datasource = expected)
self.assertEqual(expected, result)
def test_array_input(self):
data = ['Hello World']
expected = {0:'Hello World'}
result = shepherd.run(datasource = data)
self.assertEqual(expected, result)
def test_array_input_2(self):
data = ['Hello', 'World']
expected = {0:'Hello', 1:'World'}
result = shepherd.run(datasource = data)
self.assertEqual(expected, result)
def test_example(self):
expected = {'a': 2, 'on': 1, 'great': 1, 'Humpty': 3, 'again': 1, 'wall': 1, 'Dumpty': 2, 'men': 1, 'had': 1, 'all': 1, 'together': 1, "King's": 2, 'horses': 1, 'All': 1, "Couldn't": 1, 'fall': 1, 'and': 1, 'the': 2, 'put': 1, 'sat': 1}
result = shepherd.run(
datasource = example.datasource,
mapfn = example.mapfn,
reducefn = example.reducefn
)
self.assertEqual(expected, result)
def test_word_counting_1(self):
data = ['one fish two fish red fish blue fish']
expected = {'one':1, 'two':1, 'red':1, 'blue':1, 'fish':4}
result = shepherd.run(
datasource = data,
mapfn = shepherd.map_word_count,
reducefn = shepherd.reduce_word_count,
)
self.assertEqual(expected, result)
def test_word_counting_2(self):
data = ['one fish', 'two fish', 'red fish', 'blue fish']
expected = {'one':1, 'two':1, 'red':1, 'blue':1, 'fish':4}
result = shepherd.run(
datasource = data,
mapfn = shepherd.map_word_count,
reducefn = shepherd.reduce_word_count,
)
self.assertEqual(expected, result)
def test_CustomServer(self):
data = ['one fish', 'two fish', 'red fish', 'blue fish']
expected = {0: 'one fish', 1: 'two fish', 2: 'red fish', 3: 'blue fish'}
result = shepherd.run(
datasource = data,
server = shepherd.Server,
)
self.assertEqual(expected, result)
def test_WordCountServer(self):
data = ['one fish', 'two fish', 'red fish', 'blue fish']
expected = {'one':1, 'two':1, 'red':1, 'blue':1, 'fish':4}
result = shepherd.run(
datasource = data,
server = shepherd.WordCountServer,
)
self.assertEqual(expected, result)
if __name__ == '__main__':
unittest.main()