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

Diff of /trunk/pg/lib/Value/AnswerChecker.pm

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

Revision 2687 Revision 2688
46sub cmp_parse { 46sub cmp_parse {
47 my $self = shift; my $ans = shift; 47 my $self = shift; my $ans = shift;
48 # 48 #
49 # Do some setup 49 # Do some setup
50 # 50 #
51 my $context = $$Value::context; # save it for later 51 my $current = $$Value::context; # save it for later
52 my $context = $ans->{correct_value}{context};
52 Parser::Context->current(undef,$self->{context}); # change to object's context 53 Parser::Context->current(undef,$context); # change to correct answser's context
53 $context->flags->set(StringifyAsTeX => 0); # reset this, just in case. 54 $context->flags->set(StringifyAsTeX => 0); # reset this, just in case.
54 $context->flags->set(no_parameters => 1); # don't let students enter parameters 55 $context->flags->set(no_parameters => 1); # don't let students enter parameters
55 $ans->{isPreview} = $self->getPG('$inputs_ref->{previewAnswers}'); 56 $ans->{isPreview} = $self->getPG('$inputs_ref->{previewAnswers}');
56 $ans->{cmp_class} = $self->cmp_class($ans) unless $ans->{cmp_class}; 57 $ans->{cmp_class} = $self->cmp_class($ans) unless $ans->{cmp_class};
57 58
77 $self->cmp_postprocess($ans) if !$ans->{error_message}; 78 $self->cmp_postprocess($ans) if !$ans->{error_message};
78 } else { 79 } else {
79 $self->cmp_error($ans); 80 $self->cmp_error($ans);
80 } 81 }
81 $context->flags->set(no_parameters => 0); # let professors enter parameters 82 $context->flags->set(no_parameters => 0); # let professors enter parameters
82 Parser::Context->current(undef,$context); # put back the old context 83 Parser::Context->current(undef,$current); # put back the old context
83 return $ans; 84 return $ans;
84} 85}
85 86
86# 87#
87# Check if the parsed student answer equals the professor's answer 88# Check if the parsed student answer equals the professor's answer
653 654
654 my $type = $self->type; 655 my $type = $self->type;
655 $type = ($self->isComplex)? 'Complex': 'Real' if $type eq 'Number'; 656 $type = ($self->isComplex)? 'Complex': 'Real' if $type eq 'Number';
656 $type = 'Value::'.$type.'::'; 657 $type = 'Value::'.$type.'::';
657 658
658 return (&{$type.'cmp_defaults'}($self,@_)) 659 return (&{$type.'cmp_defaults'}($self,@_), upToConstant => 0)
659 if defined(%$type) && $self->type ne 'List'; 660 if defined(%$type) && $self->type ne 'List';
660 661
661 return ( 662 return (
662 Value::List::cmp_defaults($self,@_), 663 Value::List::cmp_defaults($self,@_),
663 removeParens => $self->{autoFormula}, 664 removeParens => $self->{autoFormula},
685 my $self = shift; 686 my $self = shift;
686 my $cmp = $self->SUPER::cmp(@_); 687 my $cmp = $self->SUPER::cmp(@_);
687 if ($cmp->{rh_ans}{removeParens} && $self->type eq 'List') { 688 if ($cmp->{rh_ans}{removeParens} && $self->type eq 'List') {
688 $self->{tree}{open} = $self->{tree}{close} = ''; 689 $self->{tree}{open} = $self->{tree}{close} = '';
689 $cmp->ans_hash(correct_ans => $self->stringify); 690 $cmp->ans_hash(correct_ans => $self->stringify);
691 }
692 if ($cmp->{rh_ans}{upToConstant}) {
693 my $current = Parser::Context->current();
694 my $context = $self->{context} = $self->{context}->copy;
695 Parser::Context->current(undef,$context);
696 $context->{_variables}->{pattern} = $context->{_variables}->{namePattern} =
697 'C0|' . $context->{_variables}->{pattern};
698 $context->update; $context->variables->add('C0' => 'Parameter');
699 $cmp->ans_hash(correct_value => Value::Formula->new('C0')+$self);
700 Parser::Context->current(undef,$current);
690 } 701 }
691 return $cmp; 702 return $cmp;
692} 703}
693 704
694sub cmp_equal { 705sub cmp_equal {

Legend:
Removed from v.2687  
changed lines
  Added in v.2688

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9