Skip to content
Snippets Groups Projects
Unverified Commit c880410c authored by Chris Sangwin's avatar Chris Sangwin Committed by GitHub
Browse files

Merge pull request #1321 from maths/iss1243

Issue #1243: reinstate nofunctions validator code.
parents dd74c5bd ffafdf45
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,15 @@ validate_underscore(ex) := if is(sposition("_", string(ex)) = false) then "" ...@@ -31,6 +31,15 @@ validate_underscore(ex) := if is(sposition("_", string(ex)) = false) then ""
/* Add in unit-test cases using STACK's s_test_case function. At least two please! */ /* Add in unit-test cases using STACK's s_test_case function. At least two please! */
/* Place test cases in validators_test.mac */ /* Place test cases in validators_test.mac */
/* The student may not use a user-defined function, or arrays, anywhere in their input. */
validate_nofunctions(ex):= block([op1,opp],
if atom(ex) then return(""),
op1:ev(op(ex)),
opp:apply(properties, [op1]),
if ev(emptyp(opp) or is(opp=[noun]),simp) then return(sconcat("User-defined functions are not permitted in this input. In your answer ", stack_disp(op1, "i"), " appears to be used as a function. ")),
apply(sconcat, map(validate_nofunctions, args(ex)))
);
/* The student may only use single-character variable names in their answer. */ /* The student may only use single-character variable names in their answer. */
/* This is intended for use when Insert Stars is turned off, but we still want to indicate to students that they may have forgotten a star */ /* This is intended for use when Insert Stars is turned off, but we still want to indicate to students that they may have forgotten a star */
validate_all_one_letter_variables(ex) := if not(is(ev(lmax(map(lambda([ex2],slength(string(ex2))),listofvars(ex))),simp)>1)) then "" validate_all_one_letter_variables(ex) := if not(is(ev(lmax(map(lambda([ex2],slength(string(ex2))),listofvars(ex))),simp)>1)) then ""
......
...@@ -23,6 +23,14 @@ ...@@ -23,6 +23,14 @@
/* */ /* */
/****************************************************************/ /****************************************************************/
s_test_case(validate_nofunctions(1+a1), "");
s_test_case(validate_nofunctions(sin(n*x)), "");
s_test_case(validate_nofunctions(-b#pm#sqrt(b^2-4*a*c)), "");
s_test_case(validate_nofunctions(x(2)), "User-defined functions are not permitted in this input. In your answer \\(x\\) appears to be used as a function. ");
s_test_case(validate_nofunctions(3*x(t)^2), "User-defined functions are not permitted in this input. In your answer \\(x\\) appears to be used as a function. ");
s_test_case(validate_nofunctions(1+f(x+1)), "User-defined functions are not permitted in this input. In your answer \\(f\\) appears to be used as a function. ");
s_test_case(validate_nofunctions(x(2)*y(3)), "User-defined functions are not permitted in this input. In your answer \\(x\\) appears to be used as a function. User-defined functions are not permitted in this input. In your answer \\(y\\) appears to be used as a function. ");
s_test_case(validate_underscore(1+a1), ""); s_test_case(validate_underscore(1+a1), "");
s_test_case(validate_underscore(1+a_1), "Underscore characters are not permitted in this input."); s_test_case(validate_underscore(1+a_1), "Underscore characters are not permitted in this input.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment