[system] / trunk / pg / macros / parserFormulaUpToConstant.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

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

Revision 5917 Revision 6058
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
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
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 #
180 my \$equal = \$adapt->cmp_compare(\$r,{}); 181 my \$equal = Parser::Eval(sub {\$adapt == \$r});
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#
192# 196#
194 my \$self = shift; 198 my \$self = shift;
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
262# 265#
263sub cmp_diagnostics { 266sub cmp_diagnostics {
264 my \$self = shift; 267 my \$self = shift;
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);