]> Skullheadx's Git Forge - ccc-grader.git/commitdiff
fixed
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Fri, 16 Jun 2023 15:28:05 +0000 (11:28 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Fri, 16 Jun 2023 15:28:05 +0000 (11:28 -0400)
code/main.py [new file with mode: 0644]
grader.py
input/.gitignore [deleted file]
runner.py
tests/input/case1.txt [new file with mode: 0644]
tests/input/case2.txt [new file with mode: 0644]
tests/input/case3.txt [new file with mode: 0644]
tests/output/case1.txt [new file with mode: 0644]
tests/output/case2.txt [new file with mode: 0644]
tests/output/case3.txt [new file with mode: 0644]

diff --git a/code/main.py b/code/main.py
new file mode 100644 (file)
index 0000000..ad13982
--- /dev/null
@@ -0,0 +1,5 @@
+n = int(input())
+
+for i in range(n):
+    x = int(input())
+    print(x + 1)
index f1f07c1a666af2b1970a94d1eecd2527e23d5cfa..21bc2d15f25037a37847d394860132b2f77c452d 100644 (file)
--- a/grader.py
+++ b/grader.py
@@ -3,65 +3,42 @@ import time
 from runner import run
 from capture import Capturing
 
-PATH = "input/"
-PROBLEM = input("Enter the name of the problem: ")  # i.e. S1
-FILENAME = None
-extension = ".py"
-
-for root, dirs, files in os.walk(PATH):
-    for file in files:
-        if file[-file[::-1].index(".") - 1:] == extension:
-            FILENAME = file
-
-if FILENAME is None:
-    raise FileNotFoundError
-
-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))
-
+code = "code/main.py"
 test_inputs = []
 test_outputs = []
 
-for root, dirs, files in os.walk(test_input_path):
+# Getting all the test inputs and outputs
+# the corresponding input and output files should be in the same order
+for root, dirs, files in os.walk("tests/input"):
     for i, file in enumerate(files):
         with open(os.path.join(root, file), "r") as f:
-            # 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:
-                if i % 2 == 0:
-                    test_inputs.append(f.read())
-                else:
-                    test_outputs.append(f.read())
+            test_inputs.append(f.read())
+
+for root, dirs, files in os.walk("tests/output"):
+    for i, file in enumerate(files):
+        with open(os.path.join(root, file), "r") as f:
+            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}")
+print(f"Evaluating {code}\n")
 
 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
+        run(code, test_input)  # running the program + input
         end = time.perf_counter()  # getting end time
 
     program_time = max(round(end - start, 3), 1 * 10 ** -3)  # So the output doesn't say 0.0s
 
     program_output = "\n".join(program_output)
     if test_output[-1] == "\n":
-        test_output = test_output[:-1]
+        test_output = test_output[:-1] # removing trailing newlines in the test output
+
     # Check if the program output is correct.
     if program_output == test_output:
         print(f"{i+1}. Test Passed. {program_time}s")
@@ -73,5 +50,5 @@ for i, test in enumerate(zip(test_inputs, test_outputs)):  # loop through each i
         print(f"{program_output = }")
         print()
 
-print("-" * 30)
 print(f"Tests passed: {correct}/{total}")
+print("-" * 30)
diff --git a/input/.gitignore b/input/.gitignore
deleted file mode 100644 (file)
index d6b7ef3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
index 70e90205776b214536a8628fd42f51d4bf8f4ae6..6019b01894184167ec712491340202e4da6f88a5 100644 (file)
--- a/runner.py
+++ b/runner.py
@@ -1,6 +1,7 @@
 from io import StringIO
 import sys
 
+
 # Running the code in a separate file because there can be variable conflicts in the grader.py file (i.e. output)
 def run(file_path, test_input):
     sys.stdin = StringIO(test_input)  # Enter the test input
diff --git a/tests/input/case1.txt b/tests/input/case1.txt
new file mode 100644 (file)
index 0000000..1191247
--- /dev/null
@@ -0,0 +1,2 @@
+1
+2
diff --git a/tests/input/case2.txt b/tests/input/case2.txt
new file mode 100644 (file)
index 0000000..dcf37cd
--- /dev/null
@@ -0,0 +1,3 @@
+2
+3
+4
diff --git a/tests/input/case3.txt b/tests/input/case3.txt
new file mode 100644 (file)
index 0000000..dc5f2ef
--- /dev/null
@@ -0,0 +1,4 @@
+3
+4
+5
+6
diff --git a/tests/output/case1.txt b/tests/output/case1.txt
new file mode 100644 (file)
index 0000000..00750ed
--- /dev/null
@@ -0,0 +1 @@
+3
diff --git a/tests/output/case2.txt b/tests/output/case2.txt
new file mode 100644 (file)
index 0000000..61c83cb
--- /dev/null
@@ -0,0 +1,2 @@
+4
+5
diff --git a/tests/output/case3.txt b/tests/output/case3.txt
new file mode 100644 (file)
index 0000000..e64e44e
--- /dev/null
@@ -0,0 +1,3 @@
+5
+6
+7