Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,30 @@ def test_mu_preview_evaluate(self):
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True

@pytest.mark.parametrize(
"response, is_latex, is_correct", [
("A/s(e**(-a*s)-e**(-b*s))", False, True),
("A/s(e**(-as)-e**(-bs))", False, True),
("(A/s)( e^{-a*s}-e^{-b*s})", True, True),
("(A/s)( e^{-as}-e^{-bs})", True, True),
(r"\frac{A}{s} (e^{-a*s}-e^{-b*s})", True, True),
(r"\frac{A}{s} (e^{-a s}-e^{-b s})", True, True)
]
)
def test_laplace_transforms(self, response, is_latex, is_correct):

params = {
"is_latex": is_latex,
"strict_syntax": False,
"elementary_functions": True,
"convention": "implicit_higher_precedence",
}
answer = "A/s(e**(-a*s)-e**(-b*s))"

result = evaluation_function(response, answer, params)
assert result["is_correct"] == is_correct



if __name__ == "__main__":
pytest.main(['-xk not slow', '--tb=short', '--durations=10', os.path.abspath(__file__)])
21 changes: 21 additions & 0 deletions app/preview_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,27 @@ def test_multi_character_implicit_multi_variable(self):
assert result["preview"]["latex"] =='\\frac{a}{bc \\cdot d}'
assert result["preview"]["sympy"] == "a/bcd"

@pytest.mark.parametrize(
"response, is_latex, latex, sympy", [
("A/s(e**(-a*s)-e**(-b*s))", False, r"\frac{A \cdot \left(e^{- a \cdot s} - e^{- b \cdot s}\right)}{s}", "A/s( E**(-a*s)- E**(-b*s))"),
("A/s(e**(-as)-e**(-bs))", False, r"\frac{A \cdot \left(e^{- a \cdot s} - e^{- b \cdot s}\right)}{s}", "A/s( E**(-a*s)- E**(-bs))"),
("(A/s)( e^{-a*s}-e^{-b*s})", True, r"(A/s)( e^{-a*s}-e^{-b*s})", "A*(-exp(-b*s) + exp(-a*s))/s"),
("(A/s)( e^{-as}-e^{-bs})", True, r"(A/s)( e^{-as}-e^{-bs})", "A*(-exp(-b*s) + exp(-a*s))/s"),
]
)
def test_laplace_transforms(self, response, is_latex, latex, sympy):
params = {
"is_latex": is_latex,
"strict_syntax": False,
"elementary_functions": True,
"convention": "implicit_higher_precedence",
}

result = preview_function(response, params)
assert result["preview"]["latex"] == latex
assert result["preview"]["sympy"] == sympy



if __name__ == "__main__":
pytest.main(['-xk not slow', "--tb=line", os.path.abspath(__file__)])
4 changes: 4 additions & 0 deletions app/utility/expression_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ def substitute_input_symbols(exprs, params):
# we need to make sure it is not substituted back in
substitutions = [(original, subs.replace("lambda", "lamda")) for (original, subs) in substitutions]

# Since 'as' is a reserved keyword in python, we add a subsitution of 'as' to 'a*s' if 'as' is not a defined symbol
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If more reserved words emerge:

  • Could we anticipate them? Can we find a list of Python reserved words?
  • Would it make sense to group the treatment rather than adding them one at a time?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add this to the backlog to refactor

if 'as' not in input_symbols.keys():
substitutions += [('as', 'a*s')]

substitutions = list(set(substitutions))
if len(substitutions) > 0:
substitutions.sort(key=substitutions_sort_key)
Expand Down