| … | |
… | |
| 77 | # |
77 | # |
| 78 | # Check if the parsed student answer equals the professor's answer |
78 | # Check if the parsed student answer equals the professor's answer |
| 79 | # |
79 | # |
| 80 | sub cmp_equal { |
80 | sub cmp_equal { |
| 81 | my $self = shift; my $ans = shift; |
81 | my $self = shift; my $ans = shift; |
| 82 | my $v = $ans->{correct_value}; |
82 | if ($ans->{correct_value}->typeMatch($ans->{student_value},$ans)) { |
| 83 | my $V = $ans->{student_value}; |
83 | my $equal = eval {$ans->{correct_value} == $ans->{student_value}}; |
| 84 | if ($v->typeMatch($V,$ans)) { |
|
|
| 85 | my $equal = eval {$v == $V}; # let the overloaded == do the check |
|
|
| 86 | if (defined($equal) || !$ans->{showEqualErrors}) {$ans->score(1) if $equal; return} |
84 | if (defined($equal) || !$ans->{showEqualErrors}) {$ans->score(1) if $equal; return} |
| 87 | my $cmp_error = $ans->{cmp_error} || 'cmp_error'; |
85 | my $cmp_error = $ans->{cmp_error} || 'cmp_error'; |
| 88 | $self->$cmp_error($ans); |
86 | $self->$cmp_error($ans); |
| 89 | } else { |
87 | } else { |
| 90 | $ans->{ans_message} = $ans->{error_message} = |
88 | $ans->{ans_message} = $ans->{error_message} = |
| 91 | "Your answer isn't ".$v->showClass." (it looks like ".$V->showClass.")" |
89 | "Your answer isn't ".$ans->{correct_value}->showClass. |
|
|
90 | " (it looks like ".$ans->{student_value}->showClass.")" |
| 92 | if !$ans->{isPreview} && $ans->{showTypeWarnings} && !$ans->{error_message}; |
91 | if !$ans->{isPreview} && $ans->{showTypeWarnings} && !$ans->{error_message}; |
| 93 | } |
92 | } |
| 94 | } |
93 | } |
| 95 | |
94 | |
| 96 | # |
95 | # |
| … | |
… | |
| 134 | $string =~ s/>/\>/g; |
133 | $string =~ s/>/\>/g; |
| 135 | $string; |
134 | $string; |
| 136 | } |
135 | } |
| 137 | |
136 | |
| 138 | ############################################################# |
137 | ############################################################# |
|
|
138 | ############################################################# |
|
|
139 | |
|
|
140 | package Value::Real; |
|
|
141 | |
|
|
142 | sub typeMatch { |
|
|
143 | my $self = shift; my $other = shift; my $ans = shift; |
|
|
144 | if ($other->type eq 'String') { |
|
|
145 | $ans->{showEqualErrors} = 0; |
|
|
146 | return 1; |
|
|
147 | } |
|
|
148 | $self->type eq $other->type; |
|
|
149 | } |
|
|
150 | |
| 139 | ############################################################# |
151 | ############################################################# |
| 140 | |
152 | |
| 141 | package Value::List; |
153 | package Value::List; |
| 142 | |
154 | |
| 143 | # |
155 | # |