WeBWorK Problems

Custom checker error message displays in Numeric context but not Matrix context

Custom checker error message displays in Numeric context but not Matrix context

by Jeremy Sylvestre -
Number of replies: 0
Below are two very simple PG problems based on the example code provided from the CustomAnswerCheckers page in the wiki.

With the first problem, the error message "Try again" is correctly displayed if you submit an answer of 0.

With the second problem, the error message is not displayed if you submit the zero matrix as an answer.

Can anyone tell me what is missing from the second problem to get this to work? I'm using ww_version 2.9, pg_version 2.9.

Thanks!

#########################
## Problem 1

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);
TEXT(beginproblem());

Context("Numeric");

$ans = Compute("1");

Context()->texStrings;
BEGIN_TEXT
Enter the identity in \(\mathbb{R}^\times\):
\(e = \) \{ $ans->ans_rule \}
END_TEXT
Context()->normalStrings;

$showPartialCorrectAnswers = 1;

sub mycheck {
my ($correct, $student, $ansHash) = @_;
Value->Error("Try again") if $student->isZero;
return $student->isOne;
}

ANS( $ans->cmp( checker=>~~&mycheck ) );

ENDDOCUMENT();

###################################################

#########################
## Problem 2

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);
TEXT(beginproblem());

Context("Matrix");

@A = ([1,0],[0,1]);
$ans = Matrix(@A);

Context()->texStrings;
BEGIN_TEXT
Enter the identity in \(\operatorname{GL}_2(\mathbb{R})\):
\(e = \) \{ $ans->ans_array \}
END_TEXT
Context()->normalStrings;

$showPartialCorrectAnswers = 1;

sub mycheck {
my ($correct, $student, $ansHash) = @_;
Value->Error("Try again") if $student->isZero;
return $student->isOne;
}

ANS( $ans->cmp( checker=>~~&mycheck ) );

ENDDOCUMENT();