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

View of /trunk/webwork/system/courseScripts/PG_CAPAmacros.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (download) (as text) (annotate)
Mon Jun 18 15:21:51 2001 UTC (11 years, 11 months ago) by sam
File size: 4838 byte(s)
another setup script test (changed #! lines)

    1 #!/usr/local/bin/webwork-perl
    2 
    3 BEGIN {
    4   be_strict();
    5 }
    6 
    7 
    8 sub CAPA_ans {
    9   my $ans = shift;
   10   my %options = @_;
   11   my $answer_evaluator = 0;
   12 
   13     #TEXT("answerCounter =". ++$problemCounter,"$BR"); # checking whether values are reinitialized
   14   if (defined($options{'reltol'}) or defined($options{'tol'}) or defined($options{'unit'})  ) {
   15 
   16     if (defined( $options{'unit'} ) ) {
   17       $ans = "$ans  $options{'unit'}";
   18       $answer_evaluator = numerical_compare_with_units($ans, %options);
   19     } else { # numerical compare:
   20       if (defined($options{'reltol'})  ) {  #relative tolerance is given with a percent sign
   21               my $reltol =  $options{ 'reltol' };
   22               my $format = $options{'format'} if defined($options{'format'});
   23           $answer_evaluator = std_num_cmp($ans,$reltol,$format);
   24       } elsif (defined($options{'tol'})  ) {
   25             my $format = $options{'format'} if defined($options{'format'});
   26           $answer_evaluator = std_num_cmp_abs($ans,$options{'tol'},$format);
   27         } else {
   28              my $tol = $ans*$main::numRelPercentTolDefault;
   29              my $format = $options{'format'} if defined($options{'format'});
   30              $answer_evaluator = std_num_cmp_abs($ans,$tol,$format);
   31         }
   32     }
   33   } else {
   34      # string comparisons
   35      if ( defined($options{'str'})  and   $options{'str'} =~/CS/i )  {
   36             $answer_evaluator =std_cs_str_cmp($ans);
   37      } elsif  ( defined($options{'str'}) and $options{'str'} =~/MC/i )  {
   38               $answer_evaluator = unordered_str_cmp($ans);
   39      } else {
   40               $answer_evaluator = std_str_cmp($ans);
   41      }
   42   }
   43 
   44    $answer_evaluator;
   45 }
   46 
   47 sub CAPA_import {
   48   my $filePath = shift;
   49   my %save_envir = %main::envir;
   50   my $r_string =  read_whole_problem_file($filePath);
   51 
   52   $main::envir{'probFileName'} = $filePath;
   53   $main::envir{'fileName'} = $filePath;
   54   includePGtext($r_string); # the 0 prevents  a new Safe compartment from being used
   55   %main::envir = %save_envir;
   56 }
   57 
   58 
   59 
   60 sub CAPA_map {
   61   my $seed = shift;
   62     my $array_var_ref = shift;
   63     my $PGrand = new PGrandom($seed);
   64     local $main::array_values_ref = shift;   # this must be local since it must be passed to PG_restricted_eval
   65     my $size = @$main::array_values_ref;  # get number of values
   66   my @array = 0..($size-1);
   67   my @slice = ();
   68   while ( @slice < $size) {
   69     push(@slice, splice(@array , $PGrand->random(0,$#array) , 1) );
   70   }
   71     my $string = "";
   72     my $var;
   73     my $i = 0;
   74      foreach $var (@$array_var_ref) {
   75     $string .= "\$$var = \$\$main::array_values_ref[ $slice[$i++]]; ";
   76    }
   77 
   78      # it is important that PG-restriced eval can accesss the $array_values_ref
   79      my($val, $PG_eval_errors,$PG_full_error_report) =PG_restricted_eval($string);
   80      my $out = '';
   81      $string =~ s/\$/\\\$/g;  # protect variables for error message
   82      $out = "Error in MAP subroutine: $PG_eval_errors <BR>\n" . $string ." <BR>\n" if $PG_eval_errors;
   83      $out;
   84 }
   85 
   86 sub compare_units {
   87 
   88 
   89 }
   90 
   91 sub CAPA_hint {
   92     my $hint = shift;
   93   TEXT(hint(qq{ HINT:   $hint $main::BR}));
   94 }
   95 
   96 sub CAPA_explanation {
   97   TEXT(solution( qq{ $main::BR$main::BR EXPLANATION:   @_ $main::BR$main::BR} )) if solution(@_);
   98 }
   99 
  100 sub pow {
  101     my($base,$exponent)=@_;
  102     $base**$exponent;
  103 }
  104 sub CAPA_tex {
  105     my $tex = shift;
  106    # $tex =~ s|/*|\$|g;
  107     #$tex =~ s/\\/\\\\/g;   #protect backslashes???
  108     my $nontex = shift;
  109     &M3($tex, $nontex,$nontex);
  110 }
  111 sub CAPA_web {
  112   my $text = shift;
  113   my $tex  = shift;
  114   my $html = shift;
  115   &M3($tex,"\\begin{rawhtml}$html\\end{rawhtml}",$html);
  116 }
  117 sub CAPA_html {
  118   my $html = shift;
  119   &M3("","\\begin{rawhtml}$html\\end{rawhtml}",$html);
  120 }
  121 sub var_in_tex {
  122     my($tex)=$_[0];
  123     &M3( "$tex","$tex","");
  124 }
  125 
  126 
  127 
  128 sub isNumberQ {  # determine whether the input is a number
  129   my $in = shift;
  130   $in =~ /^[\d\.\+\-Ee]+$/;
  131 }
  132 
  133 sub choose {
  134    # my($in)=join(" ",@_);
  135     my($var)=$_[0];
  136     $_[$var];
  137 }
  138 
  139 sub problem {
  140   $main::probNum;
  141 }
  142 
  143 sub pin {
  144     $main::psvnNumber;
  145 }
  146 sub section {
  147     $main::sectionNumber;
  148 }
  149 sub name {
  150     $main::studentName;
  151 }
  152 sub set {
  153     $main::setNumber;
  154 }
  155 sub question {
  156     $main::probNum;
  157 }
  158 
  159 sub due_date {
  160   $main::formattedDueDate;
  161  }
  162 
  163 sub answer_date {
  164    $main::formattedAnswerDate;
  165 }
  166 sub open_date {
  167    $main::formattedOpenDate;
  168 }
  169 sub to_string {
  170     $_[0];
  171 }
  172 
  173 
  174 sub CAPA_EV {
  175 
  176    my $out = &EV3(@_);
  177    $out  =~ s/\n\n/\n/g;  # hack to prevent introduction of paragraphs in TeX??
  178    # HACK TO DO THE RIGHT THING WITH DOLLAR SIGNS
  179    $out = ev_substring($out,"/*/*","/*/*",\&display_math_ev3);
  180    $out = ev_substring($out,"/*","/*",\&math_ev3);
  181    # TEXT($main::BR, $main::BR, $out,$main::BR,$main::BR);
  182    $out;
  183 }
  184 
  185 # these are very commonly needed files
  186 CAPA_import("${main::CAPA_Tools}StdMacros");
  187 CAPA_import("${main::CAPA_Tools}StdUnits");
  188 CAPA_import("${main::CAPA_Tools}StdConst");
  189 #####################
  190 
  191 $main::prob_val="";     # gets rid of spurious errors.
  192 $main::prob_try="";
  193 
  194 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9