-
Notifications
You must be signed in to change notification settings - Fork 46
/
utilstest.py
79 lines (67 loc) · 2.67 KB
/
utilstest.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
import json
import unittest
import utils
class TestDataMinig(unittest.TestCase):
@classmethod
def setUpClass(cls):
with open('table.json') as f:
cls.table = json.loads(f.read())
def test_is_mono(self):
testlist = ['yes', 'yes', 'yes', 'yes']
self.assertTrue(utils.is_mono(testlist))
testlist = ['yes', 'no', 'yes', 'yes']
self.assertFalse(utils.is_mono(testlist))
def test_deldup(self):
testlist = ['yes', 'yes', 'yes', 'yes']
self.assertEqual(utils.deldup(testlist), ['yes'])
testlist = ['yes', 'no', 'yes', 'no']
self.assertEqual(utils.deldup(testlist), ['yes', 'no'])
def test_get_indexes(self):
self.assertEqual(utils.get_indexes(self.table, 'arg3', 'no'), [0, 3])
self.assertEqual(utils.get_indexes(self.table, 'arg3', 'dunno'), [])
self.assertEqual(utils.get_indexes(self.table, 'arg2', 'down'),
[0, 2, 3])
def test_get_values(self):
self.assertEqual(utils.get_values(self.table, 'arg1', [0, 2, 3]),
['left', 'right', 'right'])
self.assertEqual(utils.get_values(self.table, 'arg3', [1, 3]),
['yes', 'no'])
self.assertEqual(utils.get_values(self.table, 'arg1', []), [])
self.assertEqual(utils.get_values(self.table, 'arg1', [9, 12]), [])
def test_del_values(self):
expected = {
'result': ['yes', 'yes'],
'arg1': ['left', 'right'],
'arg2': ['down', 'down'],
'arg3': ['no', 'yes'],
}
self.assertEqual(utils.del_values(self.table, [0, 2]), expected)
expected = {
'result': [],
'arg1': [],
'arg2': [],
'arg3': [],
}
self.assertEqual(utils.del_values(self.table, []), expected)
expected = {
'result': ['yes', 'yes', 'no'],
'arg1': ['left', 'right', 'right'],
'arg2': ['down', 'down', 'down'],
'arg3': ['no', 'yes', 'no'],
}
self.assertEqual(utils.del_values(self.table, [0, 2, 3]), expected)
def test_get_subtables(self):
expected = [
{ 'result': ['yes', 'no'],
'arg1': ['left', 'left'],
'arg2': ['down', 'up'],
'arg3': ['no', 'yes'],
},
{ 'result': ['yes', 'no'],
'arg1': ['right', 'right'],
'arg2': ['down', 'down'],
'arg3': ['yes', 'no'],
}]
self.assertEqual(utils.get_subtables(self.table, 'arg1'), expected)
if __name__ == '__main__':
unittest.main()