I want to write a custom answer checker that will accept either of two possible answers, each of which is a number with units. I tried this:
$ans1 = NumberWithUnits($r1, "in/day");
$ans2 = NumberWithUnits($r2, "in/day");
ANS($ans1->cmp(checker => sub {
my ($correct,$student,$ansHash) = @_;
my $v = $student->value;
return (($ans1 == $v || $ans2 == $v) ? 1 : 0);
}));
but it doesn't work: when I enter one of the correct answers (with units) I get "You must provide units for your number". I guess that maybe the "==" comparison operator is not taking account of units correctly? How can I do this?