-
Notifications
You must be signed in to change notification settings - Fork 93
/
test_gen_ordered_statistics.py
75 lines (70 loc) · 1.96 KB
/
test_gen_ordered_statistics.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
"""
Tests for apyori.gen_ordered_statistics.
"""
from mock import Mock
from nose.tools import eq_
from apyori import SupportRecord
from apyori import OrderedStatistic
from apyori import TransactionManager
from apyori import gen_ordered_statistics
def test_normal():
"""
Test for normal data.
"""
transaction_manager = Mock(spec=TransactionManager)
transaction_manager.calc_support.side_effect = lambda key: {
frozenset([]): 1.0,
frozenset(['A']): 0.8,
frozenset(['B']): 0.4,
frozenset(['C']): 0.2,
frozenset(['A', 'B']): 0.2,
frozenset(['A', 'C']): 0.1,
frozenset(['B', 'C']): 0.01,
frozenset(['A', 'B', 'C']): 0.001,
}.get(key, 0.0)
test_data = SupportRecord(frozenset(['A', 'B', 'C']), 0.001)
results = list(gen_ordered_statistics(transaction_manager, test_data))
eq_(results, [
OrderedStatistic(
frozenset([]),
frozenset(['A', 'B', 'C']),
0.001 / 1.0,
0.001 / 1.0 / 0.001,
),
OrderedStatistic(
frozenset(['A']),
frozenset(['B', 'C']),
0.001 / 0.8,
0.001 / 0.8 / 0.01,
),
OrderedStatistic(
frozenset(['B']),
frozenset(['A', 'C']),
0.001 / 0.4,
0.001 / 0.4 / 0.1,
),
OrderedStatistic(
frozenset(['C']),
frozenset(['A', 'B']),
0.001 / 0.2,
0.001 / 0.2 / 0.2,
),
OrderedStatistic(
frozenset(['A', 'B']),
frozenset(['C']),
0.001 / 0.2,
0.001 / 0.2 / 0.2,
),
OrderedStatistic(
frozenset(['A', 'C']),
frozenset(['B']),
0.001 / 0.1,
0.001 / 0.1 / 0.4,
),
OrderedStatistic(
frozenset(['B', 'C']),
frozenset(['A']),
0.001 / 0.01,
0.001 / 0.01 / 0.8,
),
])