Skip to content

Commit cca2596

Browse files
committed
Correct the locations of some submissions
1 parent fe9c3c9 commit cca2596

33 files changed

+743
-756
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
name: Test Student Submissions
2-
3-
on:
4-
push:
5-
branches:
6-
- main
7-
8-
jobs:
9-
test-submissions:
10-
runs-on: ubuntu-latest
11-
12-
steps:
13-
# Check out the repository code
14-
- name: Check out code
15-
uses: actions/checkout@v2
16-
17-
# Set up Python environment
18-
- name: Set up Python
19-
uses: actions/setup-python@v2
20-
with:
21-
python-version: "3.x"
22-
23-
# Install dependencies (if any)
24-
- name: Install dependencies
25-
run: |
26-
pip install -r requirements.txt || true # No dependencies, skip if empty
27-
28-
# Run the script to test student submissions
29-
- name: Run submission tests
30-
run: |
31-
python run_submissions.py
1+
name: Test Student Submissions
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test-submissions:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Check out the repository code
14+
- name: Check out code
15+
uses: actions/checkout@v2
16+
17+
# Set up Python environment
18+
- name: Set up Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: "3.x"
22+
23+
# Install dependencies (if any)
24+
- name: Install dependencies
25+
run: |
26+
pip install -r requirements.txt || true # No dependencies, skip if empty
27+
28+
# Run the script to test student submissions
29+
- name: Run submission tests
30+
run: |
31+
python run_submissions.py

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ On point for each of the following:
101101
---
102102

103103
## Submission Deadline
104-
- Your pull request must be submitted by Sunday 2/1/2025 at 11:59.
104+
- Your pull request must be submitted by Sunday 9/14/2025 at 11:59.
105105

106106
---
107107

math_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# math_utils.py
2-
# Your task is to implement the following function
3-
4-
5-
def gcd(a: int, b: int) -> int:
6-
"""
7-
Calculate the greatest common divisor (GCD) of two integers a and b
8-
using the Euclidean algorithm.
9-
"""
10-
pass # Replace this line with your implementation
1+
# math_utils.py
2+
# Your task is to implement the following function
3+
4+
5+
def gcd(a: int, b: int) -> int:
6+
"""
7+
Calculate the greatest common divisor (GCD) of two integers a and b
8+
using the Euclidean algorithm.
9+
"""
10+
pass # Replace this line with your implementation

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
iniconfig==2.0.0
2-
packaging==24.1
3-
pluggy==1.5.0
4-
pytest==8.3.3
1+
iniconfig==2.0.0
2+
packaging==24.1
3+
pluggy==1.5.0
4+
pytest==8.3.3

