-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_word_search.py
More file actions
executable file
·58 lines (44 loc) · 2.02 KB
/
test_word_search.py
File metadata and controls
executable file
·58 lines (44 loc) · 2.02 KB
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
import unittest
from algorithms.backtracking.word_search.point import Point
from algorithms.backtracking.word_search import WordSearch
class WordSearchTests(unittest.TestCase):
@classmethod
def setUpClass(self):
puzzle = (
"jefblpepre\n"
"camdcimgtc\n"
"oivokprjsm\n"
"pbwasqroua\n"
"rixilelhrs\n"
"wolcqlirpc\n"
"screeaumgr\n"
"alxhpburyi\n"
"jalaycalmp\n"
"clojurermt"
)
self.example = WordSearch(puzzle)
def test_horizontal_words_left_to_right(self):
self.assertEqual(self.example.search("clojure"), (Point(0, 9), Point(6, 9)))
def test_horizontal_words_right_to_left(self):
self.assertEqual(self.example.search("elixir"), (Point(5, 4), Point(0, 4)))
def test_vertical_words_top_to_bottom(self):
self.assertEqual(self.example.search("ecmascript"), (Point(9, 0), Point(9, 9)))
def test_vertical_words_bottom_to_top(self):
self.assertEqual(self.example.search("rust"), (Point(8, 4), Point(8, 1)))
def test_diagonal_words_top_left_to_bottom_right(self):
self.assertEqual(self.example.search("java"), (Point(0, 0), Point(3, 3)))
def test_diagonal_upper_bottom_right_to_top_left(self):
self.assertEqual(self.example.search("lua"), (Point(7, 8), Point(5, 6)))
def test_diagonal_upper_bottom_left_to_top_right(self):
self.assertEqual(self.example.search("lisp"), (Point(2, 5), Point(5, 2)))
def test_diagonal_upper_top_right_to_bottom_left(self):
self.assertEqual(self.example.search("ruby"), (Point(7, 5), Point(4, 8)))
def test_words_that_are_not_in_the_puzzle(self):
self.assertIsNone(self.example.search("haskell"))
def test_search_differently_sized_puzzles(self):
puzzle = "qwertyuiopz\n" "luamsicrexe\n" "abcdefghijk"
self.assertEqual(
WordSearch(puzzle).search("exercism"), (Point(10, 1), Point(3, 1))
)
if __name__ == "__main__":
unittest.main()