From: dpvc v. a. <we...@ma...> - 2010-01-27 12:04:38
|
Log Message: ----------- Make Formula typeMatch work with test_points, and not produce error messages 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.126 retrieving revision 1.127 diff -Llib/Value/AnswerChecker.pm -Llib/Value/AnswerChecker.pm -u -r1.126 -r1.127 --- lib/Value/AnswerChecker.pm +++ lib/Value/AnswerChecker.pm @@ -1579,14 +1579,25 @@ sub typeMatch { my $self = shift; my $other = shift; my $ans = shift; return 1 if $self->type eq $other->type; - my $typeMatch = ($self->createRandomPoints(1))[1]->[0]; - $other = eval {($other->createRandomPoints(1))[1]->[0]} if Value::isFormula($other); + my $typeMatch = $self->getTypicalValue($self); + $other = $self->getTypicalValue($other) if Value::isFormula($other); return 1 unless defined($other); # can't really tell, so don't report type mismatch return 1 if $typeMatch->classMatch('String') && Value::isFormula($ans->{typeMatch}); # avoid infinite loop $typeMatch->typeMatch($other,$ans); } # +# Create a value from the formula (so we know the output type) +# +sub getTypicalValue { + my $self = shift; my $f = shift; + return $f->{test_values}[0] if $f->{test_values}; + my $points = $f->{test_points} || $self->{test_points}; + return ($f->createPointValues($points)||[])->[0] if $points; + return ((($f->createRandomPoints(1,undef,1))[1])||[])->[0]; +} + +# # Handle removal of outermost parens in a list. # Evaluate answer, if the eval option is used. # Handle the UpToConstant option. |