[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 5912 Revision 5913
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.15 2008/09/12 21:53:52 dpvc Exp $ 4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.16 2008/09/15 15:35:34 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.
116 # Copy the context (so we can modify it) and 116 # Copy the context (so we can modify it) and
117 # replace the usual Variable object with our own. 117 # replace the usual Variable object with our own.
118 # 118 #
119 my $context = (Value::isContext($_[0]) ? shift : $self->context)->copy; 119 my $context = (Value::isContext($_[0]) ? shift : $self->context)->copy;
120 $context->{parser}{Variable} = 'FormulaUpToConstant::Variable'; 120 $context->{parser}{Variable} = 'FormulaUpToConstant::Variable';
121 $context->{diagnostics}{formulas}{showGraphs} = 0;
121 # 122 #
122 # Create a formula from the user's input. 123 # Create a formula from the user's input.
123 # 124 #
124 my $f = main::Formula($context,@_); 125 my $f = main::Formula($context,@_);
125 # 126 #
174 # 175 #
175 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant}; 176 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant};
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 $adapt = $l->adapt;
179 $main::{_cmp_} = sub {return $l->adapt == $r}; # a closure to access local variables 181 $main::{_cmp_} = sub {return $adapt == $r}; # a closure to access local variables
180 my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters 182 my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters
181 delete $main::{_cmp_}; # remove temprary function 183 delete $main::{_cmp_}; # remove temprary function
184 $self->{adapt} = $self->{adapt}->inherit($adapt); # save the adapted value's flags
182 return -1 unless $equal; 185 return -1 unless $equal;
183 # 186 #
184 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) 187 # 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) 188 # (remember: return value of 0 is equal, and non-zero is unequal)
186 # 189 #
187 return abs($context->variables->get("n00")->{value}) < $context->flag("zeroLevelTol"); 190 return abs($context->variables->get("n00")->{value}) < $context->flag("zeroLevelTol");
191}
192
193#
194# Provide diagnostics based on the adapted function used to check
195# the student's answer
196#
197sub cmp_diagnostics {
198 my $self = shift;
199 $self->inherit($self->{adapt})->SUPER::cmp_diagnostics(@_);
188} 200}
189 201
190# 202#
191# Return the {adapt} formula with test points adjusted 203# Return the {adapt} formula with test points adjusted
192# 204#

Legend:
Removed from v.5912  
changed lines
  Added in v.5913

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9