run_submissions.py

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
1-
import glob
2-
import os
3-
import ast
4-
from sympy import isprime # Import isprime here
5-
6-
7-
def run_gcd_test(gcd_func, a, b, expected):
8-
"""
9-
Runs a test case for the gcd function.
10-
"""
11-
result = gcd_func(a, b)
12-
if result == expected:
13-
print(f"PASS: gcd({a}, {b}) = {result}")
14-
else:
15-
print(f"FAIL: gcd({a}, {b}) = {result}, expected {expected}")
16-
17-
18-
def load_and_run():
19-
"""
20-
Detect and run all student submissions from the students_submissions directory.
21-
Each student's submission is expected to be in a file named gcd_<GitHubUsername>.py.
22-
"""
23-
# Find all the files in the students_submissions directory matching the pattern gcd_*.py
24-
student_files = glob.glob("students_submissions/gcd_*.py")
25-
26-
for file in student_files:
27-
28-
if file in [
29-
"students_submissions/gcd_dt393.py", # NameError: name 'math' is not defined. Did you forget to import 'math'?
30-
"students_submissions/gcd_zlk.py", # ZeroDivisionError: integer modulo by zero
31-
]:
32-
continue
33-
34-
# Extract the student's GitHub username or identifier from the filename
35-
module_name = os.path.splitext(os.path.basename(file))[0]
36-
37-
# Read the student's code
38-
with open(file, "r") as f:
39-
student_code = f.read()
40-
41-
# Parse the student's code to extract all function definitions
42-
parsed_code = ast.parse(student_code)
43-
functions = {}
44-
for node in parsed_code.body:
45-
if isinstance(node, ast.FunctionDef):
46-
func_code = compile(
47-
ast.Module(body=[node], type_ignores=[]),
48-
filename="<ast>",
49-
mode="exec",
50-
)
51-
func_namespace = {}
52-
exec(func_code, func_namespace)
53-
functions[node.name] = func_namespace[node.name]
54-
55-
# Check if the gcd function was found and run the test cases
56-
if "gcd" in functions:
57-
gcd_func = functions["gcd"]
58-
# Ensure all necessary functions are available in the namespace
59-
gcd_func.__globals__.update(functions)
60-
gcd_func.__globals__["isprime"] = (
61-
isprime # Add isprime to the global namespace
62-
)
63-
print(f"Running {module_name}'s submission...")
64-
# run_gcd_test(gcd_func, 54, 24, 6)
65-
# run_gcd_test(gcd_func, 48, 18, 6)
66-
# run_gcd_test(gcd_func, 101, 10, 1)
67-
# run_gcd_test(gcd_func, 270, 192, 6)
68-
# Edge case test cases
69-
run_gcd_test(gcd_func, 0, 0, None) # Both numbers are zero
70-
run_gcd_test(gcd_func, -54, 24, 6) # One negative number
71-
run_gcd_test(gcd_func, 54, -24, 6) # One negative number
72-
run_gcd_test(gcd_func, -54, -24, 6) # Both numbers are negative
73-
run_gcd_test(gcd_func, 0, 24, 24) # One number is zero
74-
run_gcd_test(gcd_func, 24, 0, 24) # One number is zero
75-
run_gcd_test(gcd_func, 17, 13, 1) # Both numbers are prime
76-
run_gcd_test(gcd_func, 1000000000, 2, 2) # Large number and small number
77-
run_gcd_test(gcd_func, 123456789, 987654321, 9) # Large numbers
78-
run_gcd_test(gcd_func, 1, 1, 1) # Both numbers are one
79-
print()
80-
else:
81-
print(f"ERROR: {module_name}'s submission does not have a gcd function\n")
82-
83-
84-
# This is the entry point of the script
85-
if __name__ == "__main__":
86-
load_and_run()
1+
import glob
2+
import os
3+
import ast
4+
from sympy import isprime # Import isprime here
5+
6+
7+
def run_gcd_test(gcd_func, a, b, expected):
8+
"""
9+
Runs a test case for the gcd function.
10+
"""
11+
result = gcd_func(a, b)
12+
if result == expected:
13+
print(f"PASS: gcd({a}, {b}) = {result}")
14+
else:
15+
print(f"FAIL: gcd({a}, {b}) = {result}, expected {expected}")
16+
17+
18+
def load_and_run():
19+
"""
20+
Detect and run all student submissions from the students_submissions directory.
21+
Each student's submission is expected to be in a file named gcd_<GitHubUsername>.py.
22+
"""
23+
# Find all the files in the students_submissions directory matching the pattern gcd_*.py
24+
student_files = glob.glob("students_submissions/gcd_*.py")
25+
26+
for file in student_files:
27+
28+
if file in [
29+
"students_submissions/gcd_dt393.py", # NameError: name 'math' is not defined. Did you forget to import 'math'?
30+
"students_submissions/gcd_zlk.py", # ZeroDivisionError: integer modulo by zero
31+
]:
32+
continue
33+
34+
# Extract the student's GitHub username or identifier from the filename
35+
module_name = os.path.splitext(os.path.basename(file))[0]
36+
37+
# Read the student's code
38+
with open(file, "r") as f:
39+
student_code = f.read()
40+
41+
# Parse the student's code to extract all function definitions
42+
parsed_code = ast.parse(student_code)
43+
functions = {}
44+
for node in parsed_code.body:
45+
if isinstance(node, ast.FunctionDef):
46+
func_code = compile(
47+
ast.Module(body=[node], type_ignores=[]),
48+
filename="<ast>",
49+
mode="exec",
50+
)
51+
func_namespace = {}
52+
exec(func_code, func_namespace)
53+
functions[node.name] = func_namespace[node.name]
54+
55+
# Check if the gcd function was found and run the test cases
56+
if "gcd" in functions:
57+
gcd_func = functions["gcd"]
58+
# Ensure all necessary functions are available in the namespace
59+
gcd_func.__globals__.update(functions)
60+
gcd_func.__globals__["isprime"] = (
61+
isprime # Add isprime to the global namespace
62+
)
63+
print(f"Running {module_name}'s submission...")
64+
# run_gcd_test(gcd_func, 54, 24, 6)
65+
# run_gcd_test(gcd_func, 48, 18, 6)
66+
# run_gcd_test(gcd_func, 101, 10, 1)
67+
# run_gcd_test(gcd_func, 270, 192, 6)
68+
# Edge case test cases
69+
run_gcd_test(gcd_func, 0, 0, None) # Both numbers are zero
70+
run_gcd_test(gcd_func, -54, 24, 6) # One negative number
71+
run_gcd_test(gcd_func, 54, -24, 6) # One negative number
72+
run_gcd_test(gcd_func, -54, -24, 6) # Both numbers are negative
73+
run_gcd_test(gcd_func, 0, 24, 24) # One number is zero
74+
run_gcd_test(gcd_func, 24, 0, 24) # One number is zero
75+
run_gcd_test(gcd_func, 17, 13, 1) # Both numbers are prime
76+
run_gcd_test(gcd_func, 1000000000, 2, 2) # Large number and small number
77+
run_gcd_test(gcd_func, 123456789, 987654321, 9) # Large numbers
78+
run_gcd_test(gcd_func, 1, 1, 1) # Both numbers are one
79+
print()
80+
else:
81+
print(f"ERROR: {module_name}'s submission does not have a gcd function\n")
82+
83+
84+
# This is the entry point of the script
85+
if __name__ == "__main__":
86+
load_and_run()

