1 | sub _answerHints_init {} |
1 | sub _answerHints_init {} |
2 | |
2 | |
3 | =head1 AnswerHints |
3 | =head1 AnswerHints() |
4 | |
4 | |
5 | # This is an answer-checker post-filter that allows you to produce |
5 | # This is an answer-checker post-filter that allows you to produce |
6 | # additional error messages for incorrect answers. You can trigger |
6 | # additional error messages for incorrect answers. You can trigger |
7 | # a message for a single answer, a collection of answers, or via a |
7 | # a message for a single answer, a collection of answers, or via a |
8 | # subroutine that determines the condition for the message. |
8 | # subroutine that determines the condition for the message. |
9 | # |
9 | # |
10 | # Note that this filter only works for MathObjects answer checkers. |
10 | # Note that this filter only works for MathObjects answer checkers. |
11 | # |
11 | # |
12 | # The answer hints are given as a pair using => with the right-hand |
12 | # The answer hints are given as a pair using => with the right-hand |
13 | # side being the answer message and the left-hand side being one of |
13 | # side being the answer message and the left-hand side being one of |
14 | # three possibilities: 1) the value that triggers the message, |
14 | # three possibilities: 1) the value that triggers the message, |
15 | # 2) a reference to an array of values that trigger the message, or |
15 | # 2) a reference to an array of values that trigger the message, or |
16 | # 3) a code reference to a subtroutine that accepts tthe correct |
16 | # 3) a code reference to a subtroutine that accepts tthe correct |
17 | # answer, the student's answer, and the answer hash, and returns |
17 | # answer, the student's answer, and the answer hash, and returns |
18 | # 1 or 0 depending on whether the message should or should not be |
18 | # 1 or 0 depending on whether the message should or should not be |
19 | # displayed. (See the examples below.) |
19 | # displayed. (See the examples below.) |
20 | # |
20 | # |
21 | # The right-hand side can be either the message string itself, or |
21 | # The right-hand side can be either the message string itself, or |
22 | # a referrence to an array where the first element is the message |
22 | # a referrence to an array where the first element is the message |
23 | # string, and the remaining elements are name-value pairs that |
23 | # string, and the remaining elements are name-value pairs that |
24 | # set options for the message. These can include: |
24 | # set options for the message. These can include: |
25 | # |
25 | # |
26 | # checkCorrect => 0 or 1 1 means check for messages even |
26 | # checkCorrect => 0 or 1 1 means check for messages even |
27 | # if the answer is correct. |
27 | # if the answer is correct. |
28 | # Default: 0 |
28 | # Default: 0 |
29 | # |
29 | # |
30 | # replaceMessage => 0 or 1 1 means it's OK to repalce any |
30 | # replaceMessage => 0 or 1 1 means it's OK to repalce any |
31 | # message that is already in place |
31 | # message that is already in place |
32 | # in the answer hash. |
32 | # in the answer hash. |
33 | # Default: 0 |
33 | # Default: 0 |
34 | # |
34 | # |
35 | # checkTypes => 0 or 1 1 means only perform the test |
35 | # checkTypes => 0 or 1 1 means only perform the test |
36 | # if the student answer is the |
36 | # if the student answer is the |
37 | # same type as the correct one. |
37 | # same type as the correct one. |
38 | # Default: 1 |
38 | # Default: 1 |
39 | # |
39 | # |
40 | # score => number Specifies the score to use if |
40 | # score => number Specifies the score to use if |
41 | # the message is triggered (so that |
41 | # the message is triggered (so that |
42 | # partial credit can be given). |
42 | # partial credit can be given). |
43 | # Default: keep original score |
43 | # Default: keep original score |
44 | # |
44 | # |
45 | # cmp_options => [...] provides options for the cmp routine |
45 | # cmp_options => [...] provides options for the cmp routine |
46 | # used to check if the student answer |
46 | # used to check if the student answer |
47 | # matches these answers. |
47 | # matches these answers. |
48 | # Default: [] |
48 | # Default: [] |
49 | # |
49 | # |
50 | # If more than one message matches the student's answer, the first |
50 | # If more than one message matches the student's answer, the first |
51 | # one in the list is used. |
51 | # one in the list is used. |
52 | # |
52 | # |
53 | # Example: |
53 | # Example: |
54 | # |
54 | # |
55 | # ANS(Vector(1,2,3)->cmp(showCoordinateHints=>0)->withPostFilter(AnswerHints( |
55 | # ANS(Vector(1,2,3)->cmp(showCoordinateHints=>0)->withPostFilter(AnswerHints( |
56 | # Vector(0,0,0) => "The zero vector is not a valid solution", |
56 | # Vector(0,0,0) => "The zero vector is not a valid solution", |
57 | # "-<1,2,3>" => "Try the opposite direction", |
57 | # "-<1,2,3>" => "Try the opposite direction", |
58 | # "<1,2,3>" => "Well done!", |
58 | # "<1,2,3>" => "Well done!", |
59 | # ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", |
59 | # ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", |
60 | # sub { |
60 | # sub { |
61 | # my ($correct,$student,$ans) = @_; |
61 | # my ($correct,$student,$ans) = @_; |
62 | # return $correct . $student == 0; |
62 | # return $correct . $student == 0; |
63 | # } => "Your answer is perpendicular to the correct one", |
63 | # } => "Your answer is perpendicular to the correct one", |
64 | # Vector(1,2,3) => [ |
64 | # Vector(1,2,3) => [ |
65 | # "You have the right direction, but not length", |
65 | # "You have the right direction, but not length", |
66 | # cmp_options => [parallel=>1], |
66 | # cmp_options => [parallel=>1], |
67 | # ], |
67 | # ], |
68 | # 0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], |
68 | # 0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], |
69 | # sub { |
69 | # sub { |
70 | # my ($correct,$student,$ans) = @_; |
70 | # my ($correct,$student,$ans) = @_; |
71 | # return norm($correct-$student) < .1; |
71 | # return norm($correct-$student) < .1; |
72 | # } => ["Close! Keep trying.", score => .25], |
72 | # } => ["Close! Keep trying.", score => .25], |
73 | # ))); |
73 | # ))); |
74 | # |
74 | # |
75 | |
75 | |
76 | =cut |
76 | =cut |
77 | |
77 | |
78 | sub AnswerHints { |
78 | sub AnswerHints { |
79 | return (sub { |
79 | return (sub { |