-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_voldemot.py
67 lines (51 loc) · 2.84 KB
/
test_voldemot.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
import asyncio
import voldemot_utils as vol
def test_wordPresent():
""" test finding a valid word in the input """
assert vol.wordIsPresent('a', 'a') == True
assert vol.wordIsPresent('art', 'arat') == True
assert vol.wordIsPresent('art', 'at') == False
def test_getWordsUnder():
""" test collecting words under a given length """
sourceList = ['a', 'ab', 'abc', 'abcd']
oneList = []
twoList = ['a']
threeList = ['a', 'ab']
fourList = ['a', 'ab', 'abc']
fiveList = ['a', 'ab', 'abc', 'abcd']
assert vol.getWordsUnder(sourceList, 1) == oneList
assert vol.getWordsUnder(sourceList, 2) == twoList
assert vol.getWordsUnder(sourceList, 3) == threeList
assert vol.getWordsUnder(sourceList, 4) == fourList
assert vol.getWordsUnder(sourceList, 5) == fiveList
def test_getWordsEqual():
""" test collecting words of a specified length """
sourceList = ['a', 'ab', 'bc', 'ac', 'abc', 'cba', 'abcd']
zeroList = []
oneList = ['a']
twoList = ['ab', 'bc', 'ac']
threeList = ['abc', 'cba']
fourList = ['abcd']
assert vol.getWordsEqualTo(sourceList, 0) == zeroList
assert vol.getWordsEqualTo(sourceList, 1) == oneList
assert vol.getWordsEqualTo(sourceList, 2) == twoList
assert vol.getWordsEqualTo(sourceList, 3) == threeList
assert vol.getWordsEqualTo(sourceList, 4) == fourList
def test_wordCombinations():
""" test finding word combinations in a given input """
wordList = ['a', 'age', 'ago', 'an', 'away', 'be', 'bile', 'cab', 'ego', 'even', 'fake', 'gave', 'give', 'given', 'go',
'hi', 'hive', 'hoe', 'i', 'in', 'it', 'leg', 'log', 'new', 'newt', 'nile', 'no', 'on', 'oven', 'tin', 'trip', 'way', 'we', 'web', 'well', 'went', 'wet', 'will', 'win', 'won']
loop = asyncio.get_event_loop()
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'igo', 2))
assert resultsList == ['go i']
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'iwent', 2))
assert resultsList == ['i newt', 'i went', 'in wet', 'it new', 'tin we']
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'ihavegone', 3))
assert resultsList == ['a given hoe', 'age hi oven', 'age hive no', 'age hive on', 'ago even hi', 'an ego hive', 'an give hoe', 'gave hoe in']
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'wegoaway', 3))
assert resultsList == ['ago way we', 'away go we']
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'wewillbegone', 4))
assert resultsList == ['be ego new will', 'be ego well win', 'bile leg we won', 'bile log new we', 'ego in web well', 'log nile we web']
resultsList = loop.run_until_complete(vol.findWordCombinations(wordList, 'raipfaetkacb', 4))
assert resultsList == ['a cab fake trip']
loop.close()