[system] / trunk / pg / macros / parserFormulaUpToConstant.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/parserFormulaUpToConstant.pl

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

Revision 5987 Revision 5988
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.18 2008/09/16 03:23:54 dpvc Exp $ 4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.19 2008/09/21 18:06:19 dpvc Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
171 return 3 if !defined($r->{constant}); 171 return 3 if !defined($r->{constant});
172 # 172 #
173 # If constants aren't the same, substitute the professor's in the student answer. 173 # If constants aren't the same, substitute the professor's in the student answer.
174 # 174 #
175 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant}; 175 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant};
176
176 # 177 #
177 # Compare with adaptive parameters to see if $l + n0 C = $r for some n0. 178 # Compare with adaptive parameters to see if $l + n0 C = $r for some n0.
178 # 179 #
179 my $adapt = $l->adapt; 180 my $adapt = $l->adapt;
180 my $equal = $adapt->cmp_compare($r,{}); 181 my $equal = Parser::Eval(sub {$adapt == $r});
181 $self->{adapt} = $self->{adapt}->inherit($adapt); # save the adapted value's flags 182 $self->{adapt} = $self->{adapt}->inherit($adapt); # save the adapted value's flags
183 $self->{adapt}{test_values} = $adapt->{test_values}; # (these two are removed by inherit)
184 $self->{adapt}{test_adapt} = $adapt->{test_adapt};
185 $_[1]->{test_values} = $r->{test_values}; # save these in student answer for diagnostics
182 return -1 unless $equal; 186 return -1 unless $equal;
183 # 187 #
184 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) 188 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer)
185 # (remember: return value of 0 is equal, and non-zero is unequal) 189 # (remember: return value of 0 is equal, and non-zero is unequal)
186 # 190 #
190# 194#
191# Return the {adapt} formula with test points adjusted 195# Return the {adapt} formula with test points adjusted
192# 196#
193sub adapt { 197sub adapt {
194 my $self = shift; 198 my $self = shift;
195 my $adapt = $self->{adapt}->inherit($self); delete $adapt->{adapt};
196 return $self->adjustInherit($self->{adapt}); 199 return $self->adjustInherit($self->{adapt});
197} 200}
198 201
199# 202#
200# Inherit from the main FormulaUpToConstant, but 203# Inherit from the main FormulaUpToConstant, but
260# Provide diagnostics based on the adapted function used to check 263# Provide diagnostics based on the adapted function used to check
261# the student's answer 264# the student's answer
262# 265#
263sub cmp_diagnostics { 266sub cmp_diagnostics {
264 my $self = shift; 267 my $self = shift;
268 my $adapt = $self->inherit($self->{adapt});
269 $adapt->{test_values} = $self->{adapt}{test_values}; # these aren't copied by inherit
270 $adapt->{test_adapt} = $self->{adapt}{test_adapt};
265 $self->inherit($self->{adapt})->SUPER::cmp_diagnostics(@_); 271 $adapt->SUPER::cmp_diagnostics(@_);
266} 272}
267 273
268# 274#
269# Make it possible to graph single-variable formulas by setting 275# Make it possible to graph single-variable formulas by setting
270# the arbitrary constants to 0 first. 276# the arbitrary constants to 0 first.
287 my $self = shift; my $ans = shift; 293 my $self = shift; my $ans = shift;
288 $self->SUPER::cmp_postprocess($ans,@_); 294 $self->SUPER::cmp_postprocess($ans,@_);
289 return unless $ans->{score} == 0 && !$ans->{isPreview}; 295 return unless $ans->{score} == 0 && !$ans->{isPreview};
290 return if $ans->{ans_message} || !$self->getFlag("showHints"); 296 return if $ans->{ans_message} || !$self->getFlag("showHints");
291 my $student = $ans->{student_value}; 297 my $student = $ans->{student_value};
292 $main::{_cmp_} = sub {return $ans->{correct_value} <=> $student}; # compare encodes the reason in the result 298 my $result = Parser::Eval(sub {return $ans->{correct_value} <=> $student}); # compare encodes the reason in the result
293 my $result = main::PG_restricted_eval('&{$main::{_cmp_}}');
294 delete $main::{_cmp_};
295 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3; 299 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3;
296 if ($result == 3) { 300 if ($result == 3) {
297 my $context = $self->context; 301 my $context = $self->context;
298 $context->flags->set(no_parameters=>0); 302 $context->flags->set(no_parameters=>0);
299 $context->variables->add(x00=>'Real'); 303 $context->variables->add(x00=>'Real');

Legend:
Removed from v.5987  
changed lines
  Added in v.5988

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9