Reformat all code with black formatter.

This commit is contained in:
dongar committed 2023-05-23 12:06:13 -05:00
1 parent 497c48f853
commit 7cf685b507
4 files changed
+66 -38

No files matched your search

+6 -5
View File
@@ -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("/<g1>/<g2>/<g3>/<g4>/<g5>")
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>/<g6>")
def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None):
constraints = wordle.Constraints()
guesses = []
@@ -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
)
+8 -6
View File
@@ -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()
+52 -26
View File
@@ -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()
-1
View File
@@ -24,7 +24,6 @@ class InvalidWord(Exception):
pass
def select_word():
return random.choice(list(dictionary.words()))