Add Python tests

This commit is contained in:
Martin Thoma
2022-03-19 12:20:57 +01:00
parent 157446f209
commit 8de3176348
5 changed files with 23 additions and 12 deletions

View File

@@ -0,0 +1,5 @@
from animal import initial_message
def test_initial_message():
initial_message()

View File

@@ -0,0 +1,5 @@
from awari import print_with_tab
def test_print_with_tab():
print_with_tab(3, "Hello")

View File

@@ -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

View File

@@ -0,0 +1,5 @@
from bagels import build_result_string
def test_build_result_string():
build_result_string(["a", "b", "c"], "abc")

View File

@@ -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()