[system] / branches / gage_dev / pg / lib / Value / AnswerChecker.pm Repository:
ViewVC logotype

Diff of /branches/gage_dev/pg/lib/Value/AnswerChecker.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2621 Revision 2622
515 my $student = $ans->{student_value}; 515 my $student = $ans->{student_value};
516 my @student = ($student); 516 my @student = ($student);
517 if ($student->class eq $self->class && 517 if ($student->class eq $self->class &&
518 ($allowParens || (!$student->{open} && !$student->{close}))) { 518 ($allowParens || (!$student->{open} && !$student->{close}))) {
519 @student = @{$student->{data}}; 519 @student = @{$student->{data}};
520 } elsif ($student->class eq 'Formula' && $student->type eq 'List') { 520 } elsif ($student->class eq 'Formula' && $student->type eq $self->type) {
521 @student = (); 521 #
522 foreach my $entry (@{$student->{tree}{coords}}) { 522 # Convert a formula returning a list to a list of formulas
523 #
524 @student = (); my @entries;
525 if ($self->type eq 'List') {@entries = @{$student->{tree}{coords}}}
526 else {@entries = $student->{tree}->makeUnion}
527 foreach my $entry (@entries) {
523 my $v = Parser::Formula($entry); 528 my $v = Parser::Formula($entry);
524 $v = Parser::Evaluate($v) if (defined($v) && $v->isConstant); 529 $v = Parser::Evaluate($v) if (defined($v) && $v->isConstant);
525 # FIXME: what if there is an error?
526 push(@student,$v); 530 push(@student,$v);
531 #
532 # In case there is an error evaluating the answer.
533 # (there shouldn't be, but you never know)
534 #
535 if (!defined($v)) {
536 my $cmp_error = $ans->{cmp_error} || 'cmp_error';
537 $self->$cmp_error; return;
538 }
527 } 539 }
528 } 540 }
529 541
530 # 542 #
531 # Initialize the score 543 # Initialize the score
553 } 565 }
554 } 566 }
555 # 567 #
556 # Give messages about incorrect answers 568 # Give messages about incorrect answers
557 # 569 #
558 my $nth = ''; $nth = ' '.$self->NameForNumber($i) if (scalar(@student) > 1); 570 my $nth = ''; my $class = $self->cmp_class;
571 if (scalar(@student) > 1) {
572 $nth = ' '.$self->NameForNumber($i);
573 $class = $ans->{cmp_class};
574 }
559 if ($showTypeWarnings && !$typeMatch->typeMatch($entry,$ans)) { 575 if ($showTypeWarnings && !$typeMatch->typeMatch($entry,$ans) &&
560 next ENTRY if ($ans->{ignoreStrings} && $entry->class eq 'String'); 576 !($ans->{ignoreStrings} && $entry->class eq 'String')) {
561 push(@errors,"Your$nth value isn't ".lc($ans->{cmp_class}). 577 push(@errors,"Your$nth value isn't ".lc($class).
562 " (it looks like ".lc($entry->showClass(1)).")"); 578 " (it looks like ".lc($entry->showClass(1)).")");
563 } elsif ($showHints && $m > 1) { 579 } elsif ($showHints && $m > 1) {
564 push(@errors,"Your$nth $value is incorrect"); 580 push(@errors,"Your$nth $value is incorrect");
565 } 581 }
566 } 582 }
597 613
598############################################################# 614#############################################################
599 615
600package Value::Formula; 616package Value::Formula;
601 617
602# 618## FIXME: Need to check types for error reporting
603# No cmp function (for now) 619sub typeMatch {1}
604# 620
621## FIXME: Do formula returning list as list of formulas
622## and formula returning union as union of formulas
605sub cmp { 623sub cmp_equal {
606 die "Answer checker for formulas is not yet defined"; 624 my $self = shift;
625 $self->{context}->flags->set(
626 random_seed => $self->getPG('$PG_original_problemSeed')
627 );
628 $self->SUPER::cmp_equal(@_);
607} 629}
630
631#
632# Replace the ones in Value::Formula
633#
634sub PGseedRandom {
635 my $self = shift;
636 return if $self->{PGrandom};
637 $self->{PGrandom} = new PGrandom($self->{context}->flag('random_seed'));
638}
639sub PGgetRandom {shift->{PGrandom}->getRandom(@_)}
608 640
609############################################################# 641#############################################################
610 642
6111; 6431;

Legend:
Removed from v.2621  
changed lines
  Added in v.2622

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9