Skip to content

Commit 9fcc7d0

Browse files
dpvcAlex-Jordan
authored andcommitted
fix bugs with answerHints from issue #964
1 parent 09d6126 commit 9fcc7d0

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

macros/answers/answerHints.pl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ sub AnswerHints {
144144
cmp_options => [],
145145
@options,
146146
);
147-
next if $options{checkTypes} && $correct->type ne $student->type;
148147
next if !$options{processPreview} && $ans->{isPreview};
149148
$wrongList = [$wrongList] unless ref($wrongList) eq 'ARRAY';
150149

151150
foreach my $wrong (@{$wrongList}) {
152151
if (ref($wrong) eq 'CODE') {
153-
if (($ans->{score} < 1 || $options{checkCorrect})
152+
if ((!$options{checkTypes} || $correct->type eq $student->type)
153+
&& ($ans->{score} < 1 || $options{checkCorrect})
154154
&& ($ans->{ans_message} eq "" || $options{replaceMessage}))
155155
{
156156
# Make the call to run the function inside an eval to trap errors
@@ -166,16 +166,12 @@ sub AnswerHints {
166166
}
167167
}
168168
} else {
169-
$wrong = Value::makeValue($wrong);
170-
if (
171-
(
172-
$ans->{score} < 1
173-
|| $options{checkCorrect}
174-
|| AnswerHints::Compare($correct, $wrong, $ans)
175-
)
176-
&& ($ans->{ans_message} eq "" || $options{replaceMessage})
177-
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} })
178-
)
169+
unless (Value::isValue($wrong)) {
170+
$wrong = main::Formula($wrong);
171+
$wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute};
172+
}
173+
if (($ans->{ans_message} eq "" || $options{replaceMessage})
174+
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} }))
179175
{
180176
$ans->{ans_message} = $ans->{error_message} = $message;
181177
$ans->{score} = $options{score} if defined $options{score};
@@ -197,13 +193,13 @@ package AnswerHints;
197193
# and returns true if the two values match and false otherwise.
198194
#
199195
sub Compare {
200-
my $self = shift;
201-
my $other = shift;
202-
my $ans = shift;
203-
$ans = bless { %{$ans}, @_ }, ref($ans); # make a copy
196+
my ($self, $other, $ans, @options) = @_;
197+
return 0 unless $self->typeMatch($other); # make sure these can be compared
198+
$ans = bless { %{$ans}, @options }, ref($ans); # make a copy
204199
$ans->{typeError} = 0;
205200
$ans->{ans_message} = $ans->{error_message} = "";
206201
$ans->{score} = 0;
202+
207203
if (sprintf("%p", $self) ne sprintf("%p", $ans->{correct_value})) {
208204
$ans->{correct_ans} = $self->string;
209205
$ans->{correct_value} = $self;

0 commit comments

Comments
 (0)