students_submissions/gcd_ahy22.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
def gcd(a: int, b: int) -> int:
2-
"""
3-
Calculate the greatest common divisor (GCD) of two integers a and b
4-
using the Euclidean algorithm.
5-
"""
6-
if(a==0 or b==0):
7-
print("One of the inputs cannot be zero")
8-
return None
9-
else:
10-
return gcd_helper(abs(max(a,b)), abs(min(a,b)))
11-
pass
12-
13-
def gcd_helper(big: int, small: int) -> int:
14-
quotient = big // small
15-
remainder = big % small
16-
if(remainder == 0):
17-
return small
18-
else:
19-
return gcd_helper(small, remainder)
20-
21-
# should be 2
22-
print(gcd(11284,874))
23-
24-
# should be error
25-
print(gcd(0,5))
26-
27-
# should be 10
28-
print(gcd(-250,10))
29-
30-
# should be 14
31-
print(gcd(42,56))
32-
33-
# should be 32
1+
def gcd(a: int, b: int) -> int:
2+
"""
3+
Calculate the greatest common divisor (GCD) of two integers a and b
4+
using the Euclidean algorithm.
5+
"""
6+
if(a==0 or b==0):
7+
print("One of the inputs cannot be zero")
8+
return None
9+
else:
10+
return gcd_helper(abs(max(a,b)), abs(min(a,b)))
11+
pass
12+
13+
def gcd_helper(big: int, small: int) -> int:
14+
quotient = big // small
15+
remainder = big % small
16+
if(remainder == 0):
17+
return small
18+
else:
19+
return gcd_helper(small, remainder)
20+
21+
# should be 2
22+
print(gcd(11284,874))
23+
24+
# should be error
25+
print(gcd(0,5))
26+
27+
# should be 10
28+
print(gcd(-250,10))
29+
30+
# should be 14
31+
print(gcd(42,56))
32+
33+
# should be 32
3434
print(gcd(7966496, 314080416))

0 commit comments

Comments
 (0)