@@ -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. ")),
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.");