def test_debug_message_complex_integrand(): grader = IntegralGrader(complex_integrand=True, answers={ 'lower': '-2', 'upper': '4', 'integrand': 'cos(s) + i*sin(s)', 'integration_variable': 's' }, debug=True, samples=2) student_input = ['-1', '5', 'sqrt(x)', 'x'] expected_message = ( "<pre>MITx Grading Library Version {version}<br/>\n" "Student Responses:<br/>\n" "-1<br/>\n" "5<br/>\n" "sqrt(x)<br/>\n" "x<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 0<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 1.8831785881043805,<br/>\n" " {u}'x': 0.022981166359782736}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 7.453559925<br/>\n" "Error Estimate: 8.27511384416e-15<br/>\n" "Number of integrand evaluations: 357<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: 0.666666666667<br/>\n" "Error Estimate: 7.40148683083e-16<br/>\n" "Number of integrand evaluations: 357<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.152494931518<br/>\n" "Error Estimate: 4.2752835891e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: 0.237496784316<br/>\n" "Error Estimate: 4.1882074502e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "</pre>").format(version=__version__, u=UNICODE_PREFIX) expected_message = round_decimals_in_string(expected_message) result = grader(None, student_input) assert result['ok'] is False assert result['grade_decimal'] == 0.0 assert expected_message == round_decimals_in_string(result['msg'])
def test_debug_message(): grader = IntegralGrader(answers={ 'lower': '1', 'upper': '8', 'integrand': 'sin(s)', 'integration_variable': 's' }, debug=True, samples=2) student_input = ['1', '8', 'sin(x)', 'x'] expected_message = ( "<pre>MITx Grading Library Version {version}<br/>\n" "Student Responses:<br/>\n" "1<br/>\n" "8<br/>\n" "sin(x)<br/>\n" "x<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 0<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 5.530375019455111,<br/>\n" " {u}'x': 5.530375019455111}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 1<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 5.530375019455111,<br/>\n" " {u}'x': 5.530375019455111}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "</pre>").format(version=__version__, u=UNICODE_PREFIX) expected_message = round_decimals_in_string(expected_message) result = grader(None, student_input) assert result['ok'] is True assert result['grade_decimal'] == 1.0 assert expected_message == round_decimals_in_string(result['msg'])
def test_debug_message(): grader = IntegralGrader(answers={ 'lower': '1', 'upper': '8', 'integrand': 'sin(s)', 'integration_variable': 's' }, debug=True, samples=2) student_input = ['1', '8', 'sin(x)', 'x'] expected_message = ( "<pre>MITx Grading Library Version {version}<br/>\n" "Running on edX using python {python_version}<br/>\n" "Student Responses:<br/>\n" "1<br/>\n" "8<br/>\n" "sin(x)<br/>\n" "x<br/>\n" "<br/>\n" "==============================================================<br/>\n" "IntegralGrader Debug Info<br/>\n" "==============================================================<br/>\n" "Functions available during evaluation and allowed in answer:<br/>\n" "{{{u}'abs': <function absolute at 0x...>,<br/>\n" " {u}'arccos': <function arccos at 0x...>,<br/>\n" " {u}'arccosh': <function arccosh at 0x...>,<br/>\n" " {u}'arccot': <function arccot at 0x...>,<br/>\n" " {u}'arccoth': <function arccoth at 0x...>,<br/>\n" " {u}'arccsc': <function arccsc at 0x...>,<br/>\n" " {u}'arccsch': <function arccsch at 0x...>,<br/>\n" " {u}'arcsec': <function arcsec at 0x...>,<br/>\n" " {u}'arcsech': <function arcsech at 0x...>,<br/>\n" " {u}'arcsin': <function arcsin at 0x...>,<br/>\n" " {u}'arcsinh': <function arcsinh at 0x...>,<br/>\n" " {u}'arctan': <function arctan at 0x...>,<br/>\n" " {u}'arctan2': <function arctan2 at 0x...>,<br/>\n" " {u}'arctanh': <function arctanh at 0x...>,<br/>\n" " {u}'ceil': <function ceil at 0x...>,<br/>\n" " {u}'conj': <ufunc 'conjugate'>,<br/>\n" " {u}'cos': <function cos at 0x...>,<br/>\n" " {u}'cosh': <function cosh at 0x...>,<br/>\n" " {u}'cot': <function cot at 0x...>,<br/>\n" " {u}'coth': <function coth at 0x...>,<br/>\n" " {u}'csc': <function csc at 0x...>,<br/>\n" " {u}'csch': <function csch at 0x...>,<br/>\n" " {u}'exp': <function exp at 0x...>,<br/>\n" " {u}'fact': <function factorial at 0x...>,<br/>\n" " {u}'factorial': <function factorial at 0x...>,<br/>\n" " {u}'floor': <function floor at 0x...>,<br/>\n" " {u}'im': <function imag at 0x...>,<br/>\n" " {u}'kronecker': <function kronecker at 0x...>,<br/>\n" " {u}'ln': <function log at 0x...>,<br/>\n" " {u}'log10': <function log10 at 0x...>,<br/>\n" " {u}'log2': <function log2 at 0x...>,<br/>\n" " {u}'max': <function max at 0x...>,<br/>\n" " {u}'min': <function min at 0x...>,<br/>\n" " {u}'re': <function real at 0x...>,<br/>\n" " {u}'sec': <function sec at 0x...>,<br/>\n" " {u}'sech': <function sech at 0x...>,<br/>\n" " {u}'sin': <function sin at 0x...>,<br/>\n" " {u}'sinh': <function sinh at 0x...>,<br/>\n" " {u}'sqrt': <function sqrt at 0x...>,<br/>\n" " {u}'tan': <function tan at 0x...>,<br/>\n" " {u}'tanh': <function tanh at 0x...>}}<br/>\n" "Functions available during evaluation and disallowed in answer:<br/>\n" "{{}}<br/>\n" "<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 1 of 2<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 5.530375019455111,<br/>\n" " {u}'x': 5.530375019455111}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 2 of 2<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 5.530375019455111,<br/>\n" " {u}'x': 5.530375019455111}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.685802339677<br/>\n" "Error Estimate: 5.23517337969e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: None<br/>\n" "Error Estimate: None<br/>\n" "Number of integrand evaluations: None<br/>\n" "<br/>\n" "<br/>\n" "==========================================<br/>\n" "Comparison Data for All 2 Samples<br/>\n" "==========================================<br/>\n" "Comparer Function: EqualityComparer({{{u}'transform': <function identity_transform at 0x...>}})<br/>\n" "Comparison Results:<br/>\n" "[{{{u}'grade_decimal': 1.0, {u}'msg': {u}'', {u}'ok': True}},<br/>\n" " {{{u}'grade_decimal': 1.0, {u}'msg': {u}'', {u}'ok': True}}]<br/>\n" "</pre>").format(version=__version__, python_version=platform.python_version(), u=UNICODE_PREFIX) expected_message = expected_message.replace("<func", "<func").replace( "...>", "...>") expected_message = round_decimals_in_string(expected_message) result = grader(None, student_input) assert result['ok'] is True assert result['grade_decimal'] == 1.0 assert expected_message == round_decimals_in_string(result['msg'])
def test_debug_message_complex_integrand(): grader = IntegralGrader(complex_integrand=True, answers={ 'lower': '-2', 'upper': '4', 'integrand': 'cos(s) + i*sin(s)', 'integration_variable': 's' }, debug=True) student_input = ['-1', '5', 'sqrt(x)', 'x'] expected_message = ( "<pre>MITx Grading Library Version {version}<br/>\n" "Running on edX using python {python_version}<br/>\n" "Student Responses:<br/>\n" "-1<br/>\n" "5<br/>\n" "sqrt(x)<br/>\n" "x<br/>\n" "<br/>\n" "==============================================================<br/>\n" "IntegralGrader Debug Info<br/>\n" "==============================================================<br/>\n" "Functions available during evaluation and allowed in answer:<br/>\n" "{{{u}'abs': <function absolute at 0x...>,<br/>\n" " {u}'arccos': <function arccos at 0x...>,<br/>\n" " {u}'arccosh': <function arccosh at 0x...>,<br/>\n" " {u}'arccot': <function arccot at 0x...>,<br/>\n" " {u}'arccoth': <function arccoth at 0x...>,<br/>\n" " {u}'arccsc': <function arccsc at 0x...>,<br/>\n" " {u}'arccsch': <function arccsch at 0x...>,<br/>\n" " {u}'arcsec': <function arcsec at 0x...>,<br/>\n" " {u}'arcsech': <function arcsech at 0x...>,<br/>\n" " {u}'arcsin': <function arcsin at 0x...>,<br/>\n" " {u}'arcsinh': <function arcsinh at 0x...>,<br/>\n" " {u}'arctan': <function arctan at 0x...>,<br/>\n" " {u}'arctan2': <function arctan2 at 0x...>,<br/>\n" " {u}'arctanh': <function arctanh at 0x...>,<br/>\n" " {u}'ceil': <function ceil at 0x...>,<br/>\n" " {u}'conj': <ufunc 'conjugate'>,<br/>\n" " {u}'cos': <function cos at 0x...>,<br/>\n" " {u}'cosh': <function cosh at 0x...>,<br/>\n" " {u}'cot': <function cot at 0x...>,<br/>\n" " {u}'coth': <function coth at 0x...>,<br/>\n" " {u}'csc': <function csc at 0x...>,<br/>\n" " {u}'csch': <function csch at 0x...>,<br/>\n" " {u}'exp': <function exp at 0x...>,<br/>\n" " {u}'fact': <function factorial at 0x...>,<br/>\n" " {u}'factorial': <function factorial at 0x...>,<br/>\n" " {u}'floor': <function floor at 0x...>,<br/>\n" " {u}'im': <function imag at 0x...>,<br/>\n" " {u}'kronecker': <function kronecker at 0x...>,<br/>\n" " {u}'ln': <function log at 0x...>,<br/>\n" " {u}'log10': <function log10 at 0x...>,<br/>\n" " {u}'log2': <function log2 at 0x...>,<br/>\n" " {u}'max': <function max at 0x...>,<br/>\n" " {u}'min': <function min at 0x...>,<br/>\n" " {u}'re': <function real at 0x...>,<br/>\n" " {u}'sec': <function sec at 0x...>,<br/>\n" " {u}'sech': <function sech at 0x...>,<br/>\n" " {u}'sin': <function sin at 0x...>,<br/>\n" " {u}'sinh': <function sinh at 0x...>,<br/>\n" " {u}'sqrt': <function sqrt at 0x...>,<br/>\n" " {u}'tan': <function tan at 0x...>,<br/>\n" " {u}'tanh': <function tanh at 0x...>}}<br/>\n" "Functions available during evaluation and disallowed in answer:<br/>\n" "{{}}<br/>\n" "<br/>\n" "<br/>\n" "==============================================<br/>\n" "Integration Data for Sample Number 1 of 1<br/>\n" "==============================================<br/>\n" "Variables: {{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'infty': inf,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'s': 1.8831785881043805,<br/>\n" " {u}'x': 0.022981166359782736}}<br/>\n" "<br/>\n" "========== Student Integration Data, Real Part<br/>\n" "Numerical Value: 7.453559925<br/>\n" "Error Estimate: 8.27511384416e-15<br/>\n" "Number of integrand evaluations: 357<br/>\n" "========== Student Integration Data, Imaginary Part<br/>\n" "Numerical Value: 0.666666666667<br/>\n" "Error Estimate: 7.40148683083e-16<br/>\n" "Number of integrand evaluations: 357<br/>\n" "<br/>\n" "========== Author Integration Data, Real Part<br/>\n" "Numerical Value: 0.152494931518<br/>\n" "Error Estimate: 4.2752835891e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "========== Author Integration Data, Imaginary Part<br/>\n" "Numerical Value: 0.237496784316<br/>\n" "Error Estimate: 4.1882074502e-14<br/>\n" "Number of integrand evaluations: 21<br/>\n" "<br/>\n" "<br/>\n" "==========================================<br/>\n" "Comparison Data for All 1 Samples<br/>\n" "==========================================<br/>\n" "Comparer Function: EqualityComparer({{{u}'transform': <function identity_transform at 0x...>}})<br/>\n" "Comparison Results:<br/>\n" "[{{{u}'grade_decimal': 0, {u}'msg': {u}'', {u}'ok': False}}]<br/>\n" "</pre>").format(version=__version__, python_version=platform.python_version(), u=UNICODE_PREFIX) expected_message = expected_message.replace("<func", "<func").replace( "...>", "...>") expected_message = round_decimals_in_string(expected_message) result = grader(None, student_input) assert result['ok'] is False assert result['grade_decimal'] == 0.0 assert expected_message == round_decimals_in_string(result['msg'])
def test_fg_debug_log(): set_seed(0) grader = FormulaGrader(answers='x^2 + f(y) + z', variables=['x', 'y', 'z'], sample_from={'z': ComplexRectangle()}, blacklist=['sin', 'cos', 'tan'], user_functions={ 'f': RandomFunction(), 'square': lambda x: x**2 }, samples=2, debug=True) result = grader(None, 'z + x*x + f(y)') message = ( "<pre>MITx Grading Library Version {version}<br/>\n" "Student Response:<br/>\n" "z + x*x + f(y)<br/>\n" "<br/>\n" "==============================================================<br/>\n" "FormulaGrader Debug Info<br/>\n" "==============================================================<br/>\n" "Functions available during evaluation and allowed in answer:<br/>\n" "{{{u}'abs': <function absolute at 0x...>,<br/>\n" " {u}'arccos': <function arccos at 0x...>,<br/>\n" " {u}'arccosh': <function arccosh at 0x...>,<br/>\n" " {u}'arccot': <function arccot at 0x...>,<br/>\n" " {u}'arccoth': <function arccoth at 0x...>,<br/>\n" " {u}'arccsc': <function arccsc at 0x...>,<br/>\n" " {u}'arccsch': <function arccsch at 0x...>,<br/>\n" " {u}'arcsec': <function arcsec at 0x...>,<br/>\n" " {u}'arcsech': <function arcsech at 0x...>,<br/>\n" " {u}'arcsin': <function arcsin at 0x...>,<br/>\n" " {u}'arcsinh': <function arcsinh at 0x...>,<br/>\n" " {u}'arctan': <function arctan at 0x...>,<br/>\n" " {u}'arctan2': <function arctan2 at 0x...>,<br/>\n" " {u}'arctanh': <function arctanh at 0x...>,<br/>\n" " {u}'ceil': <function ceil at 0x...>,<br/>\n" " {u}'conj': <ufunc 'conjugate'>,<br/>\n" " {u}'cosh': <function cosh at 0x...>,<br/>\n" " {u}'cot': <function cot at 0x...>,<br/>\n" " {u}'coth': <function coth at 0x...>,<br/>\n" " {u}'csc': <function csc at 0x...>,<br/>\n" " {u}'csch': <function csch at 0x...>,<br/>\n" " {u}'exp': <function exp at 0x...>,<br/>\n" " {u}'f': <function random_function at 0x...>,<br/>\n" " {u}'fact': <function factorial at 0x...>,<br/>\n" " {u}'factorial': <function factorial at 0x...>,<br/>\n" " {u}'floor': <function floor at 0x...>,<br/>\n" " {u}'im': <function imag at 0x...>,<br/>\n" " {u}'kronecker': <function kronecker at 0x...>,<br/>\n" " {u}'ln': <function log at 0x...>,<br/>\n" " {u}'log10': <function log10 at 0x...>,<br/>\n" " {u}'log2': <function log2 at 0x...>,<br/>\n" " {u}'max': <function max at 0x...>,<br/>\n" " {u}'min': <function min at 0x...>,<br/>\n" " {u}'re': <function real at 0x...>,<br/>\n" " {u}'sec': <function sec at 0x...>,<br/>\n" " {u}'sech': <function sech at 0x...>,<br/>\n" " {u}'sinh': <function sinh at 0x...>,<br/>\n" " {u}'sqrt': <function sqrt at 0x...>,<br/>\n" " {u}'square': <function <lambda> at 0x...>,<br/>\n" " {u}'tanh': <function tanh at 0x...>}}<br/>\n" "Functions available during evaluation and disallowed in answer:<br/>\n" "{{{u}'cos': <function cos at 0x...>,<br/>\n" " {u}'sin': <function sin at 0x...>,<br/>\n" " {u}'tan': <function tan at 0x...>}}<br/>\n" "<br/>\n" "<br/>\n" "==========================================<br/>\n" "Evaluation Data for Sample Number 1 of 2<br/>\n" "==========================================<br/>\n" "Variables:<br/>\n" "{{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'x': 3.195254015709299,<br/>\n" " {u}'y': 3.860757465489678,<br/>\n" " {u}'z': (2.205526752143288+2.0897663659937935j)}}<br/>\n" "Student Eval: (14.7111745179+2.08976636599j)<br/>\n" "Compare to: [(14.711174517877566+2.0897663659937935j)]<br/>\n" "<br/>\n" "<br/>\n" "==========================================<br/>\n" "Evaluation Data for Sample Number 2 of 2<br/>\n" "==========================================<br/>\n" "Variables:<br/>\n" "{{{u}'e': 2.718281828459045,<br/>\n" " {u}'i': 1j,<br/>\n" " {u}'j': 1j,<br/>\n" " {u}'pi': 3.141592653589793,<br/>\n" " {u}'x': 2.694619197355619,<br/>\n" " {u}'y': 3.5835764522666245,<br/>\n" " {u}'z': (1.875174422525385+2.7835460015641598j)}}<br/>\n" "Student Eval: (11.9397106851+2.78354600156j)<br/>\n" "Compare to: [(11.93971068506166+2.7835460015641598j)]<br/>\n" "<br/>\n" "<br/>\n" "==========================================<br/>\n" "Comparison Data for All 2 Samples<br/>\n" "==========================================<br/>\n" "Comparer Function: EqualityComparer({{{u}'transform': <function identity_transform at 0x...>}})<br/>\n" "Comparison Results:<br/>\n" "[{{{u}'grade_decimal': 1.0, {u}'msg': {u}'', {u}'ok': True}},<br/>\n" " {{{u}'grade_decimal': 1.0, {u}'msg': {u}'', {u}'ok': True}}]<br/>\n" "</pre>").format(version=VERSION, u=UNICODE_PREFIX) expected = round_decimals_in_string(message) result_msg = round_decimals_in_string(result['msg']).replace( 'test_fg_debug_log.<locals>.', '') assert expected == result_msg