1
- # R. Byerly, Texas Tech University, 2005
2
1
3
- sub _Generic { } # Don't reload this file.
2
+ =head1 NAME
4
3
5
- # Documentation:
4
+ Generic.pl - provide some generic answer checkers.
6
5
7
- =head1 Generic Answer Checker
6
+ =head1 DESCRIPTION
8
7
9
- (Based on David Cervone's vector_cmp. See
10
- doc/parser/extensions/8-answer.pg under the webwork2 directory.)
11
- Place in macros directory and load this file (Generic.pl) using the
12
- loadMacros command. (To just copy it into a pg file, replace
13
- occurences of "\&" by "~~&".)
8
+ This macro provides a set of functions that provide a generic answer checker.
14
9
15
- Usage:
10
+ Usage:
11
+
12
+ ANS( generic_cmp(<prof_answer>, <optional and mandatory arguments>) );
16
13
17
- ANS( generic_cmp(<prof_answer>, <optional and mandatory arguments>) );
18
14
where <prof_answer> is a parser object or syntactically correct string
19
15
for a parser object.
20
16
21
17
Mandatory arguments:
22
18
23
- type => <type>
19
+ type => <type>
20
+
24
21
where <type> is a recognized parser type (e.g., Number, Point, Vector,
25
22
Matrix, etc.)
26
23
27
- checker => <checker>
24
+ checker => <checker>
25
+
28
26
where <checker> is a reference to a subroutine that will be passed (in
29
27
order) the parsed (and, if possible, evaluated) student answer, the
30
28
parsed professor's answer, and a reference to the answer hash. (The
@@ -33,63 +31,54 @@ =head1 Generic Answer Checker
33
31
34
32
Optional arguments:
35
33
36
- correct_ans => <answer_string>
34
+ correct_ans => <answer_string>
35
+
37
36
where <answer_string> is a string that will show up as the correct
38
37
answer when solutions are available.
39
38
40
- variables_allowed => 0 or 1
39
+ variables_allowed => 0 or 1
40
+
41
41
(default 0 (false). Determines whether student's answer is allowed to
42
42
contain variables. In this case the checker must take care of
43
43
evaluating it.)
44
44
45
- length => n
45
+ length => n
46
+
46
47
where n is the number of elements in an expected answer of type list,
47
48
vector, or points. Returns error message to student if answer of wrong
48
49
length is entered.
49
50
51
+ =head1 SYNOPSIS
50
52
51
- ####################Example:##########################
52
- DOCUMENT(); # This should be the first executable line in the problem.
53
-
54
- loadMacros(
55
- "PG.pl",
56
- "PGbasicmacros.pl",
57
- "PGanswermacros.pl",
58
- "Parser.pl",
59
- "Generic.pl",
60
- );
61
-
62
- TEXT(&beginproblem);
53
+ DOCUMENT();
63
54
64
- Context("Vector");
65
- $A=Vector(1,2,1);
66
- $B=Vector(1,3,1);
67
- $C=Vector(1,4,1);
55
+ loadMacros("PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "Generic.pl");
68
56
69
- BEGIN_TEXT
70
- Show that the vectors \(\{$A->TeX\}, \{$B->TeX\}, \{$C->TeX\}\) do
71
- not span \(R^3\) by giving a vector not in their span:
72
- \{ans_rule()\}
73
- END_TEXT
57
+ Context("Vector");
58
+ $A=Vector(1,2,1);
59
+ $B=Vector(1,3,1);
60
+ $C=Vector(1,4,1);
74
61
75
- #Easy to get by guessing!
62
+ BEGIN_TEXT
63
+ Show that the vectors \(\{$A->TeX\}, \{$B->TeX\}, \{$C->TeX\}\) do
64
+ not span \(R^3\) by giving a vector not in their span:
65
+ \{ans_rule()\}
66
+ END_TEXT
76
67
77
- sub check{
78
- my $stu=shift() ;
79
- $x1=$stu->extract(1); $x3=$stu->extract(3);
80
- $x1 != $x3; #any vectors with different 1st and 3rd coordinates
81
- }
68
+ sub check {
69
+ my $stu=shift;
70
+ $x1=$stu->extract(1); $x3=$stu->extract(3);
71
+ $x1 != $x3; #any vectors with different 1st and 3rd coordinates
72
+ }
82
73
83
- ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));
74
+ ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));
84
75
85
- ENDDOCUMENT(); # This should be the last executable line in the problem.
76
+ ENDDOCUMENT();
86
77
87
- ####################End of Example########################
78
+ =head1 MACROS
88
79
89
80
=cut
90
81
91
- # End of Documentation
92
-
93
82
# From parserUtils.pl:
94
83
sub protectHTML {
95
84
my $string = shift ;
@@ -100,6 +89,10 @@ sub protectHTML {
100
89
101
90
}
102
91
92
+ =head2 generic_cmp
93
+
94
+ =cut
95
+
103
96
sub generic_cmp {
104
97
my $v = shift ;
105
98
my %opts = @_ ;
@@ -120,6 +113,10 @@ sub generic_cmp {
120
113
return $ans ;
121
114
}
122
115
116
+ =head2 generic_cmp_check
117
+
118
+ =cut
119
+
123
120
sub generic_cmp_check {
124
121
my $ans = shift ;
125
122
my $type = $ans -> {type };
0 commit comments