This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
basic_mondrain_test.py
68 lines (60 loc) · 1.83 KB
/
basic_mondrain_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
import unittest
from mondrian import mondrian
# from utils.read_data import read_data, read_tree
from models.gentree import GenTree
from models.numrange import NumRange
import random
import pdb
# Build a GenTree object
ATT_TREE = []
def init():
global ATT_TREE
ATT_TREE = []
tree_temp = {}
tree = GenTree('*')
tree_temp['*'] = tree
lt = GenTree('1,5', tree)
tree_temp['1,5'] = lt
rt = GenTree('6,10', tree)
tree_temp['6,10'] = rt
for i in range(1, 11):
if i <= 5:
t = GenTree(str(i), lt, True)
else:
t = GenTree(str(i), rt, True)
tree_temp[str(i)] = t
numrange = NumRange(['1', '2', '3', '4', '5',
'6', '7', '8', '9', '10'], dict())
ATT_TREE.append(tree_temp)
ATT_TREE.append(numrange)
class functionTest(unittest.TestCase):
def test1_mondrian(self):
init()
data = [['6', '1', 'haha'],
['6', '1', 'test'],
['8', '2', 'haha'],
['8', '2', 'test'],
['4', '1', 'hha'],
['4', '2', 'hha'],
['4', '3', 'hha'],
['4', '4', 'hha']]
result, eval_r = mondrian(ATT_TREE, data, 2)
# print result
# print eval_r
self.assertTrue(abs(eval_r[0] - 100.0 / 36) < 0.05)
def test2_mondrian(self):
init()
data = [['6', '1', 'haha'],
['6', '1', 'test'],
['8', '2', 'haha'],
['8', '2', 'test'],
['4', '1', 'hha'],
['4', '1', 'hha'],
['1', '1', 'hha'],
['2', '1', 'hha']]
result, eval_r = mondrian(ATT_TREE, data, 2)
# print result
# print eval_r
self.assertTrue(abs(eval_r[0] - 100.0 / 8) < 0.05)
if __name__ == '__main__':
unittest.main()