From 610a39a391e28eef2cb89b46583737c891cf71bc Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 29 Mar 2022 20:32:40 -0700 Subject: [PATCH 1/4] Passing wave 1 --- adagrams/game.py | 44 ++++++++++++++++++++++++++++++++++++++++++- tests/test_wave_01.py | 1 - tests/test_wave_02.py | 14 ++++++++++---- tests/test_wave_03.py | 12 ++++++++---- tests/test_wave_04.py | 21 ++++++++++++++------- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..ba05ec7e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,48 @@ +import random +import copy +LETTER_POOL = { + 'A': 9, + 'B': 2, + 'C': 2, + 'D': 4, + 'E': 12, + 'F': 2, + 'G': 3, + 'H': 2, + 'I': 9, + 'J': 1, + 'K': 1, + 'L': 4, + 'M': 2, + 'N': 6, + 'O': 8, + 'P': 2, + 'Q': 1, + 'R': 6, + 'S': 4, + 'T': 6, + 'U': 4, + 'V': 2, + 'W': 2, + 'X': 1, + 'Y': 2, + 'Z': 1 +} + + def draw_letters(): - pass + letter_pool = copy.deepcopy(LETTER_POOL) + chosen_letters = [] + while len(chosen_letters) < 10: + random_letter = random.choice(list(letter_pool)) + if letter_pool[random_letter] > 0: + chosen_letters.append(random_letter) + letter_pool[random_letter] -= 1 + + print(chosen_letters) + return chosen_letters +#random_letter = [random.choice(list(LETTER_POOL)) for i in range(10)] def uses_available_letters(word, letter_bank): pass diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 25ef73e7..8b90273f 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -50,7 +50,6 @@ def test_draw_letters_is_list_of_letter_strings(): assert len(elem) == 1 def test_letter_not_selected_too_many_times(): - for i in range(1000): # Arrange/Act letters = draw_letters() diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index a5170d8a..25b3339a 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,9 @@ from adagrams.game import uses_available_letters +@pytest.mark.skip() def test_uses_available_letters_true_word_in_letter_bank(): + # Arrange letters = ["D", "O", "G", "X", "X", "X", "X", "X", "X", "X"] word = "DOG" @@ -12,8 +14,9 @@ def test_uses_available_letters_true_word_in_letter_bank(): # Assert assert is_valid == True - +@pytest.mark.skip() def test_uses_available_letters_false_word_in_letter_bank(): + # Arrange letters = ["D", "O", "X", "X", "X", "X", "X", "X", "X", "X"] word = "DOG" @@ -23,8 +26,9 @@ def test_uses_available_letters_false_word_in_letter_bank(): # Assert assert is_valid == False - +@pytest.mark.skip() def test_uses_available_letters_false_word_overuses_letter(): + # Arrange letters = ["A", "X", "X", "X", "X", "X", "X", "X", "X", "X"] word = "AAA" @@ -34,8 +38,9 @@ def test_uses_available_letters_false_word_overuses_letter(): # Assert assert is_valid == False - +@pytest.mark.skip() def test_uses_available_letters_does_not_change_letter_bank(): + # Arrange letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] letters_copy = letters[:] @@ -47,8 +52,9 @@ def test_uses_available_letters_does_not_change_letter_bank(): # Assert assert is_valid == True assert letters == letters_copy - +@pytest.mark.skip() def test_uses_available_letters_ignores_case(): + pass # Arrange letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 5473db39..2b6c74f7 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -1,24 +1,28 @@ import pytest from adagrams.game import score_word - +@pytest.mark.skip() def test_score_word_accurate(): + pass # Assert assert score_word("A") == 1 assert score_word("DOG") == 5 assert score_word("WHIMSY") == 17 - +@pytest.mark.skip() def test_score_word_accurate_ignores_case(): + pass # Assert assert score_word("a") == 1 assert score_word("dog") == 5 assert score_word("wHiMsY") == 17 - +@pytest.mark.skip() def test_score_zero_for_empty(): + pass # Assert assert score_word("") == 0 - +@pytest.mark.skip() def test_score_extra_points_for_seven_or_longer(): + pass # Assert assert score_word("XXXXXXX") == 64 assert score_word("XXXXXXXX") == 72 diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 8fdedf66..ff1f01e3 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -1,8 +1,9 @@ import pytest from adagrams.game import score_word, get_highest_word_score - +@pytest.mark.skip() def test_get_highest_word_score_accurate(): + pass # Arrange words = ["X", "XX", "XXX", "XXXX"] @@ -13,8 +14,9 @@ def test_get_highest_word_score_accurate(): # Assert assert best_word[0] == "XXXX" assert best_word[1] == 32 - +@pytest.mark.skip() def test_get_highest_word_score_accurate_unsorted_list(): + pass # Arrange words = ["XXX", "XXXX", "XX", "X"] @@ -24,8 +26,9 @@ def test_get_highest_word_score_accurate_unsorted_list(): # Assert assert best_word[0] == "XXXX" assert best_word[1] == 32 - +@pytest.mark.skip() def test_get_highest_word_tie_prefers_shorter_word(): + pass # Arrange words = ["MMMM", "WWW"] @@ -37,8 +40,9 @@ def test_get_highest_word_tie_prefers_shorter_word(): assert score_word(words[1]) == 12 assert best_word[0] == "WWW" assert best_word[1] == 12 - +@pytest.mark.skip() def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): + pass # Arrange words = ["WWW", "MMMM"] @@ -50,8 +54,9 @@ def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): assert score_word(words[1]) == 12 assert best_word[0] == "WWW" assert best_word[1] == 12 - +@pytest.mark.skip() def test_get_highest_word_tie_prefers_ten_letters(): + pass # Arrange words = ["AAAAAAAAAA", "BBBBBB"] @@ -61,8 +66,9 @@ def test_get_highest_word_tie_prefers_ten_letters(): # Assert assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 - +@pytest.mark.skip() def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): + pass # Arrange words = ["BBBBBB", "AAAAAAAAAA"] @@ -72,8 +78,9 @@ def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): # Assert assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 - +@pytest.mark.skip() def test_get_highest_word_tie_same_length_prefers_first(): + pass # Arrange words = ["AAAAAAAAAA", "EEEEEEEEEE"] From beb86121814ed132c0a3c54fef74c70d8c8ac0d3 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 29 Mar 2022 21:31:47 -0700 Subject: [PATCH 2/4] Passing wave 2 --- adagrams/game.py | 17 ++++++++++++----- tests/test_wave_02.py | 15 ++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ba05ec7e..c8129575 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -29,7 +29,7 @@ 'Z': 1 } - +##----------- WAVE 1 ----------- ## def draw_letters(): letter_pool = copy.deepcopy(LETTER_POOL) chosen_letters = [] @@ -38,13 +38,20 @@ def draw_letters(): if letter_pool[random_letter] > 0: chosen_letters.append(random_letter) letter_pool[random_letter] -= 1 - - print(chosen_letters) return chosen_letters -#random_letter = [random.choice(list(LETTER_POOL)) for i in range(10)] + +##----------- WAVE 2 ----------- ## def uses_available_letters(word, letter_bank): - pass + letter_bank_copy = copy.deepcopy(letter_bank) + new_word = word.upper() + for letter in new_word: + if letter not in letter_bank_copy: + return False + else: + letter_bank_copy.remove(letter) + return True + def score_word(word): pass diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 25b3339a..193ebe4b 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from adagrams.game import uses_available_letters -@pytest.mark.skip() + def test_uses_available_letters_true_word_in_letter_bank(): # Arrange @@ -14,7 +14,8 @@ def test_uses_available_letters_true_word_in_letter_bank(): # Assert assert is_valid == True -@pytest.mark.skip() + + def test_uses_available_letters_false_word_in_letter_bank(): # Arrange @@ -26,7 +27,9 @@ def test_uses_available_letters_false_word_in_letter_bank(): # Assert assert is_valid == False -@pytest.mark.skip() + + + def test_uses_available_letters_false_word_overuses_letter(): # Arrange @@ -38,7 +41,8 @@ def test_uses_available_letters_false_word_overuses_letter(): # Assert assert is_valid == False -@pytest.mark.skip() + + def test_uses_available_letters_does_not_change_letter_bank(): # Arrange @@ -52,7 +56,8 @@ def test_uses_available_letters_does_not_change_letter_bank(): # Assert assert is_valid == True assert letters == letters_copy -@pytest.mark.skip() + + def test_uses_available_letters_ignores_case(): pass # Arrange From 92f74e7129cc7779b563fe386669079ab5af01df Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 31 Mar 2022 16:43:24 -0700 Subject: [PATCH 3/4] passing wave 3 now --- adagrams/game.py | 41 ++++++++++++++++++++++++++++++++++++++--- tests/test_wave_03.py | 15 +++++++++------ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c8129575..2afcd3bf 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -28,7 +28,34 @@ 'Y': 2, 'Z': 1 } - +LETTER_POINTS = { + 'A': 1, + 'B': 3, + 'C': 3, + 'D': 2, + 'E': 1, + 'F': 4, + 'G': 2, + 'H': 4, + 'I': 1, + 'J': 8, + 'K': 5, + 'L': 1, + 'M': 3, + 'N': 1, + 'O': 1, + 'P': 3, + 'Q': 10, + 'R': 1, + 'S': 1, + 'T': 1, + 'U': 1, + 'V': 4, + 'W': 4, + 'X': 8, + 'Y': 4, + 'Z': 10 +} ##----------- WAVE 1 ----------- ## def draw_letters(): letter_pool = copy.deepcopy(LETTER_POOL) @@ -52,9 +79,17 @@ def uses_available_letters(word, letter_bank): letter_bank_copy.remove(letter) return True - +##----------- WAVE 2 ----------- ## def score_word(word): - pass + points = 0 + cased_word = word.upper() + if len(cased_word) >= 7: + points += 8 + for letter in cased_word: + points += LETTER_POINTS[letter] + + return points + def get_highest_word_score(word_list): pass \ No newline at end of file diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 2b6c74f7..7df36789 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -1,26 +1,29 @@ import pytest from adagrams.game import score_word -@pytest.mark.skip() + def test_score_word_accurate(): - pass + # Assert assert score_word("A") == 1 assert score_word("DOG") == 5 assert score_word("WHIMSY") == 17 -@pytest.mark.skip() + + def test_score_word_accurate_ignores_case(): - pass + # Assert assert score_word("a") == 1 assert score_word("dog") == 5 assert score_word("wHiMsY") == 17 -@pytest.mark.skip() + + def test_score_zero_for_empty(): pass # Assert assert score_word("") == 0 -@pytest.mark.skip() + + def test_score_extra_points_for_seven_or_longer(): pass # Assert From 3301a049a62f4b9fbe53a73f8ce21f5218b761a2 Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 31 Mar 2022 18:13:24 -0700 Subject: [PATCH 4/4] passing wave 4 --- adagrams/game.py | 22 +++++++++++++++++++--- tests/test_wave_04.py | 21 +++++++++++---------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2afcd3bf..37b32041 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -79,7 +79,7 @@ def uses_available_letters(word, letter_bank): letter_bank_copy.remove(letter) return True -##----------- WAVE 2 ----------- ## +##----------- WAVE 3 ----------- ## def score_word(word): points = 0 cased_word = word.upper() @@ -90,6 +90,22 @@ def score_word(word): return points - +##----------- WAVE 4 ----------- ## def get_highest_word_score(word_list): - pass \ No newline at end of file + champ_list = [] + best_word = word_list[0] + high_score = score_word(best_word) + champ_list.append(best_word) + champ_list.append(high_score) + for word in word_list: + if score_word(word) > champ_list[1]: + champ_list[0] = word + champ_list[1] = score_word(word) + elif score_word(word) == champ_list[1] and len(word) < len(champ_list[0]) and len(champ_list[0]) != 10: + champ_list[0] = word + champ_list[1] = score_word(word) + elif score_word(word) == champ_list[1] and len(word) == 10 and len(champ_list[0]) != 10: + champ_list[0] = word + champ_list[1] = score_word(word) + return champ_list + \ No newline at end of file diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index ff1f01e3..4e831537 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -1,9 +1,9 @@ import pytest from adagrams.game import score_word, get_highest_word_score -@pytest.mark.skip() + def test_get_highest_word_score_accurate(): - pass + # Arrange words = ["X", "XX", "XXX", "XXXX"] @@ -14,9 +14,10 @@ def test_get_highest_word_score_accurate(): # Assert assert best_word[0] == "XXXX" assert best_word[1] == 32 -@pytest.mark.skip() + + def test_get_highest_word_score_accurate_unsorted_list(): - pass + # Arrange words = ["XXX", "XXXX", "XX", "X"] @@ -26,9 +27,9 @@ def test_get_highest_word_score_accurate_unsorted_list(): # Assert assert best_word[0] == "XXXX" assert best_word[1] == 32 -@pytest.mark.skip() + def test_get_highest_word_tie_prefers_shorter_word(): - pass + # Arrange words = ["MMMM", "WWW"] @@ -40,7 +41,7 @@ def test_get_highest_word_tie_prefers_shorter_word(): assert score_word(words[1]) == 12 assert best_word[0] == "WWW" assert best_word[1] == 12 -@pytest.mark.skip() + def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): pass # Arrange @@ -54,7 +55,7 @@ def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): assert score_word(words[1]) == 12 assert best_word[0] == "WWW" assert best_word[1] == 12 -@pytest.mark.skip() + def test_get_highest_word_tie_prefers_ten_letters(): pass # Arrange @@ -66,7 +67,7 @@ def test_get_highest_word_tie_prefers_ten_letters(): # Assert assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 -@pytest.mark.skip() + def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): pass # Arrange @@ -78,7 +79,7 @@ def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): # Assert assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 -@pytest.mark.skip() + def test_get_highest_word_tie_same_length_prefers_first(): pass # Arrange