From 8de31763488a3cf8435ad78a7ada8a5adbe785d5 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 19 Mar 2022 12:20:57 +0100 Subject: [PATCH] Add Python tests --- 03_Animal/python/test_animal.py | 5 +++++ 04_Awari/python/test_awari.py | 5 +++++ 05_Bagels/python/bagels.py | 14 +++++++------- 05_Bagels/python/test_bagels.py | 5 +++++ 06_Banner/python/banner.py | 6 +----- 5 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 03_Animal/python/test_animal.py create mode 100644 04_Awari/python/test_awari.py create mode 100644 05_Bagels/python/test_bagels.py diff --git a/03_Animal/python/test_animal.py b/03_Animal/python/test_animal.py new file mode 100644 index 00000000..5ea57ef4 --- /dev/null +++ b/03_Animal/python/test_animal.py @@ -0,0 +1,5 @@ +from animal import initial_message + + +def test_initial_message(): + initial_message() diff --git a/04_Awari/python/test_awari.py b/04_Awari/python/test_awari.py new file mode 100644 index 00000000..87864da8 --- /dev/null +++ b/04_Awari/python/test_awari.py @@ -0,0 +1,5 @@ +from awari import print_with_tab + + +def test_print_with_tab(): + print_with_tab(3, "Hello") diff --git a/05_Bagels/python/bagels.py b/05_Bagels/python/bagels.py index e2a8a1b6..5510a519 100644 --- a/05_Bagels/python/bagels.py +++ b/05_Bagels/python/bagels.py @@ -33,11 +33,12 @@ import random +from typing import List MAX_GUESSES = 20 -def print_rules(): +def print_rules() -> None: print("\nI am thinking of a three-digit number. Try to guess") print("my number and I will give you clues as follows:") print(" PICO - One digit correct but in the wrong position") @@ -45,17 +46,17 @@ def print_rules(): print(" BAGELS - No digits correct") -def pick_number(): +def pick_number() -> List[str]: # Note that this returns a list of individual digits # as separate strings, not a single integer or string numbers = list(range(10)) random.shuffle(numbers) num = numbers[0:3] - num = [str(i) for i in num] - return num + num_str = [str(i) for i in num] + return num_str -def get_valid_guess(guesses): +def get_valid_guess(guesses: int) -> str: valid = False while not valid: guess = input(f"Guess # {guesses} ? ") @@ -78,8 +79,7 @@ def get_valid_guess(guesses): return guess -def build_result_string(num, guess): - +def build_result_string(num: List[str], guess: str): result = "" # Correct digits in wrong place diff --git a/05_Bagels/python/test_bagels.py b/05_Bagels/python/test_bagels.py new file mode 100644 index 00000000..520778e4 --- /dev/null +++ b/05_Bagels/python/test_bagels.py @@ -0,0 +1,5 @@ +from bagels import build_result_string + + +def test_build_result_string(): + build_result_string(["a", "b", "c"], "abc") diff --git a/06_Banner/python/banner.py b/06_Banner/python/banner.py index cd32e87a..d83ac7dc 100644 --- a/06_Banner/python/banner.py +++ b/06_Banner/python/banner.py @@ -110,9 +110,5 @@ def print_banner(): # print("\n" * 75) # Feed some more paper from the printer -def main(): - print_banner() - - if __name__ == "__main__": - main() + print_banner()