def test_game_check_win(self):
        user = get_user('lee_test')
        guesses = create_game(user.id)[1]
        for letter in guesses.answer:
            update_guesses(letter, guesses)
        self.assertTrue(check_game(guesses))

        user = get_user('lee_test')
        guesses = create_game(user.id)[1]
        letter = guesses.answer[0]
        update_guesses(letter, guesses)
        self.assertFalse(check_game(guesses))
    def test_game_check_win(self):
        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        for letter in guesses.answer:
            update_guesses(letter, guesses)
        self.assertTrue(check_game(guesses)) 

        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        letter=guesses.answer[0]
        update_guesses(letter, guesses)
        self.assertFalse(check_game(guesses)) 
Пример #3
0
    def test_correct_guess_does_not_decrement_remaining_guesses(self):
        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        guess=guesses.answer[0]
        update_guesses(guess, guesses)
        self.assertEqual(guesses.remaining_guesses, len(guesses.answer))

        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        for letter in alphabet:
            if letter in guesses.answer:
                guess=letter
                break
        update_guesses(guess, guesses)
        self.assertEqual(guesses.remaining_guesses, len(guesses.answer))
    def test_remaining_guess_decrement(self):
        user = get_user('lee_test')
        guesses = create_game(user.id)[1]
        guess = guesses.answer[0]
        update_guesses(guess, guesses)
        self.assertEqual(guesses.remaining_guesses, len(guesses.answer) - 1)

        user = get_user('lee_test')
        guesses = create_game(user.id)[1]
        for letter in alphabet:
            if not letter in guesses.answer:
                guess = letter
                break
        update_guesses(guess, guesses)
        self.assertEqual(guesses.remaining_guesses, len(guesses.answer) - 1)
 def test_correct_guess_replace(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     guess = guesses.answer[0]
     update_guesses(guess, guesses)
     self.assertTrue(any(char.isalpha()
                         for char in guesses.correct_guesses))
 def setUpClass(cls):
     model.db.session.remove()
     model.db.drop_all()
     model.db.create_all()
     model.Word.add_words()
     user=create_user('lee_test', '123_test')
     game=create_game(user.id)[0]
 def setUpClass(cls):
     model.db.session.remove()
     model.db.drop_all()
     model.db.create_all()
     model.Word.add_words()
     user = create_user('lee_test', '123_test')
     game = create_game(user.id)[0]
 def test_guess_not_in_correct(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     guess=guesses.answer[0]
     update_guesses(guess, guesses)
     self.assertEqual(validate_guess(guess, guesses), 
         '"{}" already guessed. Please guess a new letter.'.format(guess))
 def test_guess_not_in_correct(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     guess = guesses.answer[0]
     update_guesses(guess, guesses)
     self.assertEqual(
         validate_guess(guess, guesses),
         '"{}" already guessed. Please guess a new letter.'.format(guess))
Пример #10
0
 def test_incorrect_guess_does_not_display(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     for letter in alphabet:
         if not letter in guesses.answer:
             guess=letter
             break
     update_guesses(guess, guesses)
     self.assertFalse(any(char.isalpha() for char in guesses.correct_guesses))
Пример #11
0
    def test_guess_not_guessed_previously(self):
        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        guess=guesses.answer[0]
        update_guesses(guess, guesses)
        self.assertEqual(validate_guess(guess, guesses),
            '"{}" already guessed. Please guess a new letter.'.format(guess))

        user=get_user('lee_test')
        guesses=create_game(user.id)[1]
        for letter in alphabet:
            if not letter in guesses.answer:
                guess=letter
                break

        update_guesses(guess, guesses)
        self.assertEqual(validate_guess(guess, guesses),
            '"{}" already guessed. Please guess a new letter.'.format(guess))
    def test_update_game_win(self):
        user = get_user('lee_test')
        user_initial_wins = user.wins
        guesses = create_game(user.id)[1]
        for letter in guesses.answer:
            update_guesses(letter, guesses)
        update_game(guesses)

        self.assertEqual(guesses.game.status, 'win')
        self.assertGreater(user.wins, user_initial_wins)
Пример #13
0
 def test_create_get_guesses(self):
     new_user=controller.create_user('ryan_test', '789_test')
     user=controller.get_user('ryan_test')
     guesses=controller.create_game(user.id)[1]
     self.assertTrue(guesses.id)
     self.assertTrue(len(guesses.answer)>0)
     self.assertFalse(guesses.correct_guesses.isalpha())
     self.assertFalse(guesses.incorrect_guesses)
     self.assertTrue(guesses.remaining_guesses>0)
     self.assertTrue(guesses.game_id)
Пример #14
0
 def test_create_get_game(self):
     new_user=controller.create_user('lauren_test', '123_test')
     user=controller.get_user('lauren_test')
     game=controller.create_game(user.id)[0]
     self.assertTrue(game.id)
     self.assertTrue(game.created_date < datetime.utcnow())
     self.assertEqual(game.status, 'in-progress')
     self.assertTrue(len(game.answer)>0)
     self.assertTrue(game.guesses.remaining_guesses>0)
     self.assertTrue(game.user_id)
 def test_incorrect_guess_without_replace(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     for letter in alphabet:
         if not letter in guesses.answer:
             guess = letter
             break
     update_guesses(guess, guesses)
     self.assertFalse(
         any(char.isalpha() for char in guesses.correct_guesses))
Пример #16
0
 def test_create_get_guesses(self):
     new_user = controller.create_user('ryan_test', '789_test')
     user = controller.get_user('ryan_test')
     guesses = controller.create_game(user.id)[1]
     self.assertTrue(guesses.id)
     self.assertTrue(len(guesses.answer) > 0)
     self.assertFalse(guesses.correct_guesses.isalpha())
     self.assertFalse(guesses.incorrect_guesses)
     self.assertTrue(guesses.remaining_guesses > 0)
     self.assertTrue(guesses.game_id)
Пример #17
0
    def test_win_status(self):
        user=get_user('lee_test')
        user_initial_wins=user.wins
        guesses=create_game(user.id)[1]
        for letter in guesses.answer:
            update_guesses(letter, guesses)
        update_game(guesses)

        self.assertEqual(guesses.game.status, 'win')
        self.assertGreater(user.wins, user_initial_wins)
Пример #18
0
 def test_create_get_game(self):
     new_user = controller.create_user('lauren_test', '123_test')
     user = controller.get_user('lauren_test')
     game = controller.create_game(user.id)[0]
     self.assertTrue(game.id)
     self.assertTrue(game.created_date < datetime.utcnow())
     self.assertEqual(game.status, 'in-progress')
     self.assertTrue(len(game.answer) > 0)
     self.assertTrue(game.guesses.remaining_guesses > 0)
     self.assertTrue(game.user_id)
Пример #19
0
    def test_answer_cheat(self):
        user=get_user('lee_test')
        game, guesses=create_game(user.id)
        update_guesses("a", guesses)
        update_answer("h", game)

        self.assertEqual(game.answer, "h")
        self.assertEqual(guesses.answer, "h")
        self.assertEqual(guesses.correct_guesses, '___')
        self.assertEqual(guesses.incorrect_guesses, '')
        self.assertEqual(guesses.remaining_guesses, 1)
    def test_guess_not_in_incorrect(self):
        user = get_user('lee_test')
        guesses = create_game(user.id)[1]
        for letter in alphabet:
            if not letter in guesses.answer:
                guess = letter
                break

        update_guesses(guess, guesses)
        self.assertEqual(
            validate_guess(guess, guesses),
            '"{}" already guessed. Please guess a new letter.'.format(guess))
 def test_game_check_loss(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     alphabet_i = 0
     answer_i = 0
     while len(guesses.answer) > answer_i:
         if guesses.answer[answer_i] != alphabet[alphabet_i]:
             update_guesses(alphabet[alphabet_i], guesses)
             answer_i += 1
             alphabet_i += 1
         else:
             alphabet_i += 1
     self.assertTrue(check_game(guesses))
 def test_game_check_loss(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     alphabet_i = 0
     answer_i = 0
     while len(guesses.answer) > answer_i:
         if guesses.answer[answer_i] != alphabet[alphabet_i]:
             update_guesses(alphabet[alphabet_i], guesses)
             answer_i += 1
             alphabet_i += 1
         else:
             alphabet_i += 1
     self.assertTrue(check_game(guesses))
    def test_update_game_loss(self):
        user=get_user('lee_test')
        user_initial_loses=user.loses
        guesses=create_game(user.id)[1]
        alphabet_i = 0
        answer_i = 0
        while len(guesses.answer) > answer_i:
            if guesses.answer[answer_i] != alphabet[alphabet_i]:
                update_guesses(alphabet[alphabet_i], guesses)
                answer_i += 1
            else:
                alphabet_i += 1
        update_game(guesses)

        self.assertEqual(guesses.game.status, 'loss')
        self.assertGreater(user.loses, user_initial_loses)
    def test_update_game_loss(self):
        user = get_user('lee_test')
        user_initial_loses = user.loses
        guesses = create_game(user.id)[1]
        alphabet_i = 0
        answer_i = 0
        while len(guesses.answer) > answer_i:
            if guesses.answer[answer_i] != alphabet[alphabet_i]:
                update_guesses(alphabet[alphabet_i], guesses)
                answer_i += 1
            else:
                alphabet_i += 1
        update_game(guesses)

        self.assertEqual(guesses.game.status, 'loss')
        self.assertGreater(user.loses, user_initial_loses)
Пример #25
0
 def test_guess_not_letter(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     self.assertEqual(validate_guess('1', guesses), 'Please guess a letter, not punctuation or numbers.')
Пример #26
0
 def test_guess_too_long(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     self.assertEqual(validate_guess('aa', guesses), 'Please guess a single letter.')
     self.assertIsNone(validate_guess('a', guesses))
 def test_guess_length(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     self.assertEqual(validate_guess('aa', guesses),
                      'Please guess a single letter.')
     self.assertIsNone(validate_guess('a', guesses))
Пример #28
0
 def test_correct_guess_displays(self):
     user=get_user('lee_test')
     guesses=create_game(user.id)[1]
     guess=guesses.answer[0]
     update_guesses(guess, guesses)
     self.assertTrue(any(char.isalpha() for char in guesses.correct_guesses))
 def test_guess_alpha(self):
     user = get_user('lee_test')
     guesses = create_game(user.id)[1]
     self.assertEqual(validate_guess('1', guesses),
                      'Please guess a letter, not punction or numbers.')