Skip to content

Commit

Permalink
Merge pull request #1321 from maths/iss1243
Browse files Browse the repository at this point in the history
Issue #1243: reinstate nofunctions validator code.
  • Loading branch information
sangwinc authored Nov 26, 2024
2 parents dd74c5b + ffafdf4 commit c880410
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stack/maxima/contrib/validators.mac
Original file line number Diff line number Diff line change
Expand Up @@ -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! */
/* 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. */
/* 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 ""
Expand Down
8 changes: 8 additions & 0 deletions stack/maxima/contrib/validators_test.mac
Original file line number Diff line number Diff line change
Expand Up @@ -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+a_1), "Underscore characters are not permitted in this input.");

Expand Down

0 comments on commit c880410

Please sign in to comment.