-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_scrabble.py
68 lines (58 loc) · 2.05 KB
/
test_scrabble.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
import unittest
from scrabble import calculate_score, find_max_score_word
class ScrabbleSolverTests(unittest.TestCase):
def setUp(self):
self.LETTER_POINTS = {
"e": 1,
"a": 1,
"i": 1,
"o": 1,
"n": 1,
"r": 1,
"t": 1,
"l": 1,
"s": 1,
"u": 1,
"d": 2,
"g": 2,
"b": 3,
"c": 3,
"m": 3,
"p": 3,
"f": 4,
"h": 4,
"v": 4,
"w": 4,
"y": 4,
"k": 5,
"j": 8,
"x": 8,
"q": 10,
"z": 10,
}
def test_calculate_score(self):
word = "banana"
score = calculate_score(word, self.LETTER_POINTS)
self.assertEqual(score, 8)
def test_find_max_score_word_with_single_solution(self):
dictionary = ["hello", "world", "python", "openai"]
letters = "owlrd"
max_score_word = find_max_score_word(dictionary, letters, self.LETTER_POINTS)
self.assertEqual(max_score_word, "world")
def test_find_max_score_word_with_different_scores(self):
dictionary = ["cat", "hat", "dog"]
letters = "atdoh"
max_score_word = find_max_score_word(dictionary, letters, self.LETTER_POINTS)
self.assertEqual(max_score_word, "hat")
def test_find_max_score_word_duplicate_letters(self):
dictionary = ["arrest", "rarest", "raster", "raters", "sartre", "starer", "waster", "waters", "wrest", "wrase"]
letters = "arwtsre"
max_score_word = find_max_score_word(dictionary, letters, self.LETTER_POINTS)
self.assertEqual(max_score_word, "waster")
def test_find_max_score_word_value_better_than_size(self):
dictionary = ["entire", "tween", "soft", "would", "test"]
letters = "etiewrn"
max_score_word = find_max_score_word(dictionary, letters, self.LETTER_POINTS)
self.assertEqual(max_score_word, "tween")
if __name__ == "__main__":
unittest.main()