Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby - Laura Perez" #18

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# AdaGrams

First project!

## Skills Assessed

- Following directions and reading comprehension
Expand Down
139 changes: 135 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,142 @@
import random
LETTER_HAND = 10
LETTER_POOL = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job using a helper variable!

'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
}
SCORE_VALUES = {
'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 check_for_values(dict,list, letter):
count_letter = list.count(letter)
print(f"count letter: {count_letter}, letter {letter}")
print(dict[letter])
if dict[letter] >= count_letter:
return True
else:
return False

def draw_letters():
pass

hand_list = []
while len(hand_list) < LETTER_HAND:
a_letter = random.choice(list(LETTER_POOL.keys()))
hand_list.append(a_letter)
value_enough_times = check_for_values(LETTER_POOL, hand_list, a_letter)
if value_enough_times is True:
continue
else:
hand_list.pop()

return hand_list


# Wave 2:
def uses_available_letters(word, letter_bank):
pass

upper_word = word.upper()
for letter in upper_word:
if letter not in letter_bank:
return False
elif upper_word.count(letter) > letter_bank.count(letter):
return False
else:
continue
return True



def score_word(word):
pass

word_upper = word.upper()
lenght_of_word = len(word)
total_score = 0
for letter in word_upper:
if letter in SCORE_VALUES:
total_score += SCORE_VALUES[letter]
if lenght_of_word > 6:
total_score += 8

return total_score



# Wave 4:
def higher_than(tuple1, tuple2):
'''returns True if word1 ranks higher than word2'''
score_word1 = tuple1[1]
score_word2 = tuple2[1]
if score_word1 == score_word2:
lenght_word1 = len(tuple1[0])
lenght_word2 = len(tuple2[0])
if lenght_word1 == 10 and lenght_word2 != 10:
return True
if lenght_word2 == 10 and lenght_word1 != 10:
return False
return lenght_word1 < lenght_word2
return score_word1 > score_word2


def get_highest_word_score(word_list):
pass
best_tuple = None
for word in word_list:
current_tuple = word, score_word(word)
if best_tuple is None or higher_than(current_tuple,best_tuple):
best_tuple = current_tuple
return best_tuple




5 changes: 5 additions & 0 deletions tempCodeRunnerFile.python
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
list = [("XXX",1),("XCV",4),("DDD",7)("DER", 9),("ERT",3)]
list_b = ["XXX", "XXXX", "XX", "X"]

for i in range(len(list)):
print(list[i][0])
2 changes: 1 addition & 1 deletion tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_letter_not_selected_too_many_times():

# Assert
for letter in letters:
assert letter_freq[letter] <= LETTER_POOL[letter]
assert letter_freq[letter] <= LETTER_POOL[letter], ("letter: {}".format(letter))

def test_draw_letters_returns_different_hands():
# Arrange/Act
Expand Down
16 changes: 11 additions & 5 deletions tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from adagrams.game import uses_available_letters


def test_uses_available_letters_true_word_in_letter_bank():
# Arrange
letters = ["D", "O", "G", "X", "X", "X", "X", "X", "X", "X"]
Expand All @@ -13,6 +14,7 @@ def test_uses_available_letters_true_word_in_letter_bank():
# Assert
assert is_valid == True


def test_uses_available_letters_false_word_in_letter_bank():
# Arrange
letters = ["D", "O", "X", "X", "X", "X", "X", "X", "X", "X"]
Expand All @@ -24,6 +26,7 @@ def test_uses_available_letters_false_word_in_letter_bank():
# Assert
assert is_valid == False


def test_uses_available_letters_false_word_overuses_letter():
# Arrange
letters = ["A", "X", "X", "X", "X", "X", "X", "X", "X", "X"]
Expand All @@ -35,6 +38,7 @@ def test_uses_available_letters_false_word_overuses_letter():
# Assert
assert is_valid == False


def test_uses_available_letters_does_not_change_letter_bank():
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
Expand All @@ -46,14 +50,16 @@ def test_uses_available_letters_does_not_change_letter_bank():

# Assert
assert is_valid == True
assert letters == letters_copy
assert letters == letters_copy, "pass this difficult test"


def test_uses_available_letters_ignores_case():
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]

# Act/Assert
assert uses_available_letters("bEd", letters)
assert uses_available_letters("fad", letters)
assert uses_available_letters("a", letters)
assert not uses_available_letters("aA", letters)
assert uses_available_letters("bEd", letters), "Test1"
assert uses_available_letters("fad", letters),"Test2"
assert uses_available_letters("a", letters), "Test3"
assert not uses_available_letters("aA", letters), "Test4"

1 change: 1 addition & 0 deletions tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_score_zero_for_empty():
# Assert
assert score_word("") == 0


def test_score_extra_points_for_seven_or_longer():
# Assert
assert score_word("XXXXXXX") == 64
Expand Down
50 changes: 49 additions & 1 deletion tests/test_wave_04.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
import pytest

from adagrams.game import score_word, get_highest_word_score
from adagrams.game import score_word, get_highest_word_score, higher_than

def test_rank_higher_than_returns_False_when_both_tuples_tie_and_have_10_letters():
tuple1 = ("AAAAAAAAAA",18)
tuple2 = ("BBBBBBBBBB",18)

result = higher_than(tuple1,tuple2)

assert result is False

def test_rank_higher_than_returns_True_when_tuple1_has_10_letters():
tuple1 = ("AAAAAAAAAA",18)
tuple2 = ("QJ",18)

result = higher_than(tuple1,tuple2)

assert result is True

def test_rank_higher_than_returns_True_when_scores_are_equal_but_tuple1_is_shorter():
tuple1 = ("QZ", 12)
tuple2 = ("VVVVV",12)

result = higher_than(tuple1,tuple2)

assert result is True

def test_rank_higher_than_returns_False_when_scores_are_equal_but_tuple1_is_longer():
tuple2 = ("QZ",5)
tuple1 = ("VVVVV",5)

result = higher_than(tuple1,tuple2)

assert result is False

def test_rank_higher_than_returns_True_when_tuple1_has_higher_score():
tuple1 = ("QZ",20)
tuple2 = ("AAA",10)

result = higher_than(tuple1, tuple2)

assert result is True

def test_rank_higher_than_returns_False_when_tuple1_has_lower_score():
tuple1 = ("AAA",3)
tuple2 = ("QZ",10)

result = higher_than(tuple1, tuple2)

assert result is False

def test_get_highest_word_score_accurate():
# Arrange
Expand Down