[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /homework/caparesponse caparesponse.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 10 Nov 2006 17:47:42 -0000
albertel Fri Nov 10 12:47:42 2006 EDT
Modified files:
/loncom/homework default_homework.lcpm
/loncom/homework/caparesponse caparesponse.pm
Log:
- check for and error when there are
- different numbers of answers
- incorrect number of input fields
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.119 loncom/homework/default_homework.lcpm:1.120
--- loncom/homework/default_homework.lcpm:1.119 Wed Nov 1 18:24:52 2006
+++ loncom/homework/default_homework.lcpm Fri Nov 10 12:45:52 2006
@@ -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.119 2006/11/01 23:24:52 albertel Exp $
+# $Id: default_homework.lcpm,v 1.120 2006/11/10 17:45:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -303,8 +303,8 @@
my $num_input_lines =
scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}});
- if ($type ne ''
- && $num_input_lines > 1) {
+
+ if ($type ne '' ) {
if (scalar(@$responses) < $num_input_lines) {
return 'MISSING_ANSWER';
}
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.195 loncom/homework/caparesponse/caparesponse.pm:1.196
--- loncom/homework/caparesponse/caparesponse.pm:1.195 Wed Nov 1 18:24:52 2006
+++ loncom/homework/caparesponse/caparesponse.pm Fri Nov 10 12:47:41 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.195 2006/11/01 23:24:52 albertel Exp $
+# $Id: caparesponse.pm,v 1.196 2006/11/10 17:47:41 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -431,6 +431,7 @@
}
}
} elsif ($target eq 'web' || $target eq 'tex') {
+ &check_for_answer_errors($parstack,$safeeval);
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
my $status = $Apache::inputtags::status['-1'];
if ($Apache::lonhomework::type eq 'exam') {
@@ -672,10 +673,36 @@
$target eq 'tex' || $target eq 'analyze') {
&Apache::lonxml::increment_counter($increment);
}
- &Apache::response::end_response;
+ &Apache::response::end_response();
return $result;
}
+sub check_for_answer_errors {
+ my ($parstack,$safeeval) = @_;
+ &add_in_tag_answer($parstack,$safeeval);
+ my %counts;
+ foreach my $name (keys(%answer)) {
+ push(@{$counts{scalar(@{$answer{$name}{'answers'}})}},$name);
+ }
+ if (scalar(keys(%counts)) > 1) {
+ my $counts = join(' ',map {
+ my $count = $_;
+ &mt("Answers [_1] had [_2] components.",
+ '<tt>'.join(', ',@{$counts{$count}}).'</tt>',
+ $count);
+ } (sort(keys(%counts))));
+ &Apache::lonxml::error(&mt("All answers must have the same number of components. Varying numbers of answers were seen. ").$counts);
+ }
+ use Data::Dumper;
+ &Apache::lonxml::debug("count dump is ".&Dumper(\%counts));
+ my $expected_number_of_inputs = (keys(%counts))[0];
+ if ( $expected_number_of_inputs != scalar(@Apache::inputtags::inputlist)) {
+ &Apache::lonxml::error(&mt("Expected [_1] input fields, but there were only [_2] seen.",
+ $expected_number_of_inputs,
+ scalar(@Apache::inputtags::inputlist)));
+ }
+}
+
sub get_table_sizes {
my ($number_of_bubbles,$rbubble_values)=@_;
my $scale=2; #mm for one digit