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

Diff of /trunk/pg/macros/answerCustom.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 4968 Revision 5052
43 # 43 #
44 # Note: If you want a correct answer whose class is a complex variable 44 # Note: If you want a correct answer whose class is a complex variable
45 # to check a real number entry you will have to set both sameClass and 45 # to check a real number entry you will have to set both sameClass and
46 # sameLength to 0 since a complex number has length 2 and a real number 46 # sameLength to 0 since a complex number has length 2 and a real number
47 # has length 1. 47 # has length 1.
48 # 48 #
49 # The checker routine will be passed the correct answer, the 49 # The checker routine will be passed the correct answer, the
50 # student's answer, and the answer evaluator object, in that order. 50 # student's answer, and the answer evaluator object, in that order.
51 # 51 #
52 # For example, the following checks if a student entered 52 # For example, the following checks if a student entered
53 # a unit vector (any unit vector in R^3 will do): 53 # a unit vector (any unit vector in R^3 will do):
70sub custom_cmp { 70sub custom_cmp {
71 my $correct = shift; my $checker = shift; 71 my $correct = shift; my $checker = shift;
72 die "custom_cmp requires a correct answer" unless defined($correct); 72 die "custom_cmp requires a correct answer" unless defined($correct);
73 die "custom_cmp requires a checker subroutine" unless defined($checker); 73 die "custom_cmp requires a checker subroutine" unless defined($checker);
74 $correct = Value::makeValue($correct); 74 $correct = Value::makeValue($correct);
75 $correct = main::Formula($correct) unless Value::isValue($correct); 75 $correct = Value->Package("Formula")->new($correct) unless Value::isValue($correct);
76 $correct->cmp( 76 $correct->cmp(
77 checker => sub { 77 checker => sub {
78 my ($correct,$student,$ans) = @_; 78 my ($correct,$student,$ans) = @_;
79 return 0 if $ans->{sameClass} && $correct->class ne $student->class; 79 return 0 if $ans->{sameClass} && $correct->class ne $student->class;
80 return 0 if $ans->{sameLength} && $correct->length != $student->length; 80 return 0 if $ans->{sameLength} && $correct->length != $student->length;
137sub custom_list_cmp { 137sub custom_list_cmp {
138 my $correct = shift; my $checker = shift; 138 my $correct = shift; my $checker = shift;
139 die "custom_list_cmp requires a correct answer" unless defined($correct); 139 die "custom_list_cmp requires a correct answer" unless defined($correct);
140 die "custom_list_cmp requires a checker subroutine" unless defined($checker); 140 die "custom_list_cmp requires a checker subroutine" unless defined($checker);
141 $correct = Value::makeValue($correct); 141 $correct = Value::makeValue($correct);
142 $correct = main::Formula($correct) unless Value::isValue($correct); 142 $correct = Value->Package("Formula")->new($correct) unless Value::isValue($correct);
143 $correct->cmp( 143 $correct->cmp(
144 list_checker => $checker, 144 list_checker => $checker,
145 @custom_list_cmp_defaults, 145 @custom_list_cmp_defaults,
146 @_, 146 @_,
147 ); 147 );

Legend:
Removed from v.4968  
changed lines
  Added in v.5052

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9