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

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

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

Revision 5584 Revision 5585
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/displayMacros.pl,v 1.9 2007/10/04 16:41:07 sh002i Exp $ 4# $CVSHeader: pg/macros/PGnumericevaluators.pl,v 1.1 2007/11/08 00:00:15 sh002i 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.
76my $numZeroLevelTolDefault; 76my $numZeroLevelTolDefault;
77my $useOldAnswerMacros; 77my $useOldAnswerMacros;
78my $user_context; 78my $user_context;
79sub _PGnumericevaluators_init { 79sub _PGnumericevaluators_init {
80 $CA = PG_restricted_eval(q/$CA/); 80 $CA = PG_restricted_eval(q/$CA/);
81 $numAbsTolDefault = PG_restricted_eval(q/$numAbsTolDefault/); 81 $numAbsTolDefault = PG_restricted_eval(q/$envir{numAbsTolDefault}/);
82 $numFormatDefault = PG_restricted_eval(q/$numFormatDefault/); 82 $numFormatDefault = PG_restricted_eval(q/$envir{numFormatDefault}/);
83 $numRelPercentTolDefault = PG_restricted_eval(q/$numRelPercentTolDefault/); 83 $numRelPercentTolDefault = PG_restricted_eval(q/$envir{numRelPercentTolDefault}/);
84 $numZeroLevelDefault = PG_restricted_eval(q/$numZeroLevelDefault/); 84 $numZeroLevelDefault = PG_restricted_eval(q/$envir{numZeroLevelDefault}/);
85 $numZeroLevelTolDefault = PG_restricted_eval(q/$numZeroLevelTolDefault/); 85 $numZeroLevelTolDefault = PG_restricted_eval(q/$envir{numZeroLevelTolDefault}/);
86 $useOldAnswerMacros = PG_restricted_eval(q/$useOldAnswerMacros/); 86 $useOldAnswerMacros = PG_restricted_eval(q/$envir{useOldAnswerMacros}/);
87 unless ($useOldAnswerMacros) { 87 unless ($useOldAnswerMacros) {
88 $user_context = PG_restricted_eval(q/\%context/); 88 $user_context = PG_restricted_eval(q/\%context/);
89 $Context = sub { Parser::Context->current($user_context, @_) }; 89 $Context = sub { Parser::Context->current($user_context, @_) };
90 } 90 }
91} 91}
376 # produce answer evaluators 376 # produce answer evaluators
377 foreach my $ans (@ans_list) { 377 foreach my $ans (@ans_list) {
378 if( defined( $out_options{'units'} ) ) { 378 if( defined( $out_options{'units'} ) ) {
379 $ans = "$ans $out_options{'units'}"; 379 $ans = "$ans $out_options{'units'}";
380 380
381 push( @output_list, NUM_CMP( 'correctAnswer' => $ans, 381 push( @output_list, NUM_CMP(
382 'correctAnswer' => $ans,
382 'tolerance' => $out_options{'tolerance'}, 383 'tolerance' => $out_options{'tolerance'},
383 'tolType' => $out_options{'tolType'}, 384 'tolType' => $out_options{'tolType'},
384 'format' => $out_options{'format'}, 385 'format' => $out_options{'format'},
385 'mode' => $out_options{'mode'}, 386 'mode' => $out_options{'mode'},
386 'zeroLevel' => $out_options{'zeroLevel'}, 387 'zeroLevel' => $out_options{'zeroLevel'},
390 ) 391 )
391 ); 392 );
392 } elsif( defined( $out_options{'strings'} ) ) { 393 } elsif( defined( $out_options{'strings'} ) ) {
393 394
394 395
395 push( @output_list, NUM_CMP( 'correctAnswer' => $ans, 396 push( @output_list, NUM_CMP(
397 'correctAnswer' => $ans,
396 'tolerance' => $out_options{tolerance}, 398 'tolerance' => $out_options{tolerance},
397 'tolType' => $out_options{tolType}, 399 'tolType' => $out_options{tolType},
398 'format' => $out_options{'format'}, 400 'format' => $out_options{'format'},
399 'mode' => $out_options{'mode'}, 401 'mode' => $out_options{'mode'},
400 'zeroLevel' => $out_options{'zeroLevel'}, 402 'zeroLevel' => $out_options{'zeroLevel'},
401 'zeroLevelTol' => $out_options{'zeroLevelTol'}, 403 'zeroLevelTol' => $out_options{'zeroLevelTol'},
402 'debug' => $out_options{'debug'}, 404 'debug' => $out_options{'debug'},
403 'strings' => $out_options{'strings'}, 405 'strings' => $out_options{'strings'},
404 ) 406 )
405 ); 407 );
406 } else { 408 } else {
407 push(@output_list, 409 push(@output_list,
410 NUM_CMP(
408 NUM_CMP( 'correctAnswer' => $ans, 411 'correctAnswer' => $ans,
409 'tolerance' => $out_options{tolerance}, 412 'tolerance' => $out_options{tolerance},
410 'tolType' => $out_options{tolType}, 413 'tolType' => $out_options{tolType},
411 'format' => $out_options{'format'}, 414 'format' => $out_options{'format'},
412 'mode' => $out_options{'mode'}, 415 'mode' => $out_options{'mode'},
413 'zeroLevel' => $out_options{'zeroLevel'}, 416 'zeroLevel' => $out_options{'zeroLevel'},
414 'zeroLevelTol' => $out_options{'zeroLevelTol'}, 417 'zeroLevelTol' => $out_options{'zeroLevelTol'},
415 'debug' => $out_options{'debug'}, 418 'debug' => $out_options{'debug'},
416 ), 419 ),
417 ); 420 );
418 } 421 }
419 } 422 }
550## format is of the form "%10.3g" or "", i.e., a format suitable for sprintf(). Use "" for default 553## format is of the form "%10.3g" or "", i.e., a format suitable for sprintf(). Use "" for default
551## You must enter a format and tolerance 554## You must enter a format and tolerance
552 555
553sub std_num_cmp_list { 556sub std_num_cmp_list {
554 my ( $relPercentTol, $format, @answerList) = @_; 557 my ( $relPercentTol, $format, @answerList) = @_;
555 558 #FIXME? errors if not defined?
556 my %options = ( 'relTol' => $relPercentTol, 559 my %options = ( 'relTol' => $relPercentTol,
557 'format' => $format, 560 'format' => $format,
558 ); 561 );
559 562
560 set_default_options( \%options, 563 set_default_options( \%options,
561 'tolType' => 'relative', 564 'tolType' => 'relative',
562 'tolerance' => $numRelPercentTolDefault, 565 'tolerance' => $numRelPercentTolDefault,
943 # 946 #
944 # check for required parameters 947 # check for required parameters
945 # 948 #
946 my @keys = qw(correctAnswer tolerance tolType format mode zeroLevel zeroLevelTol debug); 949 my @keys = qw(correctAnswer tolerance tolType format mode zeroLevel zeroLevelTol debug);
947 foreach my $key (@keys) { 950 foreach my $key (@keys) {
948 warn "$key must be defined in options when calling NUM_CMP" 951 warn( "$key must be defined in options when calling NUM_CMP" )
949 unless defined($num_params{$key}); 952 unless defined($num_params{$key});
950 } 953 }
951 954
952 my $correctAnswer = $num_params{correctAnswer}; 955 my $correctAnswer = $num_params{correctAnswer};
953 my $mode = $num_params{mode}; 956 my $mode = $num_params{mode};

Legend:
Removed from v.5584  
changed lines
  Added in v.5585

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9