From 673344b36be22fff38be3fcfe45b2a16b373d9ff Mon Sep 17 00:00:00 2001 From: didier amyot Date: Wed, 20 Dec 2023 13:29:54 -0500 Subject: [PATCH] added test --- pytestdemo/paranthesis_test.py | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pytestdemo/paranthesis_test.py diff --git a/pytestdemo/paranthesis_test.py b/pytestdemo/paranthesis_test.py new file mode 100644 index 0000000..b6d012e --- /dev/null +++ b/pytestdemo/paranthesis_test.py @@ -0,0 +1,53 @@ +import io, typing +from pathlib import Path + + +def is_balanced_file_object(file_object: typing.IO[str]) -> bool: + text = file_object.read() + counter = 0 + for letter in text: + if letter == "(": + counter += 1 + if letter == ")": + counter -= 1 + if counter < 0: + return False + return counter == 0 + + +def is_balanced_file(file_path: Path) -> bool: + with open(file_path, "r") as file_: + return is_balanced_file_object(file_) + + +def test_is_balanced_file_object() -> None: + assert is_balanced_file_object(io.StringIO("")) + assert is_balanced_file_object(io.StringIO("()")) + assert is_balanced_file_object(io.StringIO("(()())")) + assert not is_balanced_file_object(io.StringIO("((())")) + assert not is_balanced_file_object(io.StringIO("(()))")) + assert not is_balanced_file_object(io.StringIO(")")) + + +def get_first_two_numbers(lst, target): + for e in lst: + if (target - e) in lst: + return tuple(sorted((e, target - e))) + + +def test_get_two_numbers(): + lst = [55, 20, 76, 34, 80, 26] + target = 100 + assert get_first_two_numbers(lst, target) == (20, 80) + + +def test_get_two_numbers_2(): + lst = [55, 80, 76, 34, 20, 26] + target = 100 + assert get_first_two_numbers(lst, target) == (20, 80) + + +def test_get_two_numbers_3(): + lst = [55, 30, 80, 76, 34, 70, 20, 26] + target = 100 + # assert get_first_two_numbers(lst, target) == (20, 80)