--- /dev/null
+# 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
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
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
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 = }")