Skip to content

Commit

Permalink
for between_comparer, ensure input is real
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherChudzicki committed Aug 10, 2018
1 parent 027360a commit 4d2eeae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions mitxgraders/comparers/comparers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"""
from numbers import Number
import numpy as np
from mitxgraders.exceptions import InputTypeError

def equality_comparer(comparer_params_evals, student_eval, utils):
"""
Expand Down Expand Up @@ -80,9 +81,18 @@ def between_comparer(comparer_params_evals, student_eval, utils):
False
>>> grader(None, '5e7')['ok']
True
Input must be real:
>>> grader(None, '5e8+2e6*i')['ok']
Traceback (most recent call last):
InputTypeError: Input must be real.
"""
start, stop = comparer_params_evals

if not np.isreal(student_eval):
raise InputTypeError("Input must be real.")

return start <= student_eval <= stop

def congruence_comparer(comparer_params_evals, student_eval, utils):
Expand Down
6 changes: 6 additions & 0 deletions mitxgraders/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class InvalidInput(StudentFacingError):
"""
pass

class InputTypeError(InvalidInput):
"""
Indicates that student's input has evaluated to an object of the wrong
type (or shape).
"""

class MissingInput(StudentFacingError):
"""
Raised when a required input has been left blank.
Expand Down
7 changes: 1 addition & 6 deletions mitxgraders/formulagrader/matrixgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from numbers import Number
from collections import namedtuple
from voluptuous import Required, Any
from mitxgraders.exceptions import InputTypeError
from mitxgraders.formulagrader.formulagrader import FormulaGrader
from mitxgraders.helpers.validatorfuncs import NonNegative
from mitxgraders.helpers.calc import MathArray, within_tolerance, identity
Expand All @@ -14,12 +15,6 @@
from mitxgraders.helpers.calc.mathfuncs import (
merge_dicts, ARRAY_ONLY_FUNCTIONS)

class InputTypeError(CalcError):
"""
Indicates that student's input has evaluated to an object of the wrong
type (or shape).
"""

class MatrixGrader(FormulaGrader):
"""
An extension of FormulaGrader with better support for grading expressions
Expand Down

0 comments on commit 4d2eeae

Please sign in to comment.