]> Skullheadx's Git Forge - ccc-grader.git/commitdiff
readme + better file support + better output
authorSkullheadx <704277@pdsb.net>
Wed, 4 Jan 2023 23:48:46 +0000 (18:48 -0500)
committerSkullheadx <704277@pdsb.net>
Wed, 4 Jan 2023 23:48:46 +0000 (18:48 -0500)
README.md [new file with mode: 0644]
grader.py

diff --git a/README.md b/README.md
new file mode 100644 (file)
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
index c2b54157cb7e1b30e057ea4323267b771b748dda..f1f07c1a666af2b1970a94d1eecd2527e23d5cfa 100644 (file)
--- 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 = }")