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)) 
    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)
Example #4
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_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 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))
 def test_create_get_user(self):
     new_user = controller.create_user('jess_test', '123_test')
     user=controller.get_user('jess_test')
     self.assertTrue(user.id > 0)
     self.assertEqual(user.username,'jess_test')
     self.assertEqual(user.password,'123_test')
     self.assertEqual(user.wins, 0)
     self.assertEqual(user.loses, 0)
     self.assertEqual(user.games.count(), 0)
Example #9
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))
Example #10
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))
Example #11
0
 def test_create_get_user(self):
     new_user = controller.create_user('jess_test', '123_test')
     user = controller.get_user('jess_test')
     self.assertTrue(user.id > 0)
     self.assertEqual(user.username, 'jess_test')
     self.assertEqual(user.password, '123_test')
     self.assertEqual(user.wins, 0)
     self.assertEqual(user.loses, 0)
     self.assertEqual(user.games.count(), 0)
Example #12
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)
Example #13
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)
 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)
 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))
    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)
Example #18
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)
Example #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))
Example #23
0
    def test_scores_update(self):
        with hangman_app.test_client() as client:
            data = {'username': '******', 'password': '******'}
            client.post('/login', data=data, follow_redirects=True)
            guesses = controller.get_guesses(flask.session['guesses_id'])
            for guess in range(0, guesses.possible_guesses()):
                data = {'guess': 'abcdefghijklmnopqrstuvwxyz'[guess]}
                client.post('/play', data=data, follow_redirects=True)

            resp = client.get('/scores', follow_redirects=True)
            user = controller.get_user('game_test')

            self.assertEqual(resp.status, '200 OK')
            self.assertTrue(user.wins > 0 or user.loses > 0)
    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)
Example #26
0
    def test_no_repeat_words(self):
        with hangman_app.test_client() as client:
            data = {'username':'******', 'password':'******', 'confirm_password':'******'}
            client.post('/signup', data=data)
            i = 1
            total_words = Word.query.count()
            while i <= total_words:
                client.get('/play', follow_redirects=True)
                answer=get_game(flask.session['game_id']).answer
                for letter in set(answer):
                    client.post('/play', data={'guess':letter}, follow_redirects=True)
                i+=1

            user_words = [game.answer for game in get_user(flask.session['user_id']).games]
            all_words = [word.word for word in Word.query.all()]
            self.assertEqual(sorted(user_words), sorted(all_words))
 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))
Example #28
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.')
Example #29
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_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.')
Example #31
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))