add tests for task1

This commit is contained in:
2026-01-29 23:15:45 +05:00
parent 0658a15911
commit 1e5dbe95ec
9 changed files with 207 additions and 55 deletions

63
1. problem_rl/test.py Executable file
View File

@@ -0,0 +1,63 @@
#!/usr/bin/env python
from pathlib import Path
from subprocess import run
tests_1: dict = {
"2 1" : "1",
"3 2" : "1",
"2 4" : "2",
"1769 427" : "61",
"698917 -102089" : "7853",
"917 872" : "1",
"-417143 -455947" : "9701",
"63862 -55298" : "2",
"702228 373125" : "3",
"-659323 727699" : "7"
}
def test(file_name: str, compile_cmd: str, run_cmd: list[str], tests_dict: dict):
print(f"=== TESTING {file_name.upper()} ===")
file_path = Path(file_name)
if not file_path.is_file():
print(f"file '{file_name}' was not found.")
return
print(f"{file_name} found")
run([compile_cmd, file_name], check=True)
for t, res in tests_dict.items():
out = run(
run_cmd,
input=t,
text=True,
capture_output=True
)
program_result = out.stdout.strip()
if program_result != res:
print("test failed:")
print(f"\ttest: {t}")
print(f"\tprogram result: {program_result}")
print(f"\tcorrect result: {res}")
break
else:
print("test passed:")
print(f"\ttest: {t}")
print(f"\tresult: {res}")
else:
print("all tests passed!")
def main():
test("solution.c", "gcc", ["./a.out"], tests_1)
test("solution.cpp", "g++", ["./a.out"], tests_1)
if __name__ == "__main__":
main()