-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_solution.py
65 lines (50 loc) · 2.44 KB
/
test_solution.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
from unittest import TestCase
from solution import Solution
class TestSolution(TestCase):
words_board = [['a', 'b', 'a', 'c', 'a'],
['d', 'b', 'c', 'c', 'e'],
['e', 'a', 'a', 'e', 'e'],
['a', 'b', 'c', 'b', 'a'],
['d', 'a', 'e', 'b', 'd']
]
def __init__(self, *args, **kwargs):
super(TestSolution, self).__init__(*args, **kwargs)
self.solution = Solution(5)
self.solution.initial_board = self.words_board
self.solution.board_1x_dict = self.solution.to_one_dimension_dict(self.words_board)
def test_words_search(self):
words = ['abaca', 'adead', 'dbead', 'ababd', 'eba', 'eeca', 'abe', 'eaaee', 'daeb']
assert self.solution.words_search(words) == words
def test_words_search_not_wrap(self):
words = ['ccbb', 'cae']
assert self.solution.words_search(words) == [False, False]
def test_words_search_longer_word(self):
words = ['abacaaba']
assert self.solution.words_search(words) == [False]
def test_search_by_word(self):
word = 'acabd'
assert self.solution.search_by_word(word)
def test_search_word_by_position_forward(self):
word = 'eaaee'
assert self.solution.search_word_by_position(word, (2, 0), 0, 'col+')
def test_search_word_by_position_backward(self):
word = 'abcba'
assert self.solution.search_word_by_position(word, (3, 4), 0, 'col-')
def test_search_word_by_position_downward(self):
word = 'bbaba'
assert self.solution.search_word_by_position(word, (0, 1), 0, 'row+')
def test_search_word_by_position_upward(self):
word = 'daeea'
assert self.solution.search_word_by_position(word, (4, 4), 0, 'row-')
def test_search_word_by_position_diagonal_up_forward(self):
word = 'dbaca'
assert self.solution.search_word_by_position(word, (4, 0), 0, 'row-col+')
def test_search_word_by_position_diagonal_up_backward(self):
word = 'dbaba'
assert self.solution.search_word_by_position(word, (4, 4), 0, 'row-col-')
def test_search_word_by_position_diagonal_down_backward(self):
word = 'ababd'
assert self.solution.search_word_by_position(word, (0, 0), 0, 'row+col+')
def test_search_word_by_position_diagonal_down_forward(self):
word = 'acabd'
assert self.solution.search_word_by_position(word, (0, 4), 0, 'row+col-')