From: Mike G. v. a. <we...@ma...> - 2005-11-12 00:15:14
|
Log Message: ----------- Changes to code checking whether the previous answer is equivalent to the current answer. In this module additional code was answer to check for errors in the overloaded == in case the two Values can't be compared. In PGanswermacros.pl the filter which handles "parse_previous_answer" was modified to make sure the context is the same in the previous answer and the current answer. Modified Files: -------------- pg/lib/Value: AnswerChecker.pm pg/macros: PGanswermacros.pl Revision Data ------------- Index: AnswerChecker.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/AnswerChecker.pm,v retrieving revision 1.71 retrieving revision 1.72 diff -Llib/Value/AnswerChecker.pm -Llib/Value/AnswerChecker.pm -u -r1.71 -r1.72 --- lib/Value/AnswerChecker.pm +++ lib/Value/AnswerChecker.pm @@ -204,14 +204,19 @@ sub cmp_compare { my $self = shift; my $other = shift; my $ans = shift; my $nth = shift || ''; - return eval {$self == $other} unless ref($ans->{checker}) eq 'CODE'; - my $equal = eval {&{$ans->{checker}}($self,$other,$ans,$nth,@_)}; - if (!defined($equal) && $@ ne '' && (!$$Value::context->{error}{flag} || $ans->{showAllErrors})) { - $$Value::context->setError(["<I>An error occurred while checking your$nth answer:</I>\n". - '<DIV STYLE="margin-left:1em">%s</DIV>',$@],'',undef,undef,$CMP_ERROR); - warn "Please inform your instructor that an error occurred while checking your answer"; + my $equal = undef; + unless ( ref($ans->{checker}) eq 'CODE' ) { + $equal = eval {$self == $other} ; + } else { + $equal = eval {&{$ans->{checker}}($self,$other,$ans,$nth,@_)}; + } + if (!defined($equal) && $@ ne '' && ($$Value::context->{error}{flag} || $ans->{showAllErrors})) { + $$Value::context->setError(["<I>An error occurred while checking your$nth answer:</I>\n". + '<DIV STYLE="margin-left:1em">%s</DIV>',$@],'',undef,undef,$CMP_ERROR); + warn "Please inform your instructor that an error occurred while checking your answer"; } return $equal; + } sub cmp_list_compare {Value::List::cmp_list_compare(@_)} Index: PGanswermacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGanswermacros.pl,v retrieving revision 1.41 retrieving revision 1.42 diff -Lmacros/PGanswermacros.pl -Lmacros/PGanswermacros.pl -u -r1.41 -r1.42 --- macros/PGanswermacros.pl +++ macros/PGanswermacros.pl @@ -2006,7 +2006,9 @@ my $rh_ans = shift; $rh_ans->{_filter_name} = "parse_previous_answer"; return $rh_ans unless defined $rh_ans->{prev_ans}; + my $oldContext = &$Context(); &$Context($context); $rh_ans->{prev_formula} = Parser::Formula($rh_ans->{prev_ans}); + &$Context($oldContext); $rh_ans; } ); @@ -2034,7 +2036,9 @@ my $rh_ans = shift; $rh_ans->{_filter_name} = "produce_equivalence_message"; return $rh_ans unless $rh_ans->{prev_equals_current} && $rh_ans->{score} == 0; - return $rh_ans if $rh_ans->{prev_ans} eq $rh_ans->{original_student_ans}; + # the match is exact don't give an error since the previous entry + # might have been from the preview button + return $rh_ans if $rh_ans->{prev_ans} eq $rh_ans->{original_student_ans}; $rh_ans->{ans_message} = "This answer is equivalent to the one you just submitted or previewed."; $rh_ans; } |