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

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9