--- loncom/homework/default_homework.lcpm 2005/08/02 18:47:24 1.102 +++ loncom/homework/default_homework.lcpm 2005/12/20 20:00:42 1.106 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run() # -# $Id: default_homework.lcpm,v 1.102 2005/08/02 18:47:24 albertel Exp $ +# $Id: default_homework.lcpm,v 1.106 2005/12/20 20:00:42 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -182,23 +182,24 @@ sub caparesponse_check { sub caparesponse_check_list { my $response=$LONCAPA::CAPAresponse_args{'response'}; - my ($result,@list); - @list=@LONCAPA::CAPAresponse_answer; - my $aresult=''; - my $current_answer; - my $answers=join(':',@list); - $result.="Got response :$answers:\n"; - &LONCAPA_INTERNAL_DEBUG("Yo! got ".join(':',%LONCAPA::CAPAresponse_args)); + my $result="Got response :".join(':',@LONCAPA::CAPAresponse_answer).":\n"; + &LONCAPA_INTERNAL_DEBUG("args ".join(':',%LONCAPA::CAPAresponse_args)); my @responselist; my $type = $LONCAPA::CAPAresponse_args{'type'}; $result.="Got type :$type:\n"; - if ($type ne '' && $#list > 0) { - (@responselist)=split /,/,$response; + if ($type ne '' && $#LONCAPA::CAPAresponse_answer > 0) { + (@responselist)=split(/,/,$response); + if (@responselist < @LONCAPA::CAPAresponse_answer) { + return 'MISSING_ANSWER'; + } + if (@responselist > @LONCAPA::CAPAresponse_answer) { + return 'EXTRA_ANSWER'; + } } else { (@responselist)=($response); } - my $unit=''; $result.="Initial final response :$responselist['-1']:\n"; + my $unit; if ($type eq '' || $type eq 'float') { #for numerical problems split off the unit if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) { @@ -207,28 +208,32 @@ sub caparesponse_check_list { } } $result.="Final final response :$responselist['-1']:$unit:\n"; - $result.=":$#list: answers\n"; $unit=~s/\s//; - my $i=0; - my $awards=''; - my @msgs; - for ($i=0; $i<@list;$i++) { - my $msg; - $result.="trying answer :$list[$i]:\n"; - my $thisanswer=$list[$i]; + + my ($awards, @msgs, $i); + foreach my $thisanswer (@LONCAPA::CAPAresponse_answer) { + my ($msg,$aresult); $result.="trying answer :$thisanswer:\n"; - if ($unit eq '') { - ($aresult,$msg)=&caparesponse_check($thisanswer,$responselist[$i]); + if (defined($thisanswer)) { + if ($unit eq '') { + ($aresult,$msg)=&caparesponse_check($thisanswer, + $responselist[$i]); + } else { + ($aresult,$msg)=&caparesponse_check($thisanswer, + $responselist[$i]." $unit"); + } } else { - ($aresult,$msg)=&caparesponse_check($thisanswer, - $responselist[$i]." $unit"); + $aresult='ERROR'; + $msg='answer was undefined'; } - my ($temp)=split /:/, $aresult; + &LONCAPA_INTERNAL_DEBUG("after if $aresult -- $msg"); + my ($temp)=split(/:/, $aresult); $awards.="$temp,"; $result.=$aresult; push(@msgs,$msg); + $i++; } - chop $awards; + chop($awards); return ("$awards:\n$result",@msgs); } @@ -451,14 +456,14 @@ sub random_negative_binomial { return @retArray; } -sub abs { abs(shift) } -sub sin { sin(shift) } -sub cos { cos(shift) } -sub exp { exp(shift) } -sub int { int(shift) } -sub log { log(shift) } -sub atan2 { atan2($_[0],$_[1]) } -sub sqrt { sqrt(shift) } +sub abs { CORE::abs(shift) } +sub sin { CORE::sin(shift) } +sub cos { CORE::cos(shift) } +sub exp { CORE::exp(shift) } +sub int { CORE::int(shift) } +sub log { CORE::log(shift) } +sub atan2 { CORE::atan2($_[0],$_[1]) } +sub sqrt { CORE::sqrt(shift) } sub tan { CORE::sin($_[0]) / CORE::cos($_[0]) } #sub atan { atan2($_[0], 1); }