| … | |
… | |
| 825 | |
825 | |
| 826 | |
826 | |
| 827 | sub check_units { |
827 | sub check_units { |
| 828 | my ($rh_ans, %options) = @_; |
828 | my ($rh_ans, %options) = @_; |
| 829 | |
829 | |
|
|
830 | |
| 830 | my %correct_units = %{$rh_ans-> {rh_correct_units}}; |
831 | my %correct_units = %{$rh_ans-> {rh_correct_units}}; |
| 831 | |
832 | |
| 832 | my $ans = $rh_ans->{student_ans}; |
833 | my $ans = $rh_ans->{student_ans}; |
| 833 | # $ans = '' unless defined ($ans); |
834 | # $ans = '' unless defined ($ans); |
| 834 | $ans = str_filters ($ans, 'trim_whitespace'); |
835 | $ans = str_filters ($ans, 'trim_whitespace'); |
| … | |
… | |
| 861 | my %units = Units::evaluate_units($units); |
862 | my %units = Units::evaluate_units($units); |
| 862 | if ( defined( $units{'ERROR'} ) ) { |
863 | if ( defined( $units{'ERROR'} ) ) { |
| 863 | # handle error condition |
864 | # handle error condition |
| 864 | $units{'ERROR'} = clean_up_error_msg($units{'ERROR'}); |
865 | $units{'ERROR'} = clean_up_error_msg($units{'ERROR'}); |
| 865 | $rh_ans -> setKeys( 'ans_message' => "$units{'ERROR'}" ); |
866 | $rh_ans -> setKeys( 'ans_message' => "$units{'ERROR'}" ); |
|
|
867 | $rh_ans -> throw_error('UNITS', "$units{'ERROR'}"); |
| 866 | return $rh_ans; |
868 | return $rh_ans; |
| 867 | } |
869 | } |
| 868 | |
870 | |
| 869 | my $units_match = 1; |
871 | my $units_match = 1; |
| 870 | my $fund_unit; |
872 | my $fund_unit; |
| … | |
… | |
| 900 | |
902 | |
| 901 | # it surprises me that the match below works since the first .* is greedy. |
903 | # it surprises me that the match below works since the first .* is greedy. |
| 902 | my ($correct_num_answer, $correct_units) = $correct_answer =~ /^(.*)\s+([^\s]*)$/; |
904 | my ($correct_num_answer, $correct_units) = $correct_answer =~ /^(.*)\s+([^\s]*)$/; |
| 903 | |
905 | |
| 904 | $options{units} = $correct_units; |
906 | $options{units} = $correct_units; |
| 905 | |
|
|
| 906 | |
907 | |
| 907 | num_cmp($correct_num_answer, %options); |
908 | num_cmp($correct_num_answer, %options); |
| 908 | } |
909 | } |
| 909 | |
910 | |
| 910 | |
911 | |
| … | |
… | |
| 1439 | } |
1440 | } |
| 1440 | if (defined($num_params{strings}) && $num_params{strings}) { |
1441 | if (defined($num_params{strings}) && $num_params{strings}) { |
| 1441 | $answer_evaluator->install_pre_filter(\&check_strings, %num_params); |
1442 | $answer_evaluator->install_pre_filter(\&check_strings, %num_params); |
| 1442 | } |
1443 | } |
| 1443 | |
1444 | |
| 1444 | |
|
|
| 1445 | $answer_evaluator->install_pre_filter(\&check_syntax); |
1445 | $answer_evaluator->install_pre_filter(\&check_syntax); |
| 1446 | |
1446 | |
| 1447 | $answer_evaluator->install_pre_filter(\&math_constants); |
1447 | $answer_evaluator->install_pre_filter(\&math_constants); |
| 1448 | |
1448 | |
| 1449 | |
1449 | |
| 1450 | |
1450 | |
|
|
1451 | |
| 1451 | if ($mode eq 'std') { |
1452 | if ($mode eq 'std') { |
| 1452 | # do nothing |
1453 | # do nothing |
| 1453 | } elsif ($mode eq 'strict') { |
1454 | } elsif ($mode eq 'strict') { |
| 1454 | $answer_evaluator->install_pre_filter(\&is_a_number); |
1455 | $answer_evaluator->install_pre_filter(\&is_a_number); |
| 1455 | } elsif ($mode eq 'arith') { |
1456 | } elsif ($mode eq 'arith') { |
| … | |
… | |
| 1459 | |
1460 | |
| 1460 | } else { |
1461 | } else { |
| 1461 | $PGanswerMessage = 'Tell your professor that there is an error in his or her answer mechanism. No mode was specified.'; |
1462 | $PGanswerMessage = 'Tell your professor that there is an error in his or her answer mechanism. No mode was specified.'; |
| 1462 | $formattedSubmittedAnswer = $in; |
1463 | $formattedSubmittedAnswer = $in; |
| 1463 | } |
1464 | } |
| 1464 | |
1465 | |
| 1465 | if ($corrAnswerIsString == 0 ){ # avoiding running compare_numbers when correct answer is a string. |
1466 | if ($corrAnswerIsString == 0 ){ # avoiding running compare_numbers when correct answer is a string. |
| 1466 | $answer_evaluator->install_evaluator(\&compare_numbers, %num_params); |
1467 | $answer_evaluator->install_evaluator(\&compare_numbers, %num_params); |
| 1467 | } |
1468 | } |
| 1468 | ############################################################################### |
1469 | ############################################################################### |
| 1469 | # We'll leave these next lines out for now, so that the evaluated versions of the student's and professor's |
1470 | # We'll leave these next lines out for now, so that the evaluated versions of the student's and professor's |