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

View of /trunk/pg/macros/PGmiscevaluators.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5584 - (download) (as text) (annotate)
Thu Nov 8 00:00:15 2007 UTC (12 years, 3 months ago) by sh002i
File size: 4324 byte(s)
Split answer evaluators into several new files, based on the type of
answer being evaluated. The answer evaluators are fully documented, but
the rest of the functions in PGanswermacros.pl still need docs. This
still needs to be tested a bunch before it's ready for prime time.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    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 $
    5 #
    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
    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.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 =head1 NAME
   18 
   19 PGmiscevaluators.pl - Some miscellaneous answer macros.
   20 
   21 =head1 SYNOPSIS
   22 
   23 =head1 DESCRIPTION
   24 
   25 Currently contains answer evaluators for radio buttons and checkboxes.
   26 
   27 =head2 MathObjects and answer evaluators
   28 
   29 The MathObjects system provides a parserRadioButtons.pl file that manages
   30 display and checking of radio-button based answers. It is recommended that you
   31 use this method directly if possible.
   32 
   33 =cut
   34 
   35 BEGIN { be_strict() }
   36 sub _PGmiscevaluators_init {}
   37 
   38 =head1 checkbox_cmp
   39 
   40   ANS(checkbox_cmp($correctAnswer))
   41 
   42 $correctAnswer is a string containing the names of the correct boxes, e.g.
   43 "ACD". Note that this means that individual checkbox names can only be one
   44 character. Internally, this is largely the same as unordered_cs_str_cmp().
   45 
   46 =cut
   47 
   48 # added 6/14/2000 by David Etlinger
   49 # because of the conversion of the answer
   50 # string to an array, I thought it better not
   51 # to force STR_CMP() to work with this
   52 
   53 #added 2/26/2003 by Mike Gage
   54 # handled the case where multiple answers are passed as an array reference
   55 # rather than as a \0 delimited string.
   56 sub checkbox_cmp {
   57   my  $correctAnswer = shift @_;
   58   my %options = @_;
   59   assign_option_aliases( \%options,
   60      );
   61     set_default_options(  \%options,
   62           'debug'         =>  0,
   63             'type'                  =>  'checkbox_cmp',
   64     );
   65   my $answer_evaluator = new AnswerEvaluator(
   66     correct_ans      => $correctAnswer,
   67     type             => $options{type},
   68   );
   69   # pass along debug requests
   70   $answer_evaluator->{debug} = $options{debug};
   71 
   72   # join student answer array into a single string if necessary
   73   $answer_evaluator->install_pre_filter(sub {
   74     my $rh_ans = shift;
   75     $rh_ans->{_filter_name} = 'convert student_ans to string';
   76     $rh_ans->{student_ans} = join("", @{$rh_ans->{student_ans}})
   77              if ref($rh_ans->{student_ans}) =~/ARRAY/i;
   78     $rh_ans;
   79   });
   80   # ignore order of check boxes
   81   $answer_evaluator->install_pre_filter(\&ignore_order);
   82   # compare as strings
   83   $answer_evaluator->install_evaluator(sub {
   84     my $rh_ans     = shift;
   85     $rh_ans->{_filter_name} = 'compare strings generated by checked boxes';
   86     $rh_ans->{score} = ($rh_ans->{student_ans} eq $rh_ans->{correct_ans}) ? 1 : 0;
   87     $rh_ans;
   88   });
   89   # fix up preview displays
   90   $answer_evaluator->install_post_filter( sub {
   91     my $rh_ans      = shift;
   92     $rh_ans->{_filter_name} = 'adjust preview strings';
   93     $rh_ans->{type} = $options{type};
   94     $rh_ans->{preview_text_string}  = '\\text{'.$rh_ans->{student_ans}.'}',
   95     $rh_ans->{preview_latex_string} = '\\text{'.$rh_ans->{student_ans}.'}',
   96     $rh_ans;
   97 
   98 
   99   });
  100 
  101   return $answer_evaluator;
  102 }
  103 
  104 =head1 radio_cmp
  105 
  106   ANS(radio_cmp($correctAnswer))
  107 
  108 $correctAnswer  is a string containing the name of the correct radio button,
  109 e.g. "Choice1". This is case sensitive and whitespace sensitive, so the correct
  110 answer must match the name of the radio button exactly.
  111 
  112 =cut
  113 
  114 #added 6/28/2000 by David Etlinger
  115 #exactly the same as strict_str_cmp,
  116 #but more intuitive to the user
  117 
  118 # check that answer is really a string and not an array
  119 # also use ordinary string compare
  120 sub radio_cmp {
  121   #strict_str_cmp( @_ );
  122   my $response = shift;  # there should be only one item.
  123   warn "Multiple choices -- this should not happen with radio buttons. Have
  124   you used checkboxes perhaps?" if ref($response); #triggered if an ARRAY is passed
  125   str_cmp($response);
  126 }
  127 
  128 =head1 SEE ALSO
  129 
  130 L<PGanswermacros.pl>, L<MathObjects>.
  131 
  132 =cut
  133 
  134 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9