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,62 +31,55 @@ =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
+ DOCUMENT();
53
54
54
- loadMacros(
55
- "PG.pl",
56
- "PGbasicmacros.pl",
57
- "PGanswermacros.pl",
58
- "Parser.pl",
59
- "Generic.pl",
60
- );
55
+ loadMacros("PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "Generic.pl");
61
56
62
- TEXT(&beginproblem);
57
+ Context("Vector");
58
+ $A=Vector(1,2,1);
59
+ $B=Vector(1,3,1);
60
+ $C=Vector(1,4,1);
63
61
64
- Context("Vector");
65
- $A=Vector(1,2,1);
66
- $B=Vector(1,3,1);
67
- $C=Vector(1,4,1);
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
68
67
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
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
+ }
74
73
75
- #Easy to get by guessing!
76
-
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
- }
74
+ ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));
82
75
83
- ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check) );
76
+ ENDDOCUMENT( );
84
77
85
- ENDDOCUMENT(); # This should be the last executable line in the problem.
86
-
87
- ####################End of Example########################
78
+ =head1 MACROS
88
79
89
80
=cut
90
81
91
- # End of Documentation
82
+ sub _Generic_init { } # don't reload this file.
92
83
93
84
# From parserUtils.pl:
94
85
sub protectHTML {
@@ -100,6 +91,10 @@ sub protectHTML {
100
91
101
92
}
102
93
94
+ =head2 generic_cmp
95
+
96
+ =cut
97
+
103
98
sub generic_cmp {
104
99
my $v = shift ;
105
100
my %opts = @_ ;
@@ -120,6 +115,10 @@ sub generic_cmp {
120
115
return $ans ;
121
116
}
122
117
118
+ =head2 generic_cmp_check
119
+
120
+ =cut
121
+
123
122
sub generic_cmp_check {
124
123
my $ans = shift ;
125
124
my $type = $ans -> {type };
0 commit comments