-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_peinard.py
78 lines (69 loc) · 1.67 KB
/
test_peinard.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
from peinard import heuristic, mkdec
def debug(msg, result):
"""
convenience debug func for theses tests
"""
return """%s
got:
%s""" % (msg, result)
def perform(data, expected):
"""
expected result may be unordered
"""
result = heuristic(data)
assert len(expected) == len(result), debug("unmatched lengths", result)
for transfer in expected:
assert transfer in result, debug("not sure if fully reliable "
"because of Decimal comparison.", result)
TEST_MATRIX = (
(
"null test",
{},
[],
),
(
"1 person, null test",
{"a": mkdec(0)},
[("a", None, mkdec(0))],
),
(
"2 persons, no decimals",
{"a": mkdec(1),
"b": mkdec(-1)},
[("b", "a", mkdec(1))],
),
(
"2 persons, with decimals",
{"a": mkdec(1.1),
"b": mkdec(-1.1)},
[("b", "a", mkdec(1.1))],
),
(
"3 persons, no decimals",
{"a": mkdec(-2),
"b": mkdec(1),
"c": mkdec(1)},
[('a', 'c', mkdec(1)), ('a', 'b', mkdec(1))]
),
(
"3 persons, with decimals",
{"a": mkdec(-1.1),
"b": mkdec(0.1),
"c": mkdec(1.0)},
([('a', 'c', mkdec(1)), ('a', 'b', mkdec(0.1))])
)
)
def test_generator():
"""
uses the TEST_MATRIX to test heuristic,
assuming that it is a tuple of triples:
-name of the test
-input data
-expected output.
"""
for name, data, expected in TEST_MATRIX:
test = lambda: perform(data, expected)
test.description = '''%s
-input data: \t%s
-expected: \t%s''' % (name, data, expected)
yield test