From: dpvc v. a. <we...@ma...> - 2005-08-12 17:08:00
|
Log Message: ----------- Changed how Intervals implement the requireParenMatch flag for the interval and union answer checker. (Use a Context flag rather than a flag on the interval itself.) Moved the getFlag method from Formula.pm to Value.pm so it can be used by any object class. New feature where classes can add more context flags to set (and reset after the answer checker runs). Modified Files: -------------- pg/lib/Value: AnswerChecker.pm Formula.pm Interval.pm Revision Data ------------- Index: AnswerChecker.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/AnswerChecker.pm,v retrieving revision 1.51 retrieving revision 1.52 diff -Llib/Value/AnswerChecker.pm -Llib/Value/AnswerChecker.pm -u -r1.51 -r1.52 --- lib/Value/AnswerChecker.pm +++ lib/Value/AnswerChecker.pm @@ -62,6 +62,8 @@ showExtraParens => 1, # make student answer painfully unambiguous reduceConstants => 0, # don't combine student constants reduceConstantFunctions => 0, # don't reduce constant functions + ($ans->{requireParenMatch}? (): ignoreEndpointTypes => 1), # for Intervals + $self->cmp_contextFlags($ans), # any additional ones from the object itself ); $ans->{isPreview} = $self->getPG('$inputs_ref->{previewAnswers}'); $ans->{cmp_class} = $self->cmp_class($ans) unless $ans->{cmp_class}; @@ -92,7 +94,7 @@ } } else { $self->cmp_error($ans); - $self->cmp_collect($ans); + $self->cmp_collect($ans); ## FIXME: why is this here a second time? } contextSet($context,%{$flags}); # restore context values Parser::Context->current(undef,$current); # put back the old context @@ -228,6 +230,7 @@ # filled in by sub-classes # sub cmp_postprocess {} +sub cmp_contextFlags {return ()} # # create answer rules of various types @@ -773,15 +776,6 @@ $other->type =~ m/^(Interval|Union|Set)$/; } -sub cmp_compare { - my $self = shift; my $other = shift; my $ans = shift; - my $oldignore = $self->{requireParenMatch}; - $self->{ignoreEndpointTypes} = !$ans->{requireParenMatch}; - my $equal = $self->SUPER::cmp_compare($other,$ans); - $self->{ignoreEndpointTypes} = $oldignore; - return $equal; -} - # # Check for wrong enpoints and wrong type of endpoints # @@ -840,8 +834,7 @@ # sub cmp_equal { my ($self,$ans) = @_; - Value::List::cmp_equal(@_) - if $ans->{student_value}->type eq 'Set'; + Value::List::cmp_equal(@_) if $ans->{student_value}->type eq 'Set'; Value::cmp_equal(@_); } @@ -897,7 +890,7 @@ extra => $element, requireParenMatch => 1, removeParens => 1, - ); + ); } # Index: Formula.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Formula.pm,v retrieving revision 1.32 retrieving revision 1.33 diff -Llib/Value/Formula.pm -Llib/Value/Formula.pm -u -r1.32 -r1.33 --- lib/Value/Formula.pm +++ lib/Value/Formula.pm @@ -45,12 +45,15 @@ sub blank {$pkg->SUPER::new('')} # -# with() changes tree element not formula itself -# (maybe the wrong choice?) +# with() changes tree element as well +# as the formula itself. # sub with { my $self = shift; my %hash = @_; - foreach my $id (keys(%hash)) {$self->{tree}{$id} = $hash{$id}} + foreach my $id (keys(%hash)) { + $self->{tree}{$id} = $hash{$id}; + $self->{$id} = $hash{$id}; + } return $self; } @@ -465,19 +468,6 @@ return $m + $n*int(rand()*(int(($M-$m)/$n)+1)); } -# -# Get the value of a flag from the object itself, -# or from the context, or from the default context -# or from the given default, whichever is found first. -# -sub getFlag { - my $self = shift; my $name = shift; - return $self->{$name} if defined($self->{$name}); - return $self->{context}{flags}{$name} if defined($self->{context}{flags}{$name}); - return $$Value::context->{flags}{$name} if defined($$Value::context->{flags}{$name}); - return shift; -} - ############################################ # # Check if the value of a formula is constant Index: Interval.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Interval.pm,v retrieving revision 1.22 retrieving revision 1.23 diff -Llib/Value/Interval.pm -Llib/Value/Interval.pm -u -r1.22 -r1.23 --- lib/Value/Interval.pm +++ lib/Value/Interval.pm @@ -219,8 +219,9 @@ $r = promote($r); if ($flag) {my $tmp = $l; $l = $r; $r = $tmp}; my ($la,$lb) = @{$l->data}; my ($ra,$rb) = @{$r->data}; my $cmp = $la <=> $ra; return $cmp if $cmp; - $cmp = $l->{open} cmp $r->{open}; return $cmp if $cmp && !$l->{ignoreEndpointTypes}; - $cmp = $lb <=> $rb; return $cmp if $cmp || $l->{ignoreEndpointTypes}; + my $ignoreEndpointTypes = $l->getFlag('ignoreEndpointTypes'); + $cmp = $l->{open} cmp $r->{open}; return $cmp if $cmp && !$ignoreEndpointTypes; + $cmp = $lb <=> $rb; return $cmp if $cmp || $ignoreEndpointTypes; return $l->{close} cmp $r->{close}; } |