mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Add Python tests
This commit is contained in:
5
03_Animal/python/test_animal.py
Normal file
5
03_Animal/python/test_animal.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from animal import initial_message
|
||||||
|
|
||||||
|
|
||||||
|
def test_initial_message():
|
||||||
|
initial_message()
|
||||||
5
04_Awari/python/test_awari.py
Normal file
5
04_Awari/python/test_awari.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from awari import print_with_tab
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_with_tab():
|
||||||
|
print_with_tab(3, "Hello")
|
||||||
@@ -33,11 +33,12 @@
|
|||||||
|
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
from typing import List
|
||||||
|
|
||||||
MAX_GUESSES = 20
|
MAX_GUESSES = 20
|
||||||
|
|
||||||
|
|
||||||
def print_rules():
|
def print_rules() -> None:
|
||||||
print("\nI am thinking of a three-digit number. Try to guess")
|
print("\nI am thinking of a three-digit number. Try to guess")
|
||||||
print("my number and I will give you clues as follows:")
|
print("my number and I will give you clues as follows:")
|
||||||
print(" PICO - One digit correct but in the wrong position")
|
print(" PICO - One digit correct but in the wrong position")
|
||||||
@@ -45,17 +46,17 @@ def print_rules():
|
|||||||
print(" BAGELS - No digits correct")
|
print(" BAGELS - No digits correct")
|
||||||
|
|
||||||
|
|
||||||
def pick_number():
|
def pick_number() -> List[str]:
|
||||||
# Note that this returns a list of individual digits
|
# Note that this returns a list of individual digits
|
||||||
# as separate strings, not a single integer or string
|
# as separate strings, not a single integer or string
|
||||||
numbers = list(range(10))
|
numbers = list(range(10))
|
||||||
random.shuffle(numbers)
|
random.shuffle(numbers)
|
||||||
num = numbers[0:3]
|
num = numbers[0:3]
|
||||||
num = [str(i) for i in num]
|
num_str = [str(i) for i in num]
|
||||||
return num
|
return num_str
|
||||||
|
|
||||||
|
|
||||||
def get_valid_guess(guesses):
|
def get_valid_guess(guesses: int) -> str:
|
||||||
valid = False
|
valid = False
|
||||||
while not valid:
|
while not valid:
|
||||||
guess = input(f"Guess # {guesses} ? ")
|
guess = input(f"Guess # {guesses} ? ")
|
||||||
@@ -78,8 +79,7 @@ def get_valid_guess(guesses):
|
|||||||
return guess
|
return guess
|
||||||
|
|
||||||
|
|
||||||
def build_result_string(num, guess):
|
def build_result_string(num: List[str], guess: str):
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
# Correct digits in wrong place
|
# Correct digits in wrong place
|
||||||
|
|||||||
5
05_Bagels/python/test_bagels.py
Normal file
5
05_Bagels/python/test_bagels.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from bagels import build_result_string
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_result_string():
|
||||||
|
build_result_string(["a", "b", "c"], "abc")
|
||||||
@@ -110,9 +110,5 @@ def print_banner():
|
|||||||
# print("\n" * 75) # Feed some more paper from the printer
|
# print("\n" * 75) # Feed some more paper from the printer
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
print_banner()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
print_banner()
|
||||||
|
|||||||
Reference in New Issue
Block a user