[system] / trunk / webwork / system / courseScripts / PGanswermacros.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/courseScripts/PGanswermacros.pl

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

Revision 237 Revision 274
351 'relTol' => $numRelPercentTolDefault, 351 'relTol' => $numRelPercentTolDefault,
352 'units' => undef, 352 'units' => undef,
353 'strings' => undef, 353 'strings' => undef,
354 'zeroLevel' => $numZeroLevelDefault, 354 'zeroLevel' => $numZeroLevelDefault,
355 'zeroLevelTol' => $numZeroLevelTolDefault, 355 'zeroLevelTol' => $numZeroLevelTolDefault,
356 'tolType' => 'relative', 356 'tolType' => 'relative',
357 'tolerance' => 1, 357 'tolerance' => 1,
358 'reltol' => undef, #alternate spelling 358 'reltol' => undef, #alternate spelling
359 'unit' => undef, #alternate spelling 359 'unit' => undef, #alternate spelling
360 'debug' => 0 360 'debug' => 0
361 ); 361 );
362 362
375 " check that your first option is spelled correctly)."; 375 " check that your first option is spelled correctly).";
376 376
377 %out_options = ( 'relTol' => $relPercentTol, 377 %out_options = ( 'relTol' => $relPercentTol,
378 'format' => $format, 378 'format' => $format,
379 'zeroLevel' => $zeroLevel, 379 'zeroLevel' => $zeroLevel,
380 'zeroLevelTol' => $zeroLevelTol, 380 'zeroLevelTol' => $zeroLevelTol,
381 'mode' => 'std' 381 'mode' => 'std'
382 ); 382 );
383 } 383 }
384 384
385######################################################################### 385#########################################################################
388######################################################################### 388#########################################################################
389 %out_options = @opt; 389 %out_options = @opt;
390 assign_option_aliases( \%out_options, 390 assign_option_aliases( \%out_options,
391 'reltol' => 'relTol', 391 'reltol' => 'relTol',
392 'unit' => 'units', 392 'unit' => 'units',
393 'abstol' => 'tol',
393 ); 394 );
394 395
395 set_default_options( \%out_options, 396 set_default_options( \%out_options,
396 'tolType' => (defined($out_options{tol}) ) ? 'absolute' : 'relative', 397 'tolType' => (defined($out_options{tol}) ) ? 'absolute' : 'relative', # the existence of "tol" means that we use absolute tolerance mode
397 'tolerance' => (defined($out_options{tol}) ) ? $numAbsTolDefault : $numRelPercentTolDefault, 398 'tolerance' => (defined($out_options{tol}) ) ? $numAbsTolDefault : $numRelPercentTolDefault,
398 'mode' => 'std', 399 'mode' => 'std',
399 'format' => $numFormatDefault, 400 'format' => $numFormatDefault,
400 'tol' => $numAbsTolDefault, 401 'tol' => undef,
401 'relTol' => $numRelPercentTolDefault, 402 'relTol' => undef,
402 'units' => undef, 403 'units' => undef,
403 'strings' => undef, 404 'strings' => undef,
404 'zeroLevel' => $numZeroLevelDefault, 405 'zeroLevel' => $numZeroLevelDefault,
405 'zeroLevelTol' => $numZeroLevelTolDefault, 406 'zeroLevelTol' => $numZeroLevelTolDefault,
406 'debug' => 0, 407 'debug' => 0,
410 if( defined( $out_options{'units'} ) && defined( $out_options{'strings'} ) ) { 411 if( defined( $out_options{'units'} ) && defined( $out_options{'strings'} ) ) {
411 warn "Can't use both 'units' and 'strings' in the same problem " . 412 warn "Can't use both 'units' and 'strings' in the same problem " .
412 "(check your parameters to num_cmp() )"; 413 "(check your parameters to num_cmp() )";
413 } 414 }
414 415
415 # my ($tolType, $tol); 416 # Handle legacy options
416 if ($out_options{tolType} eq 'absolute') { 417 if ($out_options{tolType} eq 'absolute') {
417 $out_options{'tolerance'}=$out_options{'tol'}; 418 $out_options{'tolerance'}=$out_options{'tol'} if defined($out_options{'tol'});
418 delete($out_options{'relTol'}) if exists( $out_options{'relTol'} ); 419 delete($out_options{'relTol'}) if exists( $out_options{'relTol'} );
419 } else { 420 } else {
420 $out_options{'tolerance'}=$out_options{'relTol'}; 421 $out_options{'tolerance'}=$out_options{'relTol'} if defined($out_options{'relTol'});
421 # delete($out_options{'tol'}) if exists( $out_options{'tol'} ); 422 # delete($out_options{'tol'}) if exists( $out_options{'tol'} );
422 } 423 }
423 424 # end legacy options
425
424 # thread over lists 426 # thread over lists
425 my @ans_list = (); 427 my @ans_list = ();
426 428
427 if ( ref($correctAnswer) eq 'ARRAY' ) { 429 if ( ref($correctAnswer) eq 'ARRAY' ) {
428 @ans_list = @{$correctAnswer}; 430 @ans_list = @{$correctAnswer};
434 foreach my $ans (@ans_list) { 436 foreach my $ans (@ans_list) {
435 if( defined( $out_options{'units'} ) ) { 437 if( defined( $out_options{'units'} ) ) {
436 $ans = "$ans $out_options{'units'}"; 438 $ans = "$ans $out_options{'units'}";
437 439
438 push( @output_list, NUM_CMP( 'correctAnswer' => $ans, 440 push( @output_list, NUM_CMP( 'correctAnswer' => $ans,
439 'tolerance' => $out_options{tolerance}, 441 'tolerance' => $out_options{'tolerance'},
440 'tolType' => $out_options{tolType}, 442 'tolType' => $out_options{'tolType'},
441 'format' => $out_options{'format'}, 443 'format' => $out_options{'format'},
442 'mode' => $out_options{'mode'}, 444 'mode' => $out_options{'mode'},
443 'zeroLevel' => $out_options{'zeroLevel'}, 445 'zeroLevel' => $out_options{'zeroLevel'},
444 'zeroLevelTol' => $out_options{'zeroLevelTol'}, 446 'zeroLevelTol' => $out_options{'zeroLevelTol'},
445 'debug' => $out_options{'debug'}, 447 'debug' => $out_options{'debug'},
446 'units' => $out_options{'units'}, 448 'units' => $out_options{'units'},
447 ) 449 )
448 ); 450 );
449 } elsif( defined( $out_options{'strings'} ) ) { 451 } elsif( defined( $out_options{'strings'} ) ) {
450 #if( defined $out_options{'tol'} ) {
451 # warn "You are using 'tol' (for absolute tolerance) with a num/str " .
452 # "compare, which currently only uses relative tolerance. The default " .
453 # "tolerance will be used.";
454 #} 452
455 453
456 push( @output_list, NUM_CMP( 'correctAnswer' => $ans, 454 push( @output_list, NUM_CMP( 'correctAnswer' => $ans,
457 'tolerance' => $out_options{tolerance}, 455 'tolerance' => $out_options{tolerance},
458 'tolType' => $out_options{tolType}, 456 'tolType' => $out_options{tolType},
459 'format' => $out_options{'format'}, 457 'format' => $out_options{'format'},
460 'mode' => $out_options{'mode'}, 458 'mode' => $out_options{'mode'},
461 'zeroLevel' => $out_options{'zeroLevel'}, 459 'zeroLevel' => $out_options{'zeroLevel'},
462 'zeroLevelTol' => $out_options{'zeroLevelTol'}, 460 'zeroLevelTol' => $out_options{'zeroLevelTol'},

Legend:
Removed from v.237  
changed lines
  Added in v.274

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9