WeBWorK Problems

Type checking in custom answer checker

Re: Type checking in custom answer checker

by Davide Cervone -
Number of replies: 0
For a String object, if the other answers could be something other than a number, you have to tell MathObjects what type that is so that if produces the correct error messages. The usual way to do that is to add a typeMatch option to the cmp() call, as in
But with the MultiAnswer object, you don't make the individual cmp() calls yourself, so you can't add that option.

In your case, you could handle it by overriding the default typeMatch option for the String comparisons by adding

Context()->{cmpDefaults}{String} = {typeMatch=>Formula("x")};
to your Context setup code. This will make all string comparisons be done with messages appropriate for formulas rather than numbers.

If you have more than one string answer and need a different type for each, then you would have to be more sophisticated about it. I don't want to complicate this answer by writing that out as well unless you really need it. If so, let me know and I'll write that up, too.