[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 5550 Revision 5551
1=head1 NAME
2
3answerCustom.pl - An easy method for creating answer checkers with a custom
4subroutine that performs the check for correctness.
5
6=cut
7
1loadMacros('MathObjects.pl'); 8loadMacros('MathObjects.pl');
2 9
3sub _answerCustom_init {}; # don't reload this file 10sub _answerCustom_init {}; # don't reload this file
4 11
5=head3 custom response evaluator 12=head1 MACROS
6 13
7 ###################################################################### 14=head2 custom_cmp
8 # 15
16 ANS(custom_cmp($correct_ans, $ans_checker, %options))
17
9 # This answer checker provides an easy method for creating an answer 18This answer checker provides an easy method for creating an answer
10 # checker with a custom subroutine that performs the check for 19checker with a custom subroutine that performs the check for
11 # correctness. 20correctness.
12 # 21
13 # Pass the correct answer (either as a string or as a Parser object) 22Pass the correct answer (either as a string or as a Parser object)
14 # as the first argument, and a reference to the checker subroutine 23as the first argument, and a reference to the checker subroutine
15 # as the second argument. Additional parameters can follow. These 24as the second argument. Additional parameters can follow. These
16 # include any of the parameters for the usual answer checker of the 25include any of the parameters for the usual answer checker of the
17 # of the type of the correct answer (e.g., showCoordinateHints), plus 26of the type of the correct answer (e.g., showCoordinateHints), plus
18 # the following: 27the following:
19 # 28
20 # sameClass => 0 or 1 If 1 (the default), only call the 29=over
21 # custom checker if the student answer 30
22 # is the same object class as the correct 31=item S<C<< sameClass => 0 or 1 >>>
23 # answer (e.g., both are points). 32
24 # If 0, the checker will be called 33If 1 (the default), only call the
25 # whenever the student answer passes 34custom checker if the student answer
26 # the typeMatch check for the correct 35is the same object class as the correct
27 # answer. For example, if the correct 36answer (e.g., both are points).
28 # answer is a vector, and promotePoints 37If 0, the checker will be called
29 # has been set to 1, then the checker 38whenever the student answer passes
30 # will be called when the student answer 39the typeMatch check for the correct
31 # is a vector OR a point. 40answer. For example, if the correct
32 # 41answer is a vector, and promotePoints
33 # sameLength => 0 or 1 If 1 (the default), only call the 42has been set to 1, then the checker
34 # custom checker if the student answer 43will be called when the student answer
35 # has the same number of coordinates as 44is a vector OR a point.
36 # the correct answer. 45
37 # 46=item S<C<< sameLength => 0 or 1 >>>
47
48If 1 (the default), only call the
49custom checker if the student answer
50has the same number of coordinates as
51the correct answer.
52
53=back
54
38 # If the correct answer is a list, the custom checker will be called 55If the correct answer is a list, the custom checker will be called
39 # on the individual entries of the list, not on the list as a whole. 56on the individual entries of the list, not on the list as a whole.
40 # If the list is an unordered list, the routine may be called 57If the list is an unordered list, the routine may be called
41 # multiple times with various combinations of student and professor's 58multiple times with various combinations of student and professor's
42 # answers in order to find a correct match. 59answers in order to find a correct match.
43 # 60
44 # Note: If you want a correct answer whose class is a complex variable 61Note: 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 62to 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 63sameLength to 0 since a complex number has length 2 and a real number
47 # has length 1. 64has length 1.
48 # 65
49 # The checker routine will be passed the correct answer, the 66The checker routine will be passed the correct answer, the
50 # student's answer, and the answer evaluator object, in that order. 67student's answer, and the answer evaluator object, in that order.
51 # 68
52 # For example, the following checks if a student entered 69For example, the following checks if a student entered
53 # a unit vector (any unit vector in R^3 will do): 70a unit vector (any unit vector in R^3 will do):
54 # 71
55 # ANS(custom_cmp("<1,0,0>",sub { 72 ANS(custom_cmp("<1,0,0>",sub {
56 # my ($correct,$student,$ans) = @_; 73 my ($correct,$student,$ans) = @_;
57 # return norm($student) == 1; 74 return norm($student) == 1;
58 # },showCoordinateHints => 0)); 75 },showCoordinateHints => 0));
59 # 76
60 # The checker subroutine can call Value::Error(message) to generate 77The checker subroutine can call Value::Error(message) to generate
61 # an error message that will be reported in the table at the top of 78an error message that will be reported in the table at the top of
62 # the page. If the checker generates a fatal runtime error (e.g., 79the page. If the checker generates a fatal runtime error (e.g.,
63 # calls the "die" function), then the message is reported with the 80calls the "die" function), then the message is reported with the
64 # "pink screen of death", and includes a request for the student to 81"pink screen of death", and includes a request for the student to
65 # inform the instructor. 82inform the instructor.
66 #
67 83
68=cut 84=cut
69 85
70sub custom_cmp { 86sub custom_cmp {
71 my $correct = shift; my $checker = shift; 87 my $correct = shift; my $checker = shift;
93# Set this to include any default parameters you want 109# Set this to include any default parameters you want
94# to include in the custom answer checkers 110# to include in the custom answer checkers
95# 111#
96@custom_cmp_defaults = (); 112@custom_cmp_defaults = ();
97 113
98=head3 a custom list evaluator 114=head2 custom_list_cmp
99 115
100 # 116 ANS(custom_list_cmp($correct_ans, $ans_checker, %options))
117
101 # This one installs a custom list-based answer checker (for the 118This one installs a custom list-based answer checker (for the
102 # List and Union classes). Basically it is just a shell that makes 119List and Union classes). Basically it is just a shell that makes
103 # it a little easier to do, and provides an interface similar to 120it a little easier to do, and provides an interface similar to
104 # custom_cmp. 121custom_cmp.
105 # 122
106 # You pass the correct answer (as a string or as a List or Union 123You pass the correct answer (as a string or as a List or Union
107 # object) as the first argument, and the custom list checker as 124object) as the first argument, and the custom list checker as
108 # the second argument. You can pass any additional parameters 125the second argument. You can pass any additional parameters
109 # that should be included in the answer checker following those 126that should be included in the answer checker following those
110 # two required ones. 127two required ones.
111 # 128
112 # The checker will be passed a reference to the array of correct 129The checker will be passed a reference to the array of correct
113 # answers, a reference to the array of student answers, and 130answers, a reference to the array of student answers, and
114 # the answer evaluator object. Note that the correct and student 131the answer evaluator object. Note that the correct and student
115 # answers are array references, not List structures (this is because 132answers are array references, not List structures (this is because
116 # a list of formulas becomes a formula returning a list, so in order 133a list of formulas becomes a formula returning a list, so in order
117 # to keep the formulas separate, they are passed in an array). 134to keep the formulas separate, they are passed in an array).
118 # 135
119 # The checker should return the number of list entries that were 136The checker should return the number of list entries that were
120 # matched by the students answers. (I.e., a number between 0 137matched by the students answers. (I.e., a number between 0
121 # and the length of the list.) 138and the length of the list.)
122 # 139
123 # For example, the following checks for any list of the same length 140For example, the following checks for any list of the same length
124 # as the instructor's list. (A stupid checker, but just an example.) 141as the instructor's list. (A stupid checker, but just an example.)
125 # 142
126 # ANS(custom_list_cmp("1,2,3",sub { 143 ANS(custom_list_cmp("1,2,3",sub {
127 # my ($correct,$student,$ans) = @_; 144 my ($correct,$student,$ans) = @_;
128 # (scalar(@{$correct}) == scalar(@{$student}) ? 3 : 0); 145 (scalar(@{$correct}) == scalar(@{$student}) ? 3 : 0);
129 # })); 146 }));
130 # 147
131 # The checker subroutine can call Value::Error(message) to generate 148The checker subroutine can call Value::Error(message) to generate
132 # an error message that will be reported in the table at the top of 149an error message that will be reported in the table at the top of
133 # the page. If the checker generates a fatal runtime error (e.g., 150the page. If the checker generates a fatal runtime error (e.g.,
134 # calls the "die" function), then the message is reported with the 151calls the "die" function), then the message is reported with the
135 # "pink screen of death", and includes a request for the student to 152"pink screen of death", and includes a request for the student to
136 # inform the instructor. 153inform the instructor.
137 #
138 154
139=cut 155=cut
140 156
141sub custom_list_cmp { 157sub custom_list_cmp {
142 my $correct = shift; my $checker = shift; 158 my $correct = shift; my $checker = shift;
154# 170#
155# Set this to include any default parameters you want 171# Set this to include any default parameters you want
156# to include in the custom answer checkers 172# to include in the custom answer checkers
157# 173#
158@custom_list_cmp_defaults = (); 174@custom_list_cmp_defaults = ();
175

Legend:
Removed from v.5550  
changed lines
  Added in v.5551

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9