forked from cmapman/C45algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc45test.py
30 lines (20 loc) · 785 Bytes
/
c45test.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
import unittest
import json
from c45 import freq, info, infox, gain
class TestC45(unittest.TestCase):
@classmethod
def setUpClass(cls):
with open('table.json') as f:
cls.table = json.loads(f.read())
def test_freq(self):
self.assertEqual(freq(self.table, 'arg1', 'left'), 2)
self.assertEqual(freq(self.table, 'result', 'no'), 2)
self.assertEqual(freq(self.table, 'arg3', 'foo'), 0)
def test_info(self):
self.assertEqual(info(self.table, 'result'), 1)
def test_infox(self):
self.assertEqual(infox(self.table, 'arg1', 'result'), 1)
def test_gain(self):
self.assertEqual(gain(self.table, 'arg1', 'result'), 0)
if __name__ == '__main__':
unittest.main()