-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallcombmap_test.py
72 lines (48 loc) · 1.62 KB
/
allcombmap_test.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
import unittest2 as unittest
from allcombmap import *
class AllCombMapTests(unittest.TestCase):
def test_basic(self):
def foo(x,y):
return x+y
ret = AllCombMap([[1,2,3,4,5]], foo, 4).execute()
answer = map(lambda x: x+4, [1,2,3,4,5])
ret.sort()
answer.sort()
self.assertEqual(ret, answer)
class SMTests(unittest.TestCase):
def test_building_SM(self):
def foo(x):
return x
sm = AllCombMapSM([[1,2,3]], foo).run()
self.assertEqual(sm.tree.lists[0], [1,2,3])
self.assertEqual(sm.tree.func, foo)
def test_interpreting_SM(self):
def foo(x):
return -x
sm = AllCombMapSM([[1,2,3,4]], foo).run()
x = sm.interpret(nproc=2)
space = [-1, -2, -3, -4]
space.sort()
x.sort()
self.assertEqual(x, space)
def test_interpreting_complicated_SM(self):
def foo(x,y):
return x+y
sm = AllCombMapSM([[1,2,3,4],[1,2,3,4]], foo).run()
ret = sm.interpret(nproc=3)
import itertools
answer = [x+y for x,y in itertools.product([1,2,3,4],[1,2,3,4])]
ret.sort()
answer.sort()
self.assertEqual(ret, answer)
def test_with_extra_args(self):
def foo(x,y):
return x+y
sm = AllCombMapSM([[1,2,3,4]], foo, 3).run()
ret = sm.interpret(nproc=2)
answer = map(lambda x: x+3, [1,2,3,4])
answer.sort()
ret.sort()
self.assertEqual(ret, answer)
if __name__ == '__main__':
unittest.main()