From: Skullheadx <704277@pdsb.net> Date: Wed, 4 Jan 2023 23:48:46 +0000 (-0500) Subject: readme + better file support + better output X-Git-Url: http://git.skullheadx.com/nixos/projects.html?a=commitdiff_plain;h=8486babb61eb6890222abb5b7b1ca87b88eac3a3;p=ccc-grader.git readme + better file support + better output --- diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ca0fce --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# CCC-Grader + +_Python Code to grade solutions to the CCC using test data from their website._ + +CEMC Website: https://cemc.uwaterloo.ca/contests/past_contests.html + +------------------------------------------------------------------ +**HOW TO USE**: +1. Scroll to the bottom of https://cemc.uwaterloo.ca/contests/past_contests.html +2. Click on the contest you are attempting +3. Download the Test Data +4. Extract the senior or junior folder into the input directory in the grader project +5. Copy your python file (.py) into the input folder +6. Run the grader.py file using python +7. Enjoy your grader. It will tell you your time and incorrect test cases + +_Note: This program will run the code on your computer which is assuredly faster than the computers that actually grade the contest, hence a margin of error is created._ \ No newline at end of file diff --git a/grader.py b/grader.py index c2b5415..f1f07c1 100644 --- a/grader.py +++ b/grader.py @@ -16,17 +16,33 @@ for root, dirs, files in os.walk(PATH): if FILENAME is None: raise FileNotFoundError -test_input_path = os.path.join(PATH, f"windows_data/senior/{PROBLEM}/") +if PROBLEM[0] == "S" or PROBLEM[0] == "s": + contest = "senior" +elif PROBLEM[0] == "J" or PROBLEM[0] == "j": + contest = "junior" +else: + contest = input("Please enter name of contest; 'senior' or 'junior': ") + +test_input_path = os.path.join(PATH, os.path.join(contest, PROBLEM)) test_inputs = [] test_outputs = [] + for root, dirs, files in os.walk(test_input_path): for i, file in enumerate(files): with open(os.path.join(root, file), "r") as f: - if i % 2 == 0: # CCC test cases alternate between IN and OUT files. - test_inputs.append(f.read()) + # CCC test cases alternate between IN and OUT files. + if "sample" in file: + if i % 2 == 0: + test_inputs.insert(0,f.read()) + else: + test_outputs.insert(0,f.read()) else: - test_outputs.append(f.read()) + if i % 2 == 0: + test_inputs.append(f.read()) + else: + test_outputs.append(f.read()) + total = min(len(test_inputs), len(test_outputs)) # Total number of questions correct = 0 # how many are correct answered @@ -34,7 +50,8 @@ correct = 0 # how many are correct answered print("-" * 30) print(f"Evaluating {FILENAME}") -for test_input, test_output in zip(test_inputs, test_outputs): # loop through each input and output +for i, test in enumerate(zip(test_inputs, test_outputs)): # loop through each input and output + test_input, test_output = test with Capturing() as program_output: # Capture output from print() start = time.perf_counter() # getting start time run(os.path.join(PATH, FILENAME), test_input) # running the program + input @@ -47,10 +64,10 @@ for test_input, test_output in zip(test_inputs, test_outputs): # loop through e test_output = test_output[:-1] # Check if the program output is correct. if program_output == test_output: - print(f"Test Passed. {program_time}s") + print(f"{i+1}. Test Passed. {program_time}s") correct += 1 else: - print(f"Test Failed. {program_time}s") + print(f"{i+1}. Test Failed. {program_time}s") print(f"{test_input = }") print(f"{test_output = }") print(f"{program_output = }")