Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
fix(mygrader): Resolve Math Domain Error and Refine Exception Handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
AppleBoiy committed Aug 26, 2023
1 parent b1c62a1 commit 0a948c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
10 changes: 0 additions & 10 deletions mygrader/mygrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,10 @@ def run_test_case():
else:
raise ValueError(f"Invalid option: {self.log_option}")

except (ValueError, FileNotFoundError) as e:
print(f"Error: {e}")
if self.debug:
print(f"Error at line {e.__traceback__.tb_lineno}")

except AttributeError:
info = sys.exc_info()
raise AttributeError(f"Invalid function name: {user_func.__name__}") from info[1]

except Exception as e:
if self.debug:
print(f"Error at line {e.__traceback__.tb_lineno}: ", e)
print("An error occurred while running the test.")

@classmethod
def __return_type__(cls, func: Callable) -> str:
"""
Expand Down
14 changes: 10 additions & 4 deletions mygrader/src/y2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ def calculate_triangle_area_test_cases(cls, num_test_cases: int) -> List:
num_test_cases (int): Number of test cases to generate.
"""
test_cases = []
for _ in range(num_test_cases):
a = random.uniform(0.0, 1000.0)
b = random.uniform(0.0, 1000.0)
c = random.uniform(0.0, 1000.0)
while len(test_cases) < num_test_cases:
a = random.uniform(1.0, 100.0)
b = random.uniform(1.0, 100.0)

# Ensure that the sum of a and b is greater than c
c_min = abs(a - b) + 0.0001 # Add a small epsilon to avoid floating point precision issues
c_max = a + b - 0.0001 # Subtract a small epsilon to avoid floating point precision issues

c = random.uniform(c_min, c_max)
test_cases.append((a, b, c))

return test_cases

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='mygrader',
version='0.3.4-alpha',
version='0.4-alpha1',
packages=find_packages(),

# Add any required dependencies here
Expand Down

0 comments on commit 0a948c0

Please sign in to comment.