From 7cf685b50723816327773c6225edfc81cb326fc9 Mon Sep 17 00:00:00 2001 From: Don Garrett Date: Tue, 23 May 2023 12:06:13 -0500 Subject: [PATCH] Reformat all code with black formatter. --- app.py | 13 +++++---- play.py | 14 +++++---- test_wordle.py | 78 +++++++++++++++++++++++++++++++++----------------- wordle.py | 1 - 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/app.py b/app.py index 9792f36..1d8f3de 100644 --- a/app.py +++ b/app.py @@ -7,8 +7,9 @@ import wordle app = Flask(__name__) + def parse_guess(guess): - return 'foody', 'CICMI' + return "foody", "CICMI" @app.route("/") @@ -19,7 +20,6 @@ def parse_guess(guess): @app.route("/////") @app.route("//////") def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None): - constraints = wordle.Constraints() guesses = [] @@ -31,7 +31,7 @@ def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None): if parsed_guess: guesses.append(parsed_guess) - if parsed_result: + if parsed_result: results.append(parsed_result) if parsed_guess and parsed_result: @@ -63,7 +63,8 @@ def dictionary(page=0): start_word = page * PAGE_SIZE end_word = start_word + PAGE_SIZE - words = words[start_word: end_word] + words = words[start_word:end_word] - return render_template("dictionary.html", - page=page, max_pages=max_pages, words=words) + return render_template( + "dictionary.html", page=page, max_pages=max_pages, words=words + ) diff --git a/play.py b/play.py index dccda57..84e44ca 100644 --- a/play.py +++ b/play.py @@ -6,7 +6,8 @@ import wordle def display_instructions(): """Print out instuctions before starting play.""" - print(f"""Welcome to Wordle! + print( + f"""Welcome to Wordle! Wordle has a hidden word of five letters, and you get to make up to six guesses to find out what it is. @@ -15,12 +16,13 @@ def display_instructions(): * {wordle.display_result(wordle.LetterResult.CORRECT, "Correct!")} * {wordle.display_result(wordle.LetterResult.MOVE, "Correct, in a different location.")} * {wordle.display_result(wordle.LetterResult.INCORRECT, "Not in the word.")} - """) + """ + ) def read_valid_guess(guess_number): while True: - print(f"Guess {guess_number}: ", end='') + print(f"Guess {guess_number}: ", end="") guess = input() if guess in wordle.dictionary(): return guess @@ -29,9 +31,9 @@ def read_valid_guess(guess_number): def display_results(guess, results): - print(" ", end='') + print(" ", end="") for i in range(wordle.WORDLE_LENGTH): - print(wordle.display_result(results[i], guess[i]), end='') + print(wordle.display_result(results[i], guess[i]), end="") print("") @@ -56,5 +58,5 @@ def play_game(): print(f"Sorry, no guesses remaining. The word was: {target}") -if __name__ == '__main__': +if __name__ == "__main__": play_game() diff --git a/test_wordle.py b/test_wordle.py index d3a8e4e..58bb1e9 100644 --- a/test_wordle.py +++ b/test_wordle.py @@ -9,49 +9,75 @@ import unittest class TestConstraints(unittest.TestCase): - def test_empty(self): constraints = wordle.Constraints() - self.assertTrue(constraints.matches('abcde')) - self.assertTrue(constraints.matches('bcdef')) + self.assertTrue(constraints.matches("abcde")) + self.assertTrue(constraints.matches("bcdef")) def test_correct(self): constraints = wordle.Constraints() - constraints.update_graded('abcde', [LetterResult.CORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT]) + constraints.update_graded( + "abcde", + [ + LetterResult.CORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + ], + ) - self.assertTrue(constraints.matches('amnop')) - self.assertTrue(constraints.matches('aaaaa')) + self.assertTrue(constraints.matches("amnop")) + self.assertTrue(constraints.matches("aaaaa")) - self.assertFalse(constraints.matches('abcde')) - self.assertFalse(constraints.matches('lmnop')) - self.assertFalse(constraints.matches('aedcb')) - self.assertFalse(constraints.matches('amnob')) + self.assertFalse(constraints.matches("abcde")) + self.assertFalse(constraints.matches("lmnop")) + self.assertFalse(constraints.matches("aedcb")) + self.assertFalse(constraints.matches("amnob")) def test_correct_count_limit(self): constraints = wordle.Constraints() - constraints.update_graded('aazzz', [LetterResult.CORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT]) + constraints.update_graded( + "aazzz", + [ + LetterResult.CORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + ], + ) - self.assertTrue(constraints.matches('abcde')) - self.assertTrue(constraints.matches('abbbb')) + self.assertTrue(constraints.matches("abcde")) + self.assertTrue(constraints.matches("abbbb")) - self.assertFalse(constraints.matches('aabbb')) - self.assertFalse(constraints.matches('abbba')) - self.assertFalse(constraints.matches('bbbbb')) - self.assertFalse(constraints.matches('bbbba')) - self.assertFalse(constraints.matches('babbb')) + self.assertFalse(constraints.matches("aabbb")) + self.assertFalse(constraints.matches("abbba")) + self.assertFalse(constraints.matches("bbbbb")) + self.assertFalse(constraints.matches("bbbba")) + self.assertFalse(constraints.matches("babbb")) def test_move(self): constraints = wordle.Constraints() - constraints.update_graded('abcde', [LetterResult.MOVE, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT]) + constraints.update_graded( + "abcde", + [ + LetterResult.MOVE, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + LetterResult.INCORRECT, + ], + ) - self.assertTrue(constraints.matches('zzzza')) - self.assertTrue(constraints.matches('zzzaa')) - self.assertTrue(constraints.matches('zaaaa')) + self.assertTrue(constraints.matches("zzzza")) + self.assertTrue(constraints.matches("zzzaa")) + self.assertTrue(constraints.matches("zaaaa")) - self.assertFalse(constraints.matches('azzzz')) - self.assertFalse(constraints.matches('zzzzz')) - self.assertFalse(constraints.matches('zzzba')) + self.assertFalse(constraints.matches("azzzz")) + self.assertFalse(constraints.matches("zzzzz")) + self.assertFalse(constraints.matches("zzzba")) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/wordle.py b/wordle.py index af1cb9a..f4f6212 100644 --- a/wordle.py +++ b/wordle.py @@ -24,7 +24,6 @@ class InvalidWord(Exception): pass - def select_word(): return random.choice(list(dictionary.words()))