From: dpvc v. a. <we...@ma...> - 2007-09-08 23:00:45
|
Log Message: ----------- Report error messages correctly when ijk notation is involved and ijkAnyDimension is set. Modified Files: -------------- pg/lib/Value: AnswerChecker.pm Revision Data ------------- Index: AnswerChecker.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/AnswerChecker.pm,v retrieving revision 1.112 retrieving revision 1.113 diff -Llib/Value/AnswerChecker.pm -Llib/Value/AnswerChecker.pm -u -r1.112 -r1.113 --- lib/Value/AnswerChecker.pm +++ lib/Value/AnswerChecker.pm @@ -865,8 +865,11 @@ return unless $ans->{score} == 0 && !$ans->{isPreview}; my $student = $ans->{student_value}; return if $ans->{ignoreStrings} && (!Value::isValue($student) || $student->type eq 'String'); - if ($ans->{showDimensionHints} && $self->length != $student->length) { - $self->cmp_Error($ans,"The number of coordinates is incorrect"); return; + if ($self->length != $student->length) { + ($self,$student) = $self->cmp_pad($student); + if ($ans->{showDimensionHints} && $self->length != $student->length) { + $self->cmp_Error($ans,"The number of coordinates is incorrect"); return; + } } if ($ans->{parallel} && !$student->isFormula && !$student->classMatch('String') && $self->isParallel($student,$ans->{sameDirection})) { @@ -882,6 +885,23 @@ } } +# +# Pad the student or correct answer if either is in ijk notation +# and they are not the same dimension. Only add zeros when the other one +# also has zeros in those places. +# +sub cmp_pad { + my $self = shift; my $student = shift; + if (($self->getFlag("ijk") || $student->getFlag("ijk")) && $self->getFlag("ijkAnyDimension")) { + $self = $self->copy; $student = $student->copy; + while ($self->length > $student->length && $self->{data}[$student->length] == 0) + {push(@{$student->{data}},Value::Real->new(0))} + while ($self->length < $student->length && $student->{data}[$self->length] == 0) + {push(@{$self->{data}},Value::Real->new(0))} + } + return ($self,$student); +} + sub correct_ans { my $self = shift; return $self->SUPER::correct_ans unless $self->{ans_name}; |