[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 5913 Revision 5914
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.16 2008/09/15 15:35:34 dpvc Exp $ 4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.17 2008/09/16 03:01:17 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;
122 # 121 #
123 # Create a formula from the user's input. 122 # Create a formula from the user's input.
124 # 123 #
125 my $f = main::Formula($context,@_); 124 my $f = main::Formula($context,@_);
126 # 125 #
186 # 185 #
187 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) 186 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer)
188 # (remember: return value of 0 is equal, and non-zero is unequal) 187 # (remember: return value of 0 is equal, and non-zero is unequal)
189 # 188 #
190 return abs($context->variables->get("n00")->{value}) < $context->flag("zeroLevelTol"); 189 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(@_);
200} 190}
201 191
202# 192#
203# Return the {adapt} formula with test points adjusted 193# Return the {adapt} formula with test points adjusted
204# 194#
258 248
259# 249#
260# Show hints by default 250# Show hints by default
261# 251#
262sub cmp_defaults {((shift)->SUPER::cmp_defaults,showHints => 1, showLinearityHints => 1)}; 252sub cmp_defaults {((shift)->SUPER::cmp_defaults,showHints => 1, showLinearityHints => 1)};
253
254#
255# Provide diagnostics based on the adapted function used to check
256# the student's answer
257#
258sub cmp_diagnostics {
259 my $self = shift;
260 $self->inherit($self->{adapt})->SUPER::cmp_diagnostics(@_);
261}
262
263#
264# Make it possible to graph single-variable formulas by setting
265# the arbitrary constants to 0 first.
266#
267sub cmp_graph {
268 my $self = shift; my $diagnostics = shift;
269 my $F1 = shift; my $F2; ($F1,$F2) = @{$F1} if (ref($F1) eq 'ARRAY');
270 my %subs; my $context = $self->context;
271 foreach my $v ($context->variables->variables)
272 {$subs{$v} = 0 if ($context->variables->get($v)->{arbitraryConstant})}
273 $F1 = $F1->inherit($F1->{adapt})->substitute(%subs)->reduce;
274 $F2 = $F2->inherit($F2->{adapt})->substitute(%subs)->reduce;
275 $self->SUPER::cmp_graph($diagnostics,[$F1,$F2]);
276}
263 277
264# 278#
265# Add useful messages, if the author requested them 279# Add useful messages, if the author requested them
266# 280#
267sub cmp_postprocess { 281sub cmp_postprocess {

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9