forked from shuyo/ldig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_da.py
executable file
·61 lines (50 loc) · 1.84 KB
/
test_da.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
import da
class TestDoubleArray(unittest.TestCase):
def test1(self):
trie = da.DoubleArray(verbose=False)
trie.initialize(["cat"])
self.assertEqual(trie.N, 4)
self.assertTrue(trie.get("ca") is None)
self.assertTrue(trie.get("xxx") is None)
self.assertEqual(trie.get("cat"), 0)
def test2(self):
trie = da.DoubleArray()
trie.initialize(["cat", "dog"])
self.assertEqual(trie.N, 7)
self.assertTrue(trie.get("ca") is None)
self.assertTrue(trie.get("xxx") is None)
self.assertEqual(trie.get("cat"), 0)
self.assertEqual(trie.get("dog"), 1)
def test3(self):
trie = da.DoubleArray(verbose=False)
trie.initialize(["ca", "cat", "deer", "dog", "fox", "rat"])
print (trie.base)
print (trie.check)
print (trie.value)
self.assertEqual(trie.N, 17)
self.assertTrue(trie.get("c") is None)
self.assertEqual(trie.get("ca"), 0)
self.assertEqual(trie.get("cat"), 1)
self.assertEqual(trie.get("deer"), 2)
self.assertEqual(trie.get("dog"), 3)
self.assertTrue(trie.get("xxx") is None)
def test4(self):
trie = da.DoubleArray()
self.assertRaises(Exception, trie.initialize, ["cat", "ant"])
def test5(self):
trie = da.DoubleArray(verbose=False)
trie.initialize(["ca", "cat", "deer", "dog", "fox", "rat"])
r = trie.extract_features("")
self.assertEqual(len(r), 0)
r = trie.extract_features("cat")
self.assertEqual(len(r), 2)
self.assertEqual(r[0], 1)
self.assertEqual(r[1], 1)
r = trie.extract_features("deerat")
self.assertEqual(len(r), 2)
self.assertEqual(r[2], 1)
self.assertEqual(r[5], 1)
unittest.main()