def test_should_return_false_if_doesnt_have_letter(self): og_word = 'abc def hij' sw = SecretWord(word=og_word) assert not sw.has_letter('K') assert not sw.has_letter('R') assert not sw.has_letter('M')
def test_should_not_care_about_case_sensitive(self): og_word = 'abc def hij' sw = SecretWord(word=og_word) assert sw.has_letter('a') assert sw.has_letter('b') assert sw.has_letter('c')
def test_should_return_the_word_as_a_list_with_valid_letters_replaced( self): og_word = 'Spider-Man 3: Venom' sw = SecretWord(word=og_word) hidden_word = sw.get_hidden_word() assert ' '.join(hidden_word) == '_ _ _ _ _ _ - _ _ _ _ : _ _ _ _ _'
def test_should_return_the_value_set_for__hidden_word(self): og_word = 'just a test' sw = SecretWord(word='a') sw._hidden_word = 'just a test' word = sw.get_hidden_word() assert word == og_word
def test_should_return_true_if_has_letter(self): og_word = 'abc def hij' sw = SecretWord(word=og_word) assert sw.has_letter('A') assert sw.has_letter('B') assert sw.has_letter('D')
def test_should_return_false_for_special_characters(self): from_underscore = SecretWord._is_letter_valid('_') from_dash = SecretWord._is_letter_valid('-') from_exclamation = SecretWord._is_letter_valid('!') from_space = SecretWord._is_letter_valid(' ') assert not from_underscore assert not from_dash assert not from_exclamation assert not from_space
def test_should_only_map_valid_letters(self): sw = SecretWord(word='Spider-Man 3: Venom') mapped_positions = sw._map_positions() assert len(mapped_positions['E']) == 2 assert len(mapped_positions['S']) == 1 assert len(mapped_positions['3']) == 1 assert len(mapped_positions[' ']) == 0 assert len(mapped_positions['-']) == 0 assert len(mapped_positions[':']) == 0
def test_should_use_the_passed_word_as_the_secret_word(self): sw = SecretWord(word='Sabão em pó') assert sw.get_word() == 'SABÃO EM PÓ' assert sw.get_hidden_word().count('_') == 9 assert sw.get_letter_count('a') == 2 assert sw.get_letter_count('o') == 2 assert sw.get_letter_count('e') == 1 assert len(sw._previously_guessed_letters) == 0 assert not sw.was_guessed
def test_should_get_random_word_if_a_theme_is_passed(self): seed(3) sw = SecretWord('video_games') assert sw.get_word() == 'ASTRO BOT' assert sw.get_hidden_word().count('_') == 8 assert sw.get_letter_count('a') == 1 assert sw.get_letter_count('o') == 2 assert sw.get_letter_count('e') == 0 assert sw.get_letter_count('t') == 2 assert len(sw._previously_guessed_letters) == 0 assert not sw.was_guessed
def test_should_return_only_the_first_letter_if_a_word_is_given(self): letter = SecretWord._normalize_letter('word') assert letter == 'W'
def test_should_return_true_for_letter_with_accentuation(self): from_letter_with_accentuation = SecretWord._is_letter_valid('Á') assert from_letter_with_accentuation
def test_should_return_true_for_upper_case_letter(self): from_upper_letter = SecretWord._is_letter_valid('A') assert from_upper_letter
def test_should_return_true_for_lower_cased_letter(self): from_lower_letter = SecretWord._is_letter_valid('a') assert from_lower_letter
def test_should_return_true_for_number(self): from_number = SecretWord._is_letter_valid('1') assert from_number
def test_should_throw_error_if_the_theme_doesnt_exists(self): with pytest.raises(FileNotFoundError): SecretWord._get_random_secret_word('a9s7d9a87sd9')
def test_should_get_random_word_from_theme(self): theme = 'fruits' seed(3) word = SecretWord._get_random_secret_word(theme) assert word == 'banana'
def test_should_raise_error_if_no_word_or_theme_is_passed(self): with pytest.raises(TypeError): SecretWord._get_random_secret_word()
def test_should_raise_error_if_no_theme_or_word_is_passed(self): with pytest.raises(RequiredField): SecretWord()
def secret_word(): return SecretWord(word='Sabão em pó')
def test_should_return_upper_cased_letter(self): letter = SecretWord._normalize_letter('z') assert letter == 'Z'
def test_should_return_a_upper_cased_and_stripped_word(self): og_word = ' la casa de papel ' sw = SecretWord(word=og_word) word = sw.get_word() assert word == og_word.upper().strip()
def test_should_strip_all_spaces_before_and_after_the_letter(self): letter = SecretWord._normalize_letter(' a ') assert letter == 'A'
def test_should_return_accented_letter_without_accentuation(self): letter = SecretWord._normalize_letter('á') assert letter == 'A'