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 0
/
test.py
151 lines (139 loc) · 4.55 KB
/
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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import unittest
from models.gentree import GenTree
from models.numrange import NumRange
from NEC_based_Anon import NEC_based_Anon
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_EC_based_Anon_knn(self):
init()
data = [['6', '1', 'haha'],
['6', '1', 'test'],
['8', '2', 'haha'],
['8', '2', 'test'],
['4', '1', 'hha'],
['4', '1', 'hha'],
['4', '3', 'hha'],
['4', '3', 'hha']]
result, eval_r = NEC_based_Anon(ATT_TREE, data, 'knn', 2)
try:
self.assertTrue(abs(eval_r[0] - 0) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
def test2_EC_based_Anon_knn(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 = NEC_based_Anon(ATT_TREE, data, 'knn', 2)
try:
self.assertTrue(abs(eval_r[0] - 2.77) < 0.05 or abs(eval_r[0] - 5.55) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
def test1_EC_based_Anon_kmember(self):
init()
data = [['6', '1', 'haha'],
['6', '1', 'test'],
['8', '2', 'haha'],
['8', '2', 'test'],
['4', '1', 'hha'],
['4', '1', 'hha'],
['4', '3', 'hha'],
['4', '3', 'hha']]
result, eval_r = NEC_based_Anon(ATT_TREE, data, 'kmember', 2)
try:
self.assertTrue(abs(eval_r[0] - 0) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
def test2_EC_based_Anon_kmember(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 = NEC_based_Anon(ATT_TREE, data, 'kmember', 2)
try:
self.assertTrue(abs(eval_r[0] - 2.77) < 0.05 or abs(eval_r[0] - 5.55) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
def test1_EC_based_Anon_oka(self):
init()
data = [['6', '1', 'haha'],
['6', '1', 'test'],
['8', '2', 'haha'],
['8', '2', 'test'],
['4', '1', 'hha'],
['4', '1', 'hha'],
['4', '3', 'hha'],
['4', '3', 'hha']]
result, eval_r = NEC_based_Anon(ATT_TREE, data, 'oka', 2)
try:
self.assertTrue(abs(eval_r[0] - 0) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
def test2_EC_based_Anon_oka(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 = NEC_based_Anon(ATT_TREE, data, 'oka', 2)
try:
self.assertTrue(abs(eval_r[0] - 2.77) < 0.05 or abs(eval_r[0] - 5.55) < 0.05)
except AssertionError:
print data
print result
print eval_r
self.assertEqual(0, 1)
if __name__ == '__main__':
unittest.main()