예제 #1
0
    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')
예제 #2
0
    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')
예제 #3
0
    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) == '_ _ _ _ _ _ - _ _ _   _ :   _ _ _ _ _'
예제 #4
0
    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
예제 #5
0
    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')
예제 #6
0
    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
예제 #7
0
    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
예제 #8
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
예제 #9
0
    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
예제 #10
0
 def test_should_return_only_the_first_letter_if_a_word_is_given(self):
     letter = SecretWord._normalize_letter('word')
     assert letter == 'W'
예제 #11
0
 def test_should_return_true_for_letter_with_accentuation(self):
     from_letter_with_accentuation = SecretWord._is_letter_valid('Á')
     assert from_letter_with_accentuation
예제 #12
0
 def test_should_return_true_for_upper_case_letter(self):
     from_upper_letter = SecretWord._is_letter_valid('A')
     assert from_upper_letter
예제 #13
0
 def test_should_return_true_for_lower_cased_letter(self):
     from_lower_letter = SecretWord._is_letter_valid('a')
     assert from_lower_letter
예제 #14
0
 def test_should_return_true_for_number(self):
     from_number = SecretWord._is_letter_valid('1')
     assert from_number
예제 #15
0
 def test_should_throw_error_if_the_theme_doesnt_exists(self):
     with pytest.raises(FileNotFoundError):
         SecretWord._get_random_secret_word('a9s7d9a87sd9')
예제 #16
0
 def test_should_get_random_word_from_theme(self):
     theme = 'fruits'
     seed(3)
     word = SecretWord._get_random_secret_word(theme)
     assert word == 'banana'
예제 #17
0
 def test_should_raise_error_if_no_word_or_theme_is_passed(self):
     with pytest.raises(TypeError):
         SecretWord._get_random_secret_word()
예제 #18
0
 def test_should_raise_error_if_no_theme_or_word_is_passed(self):
     with pytest.raises(RequiredField):
         SecretWord()
예제 #19
0
def secret_word():
    return SecretWord(word='Sabão em pó')
예제 #20
0
 def test_should_return_upper_cased_letter(self):
     letter = SecretWord._normalize_letter('z')
     assert letter == 'Z'
예제 #21
0
    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()
예제 #22
0
 def test_should_strip_all_spaces_before_and_after_the_letter(self):
     letter = SecretWord._normalize_letter('     a     ')
     assert letter == 'A'
예제 #23
0
 def test_should_return_accented_letter_without_accentuation(self):
     letter = SecretWord._normalize_letter('á')
     assert letter == 'A'