-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunittesting.py
125 lines (103 loc) · 3.42 KB
/
unittesting.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
from Trie import Trie
from dbController import dbController
import unittest
class TestMethods(unittest.TestCase):
"""
This class is used to test individual methods in the Trie class.
"""
def testGetTrie(self):
"""
Testing the getTrie function in the Trie class.
Return
----------
None
"""
trie = Trie()
self.assertEqual(trie.getTrie(), {})
print("GetTrie test finished")
def testInsertWord(self):
"""
Testing the insertWord function in the Trie class.
Return
----------
None
"""
trie = Trie()
self.assertEqual(trie.insertWord("Insert"),None)
print("InsertWord test finished")
def testGetDirectChildren(self):
"""
Testing the getDirectChildren function in the Trie class.
Return
----------
None
"""
trie=Trie()
trie.insertWord("insert")
trie.insertWord("insect")
self.assertEqual(trie.getDirectChildren("inse"),["r","c"])
self.assertEqual(trie.getDirectChildren("none"),'Error: Word is not currently implemented!')
print("GetDirectChildren test finished")
def testGetChildren(self):
"""
Testing the getChildren function in the Trie class.
Return
----------
None
"""
trie=Trie()
trie.insertWord("insert")
trie.insertWord("insect")
self.assertEqual(trie.getChildren({'r': {'t': {'!': True}}, 'c': {'t': {'!': True}}}),["r","c"])
print("GetChildren test finished")
def testContainsWord(self):
"""
Testing the containsWord function in the Trie class.
Return
----------
None
"""
trie = Trie()
self.assertEqual(trie.containsWord("Anything"),False)
trie.insertWord("lorem")
self.assertEqual(trie.containsWord("Anything"),False)
self.assertEqual(trie.containsWord("lorem"),True)
print("ContainsWord test finished")
def testFindCandidates(self):
"""
Testing the findCandidates function in the Trie class.
Return
----------
None
"""
trie = Trie()
self.assertEqual(trie.findCandidates("Anything",[]),[])
trie.insertWord("insert")
trie.insertWord("insect")
trie.insertWord("indirect")
trie.insertWord("island")
self.assertEqual(trie.findCandidates("i",[]),["insert","insect","indirect","island"])
self.assertEqual(trie.findCandidates("is",[]),["island"])
self.assertEqual(trie.findCandidates("never",[]),[])
print("FindCandidates test finished")
def testGetWords(self):
"""
Testing the getWords function in the dbController class.
*NOTE* Testing this fully is not possible due to the changing nature of the database.
Return
---------
None
"""
db = dbController()
self.assertEqual(db.getWords()[0:5],['James', 'Jake', 'Jam', 'Lorem', 'Lore'])
print("getWords test finished")
db.con.close()
def testAddWord(self):
db = dbController()
self.assertEqual(db.addWord("Jake"),False)
self.assertEqual(db.addWord("James"),False)
self.assertEqual(db.addWord("Jam"),False)
print("addWord test finished")
db.con.close()
if __name__ == '__main__':
unittest.main()