Skip to content

Commit

Permalink
fix bugs with answerHints from issue #964
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc authored and Alex-Jordan committed Dec 1, 2023
1 parent f8ff076 commit 9bc48db
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions macros/answers/answerHints.pl
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ sub AnswerHints {
cmp_options => [],
@options,
);
next if $options{checkTypes} && $correct->type ne $student->type;
next if !$options{processPreview} && $ans->{isPreview};
$wrongList = [$wrongList] unless ref($wrongList) eq 'ARRAY';

foreach my $wrong (@{$wrongList}) {
if (ref($wrong) eq 'CODE') {
if (($ans->{score} < 1 || $options{checkCorrect})
if ((!$options{checkTypes} || $correct->type eq $student->type)
&& ($ans->{score} < 1 || $options{checkCorrect})
&& ($ans->{ans_message} eq "" || $options{replaceMessage}))
{
# Make the call to run the function inside an eval to trap errors
Expand All @@ -166,16 +166,12 @@ sub AnswerHints {
}
}
} else {
$wrong = Value::makeValue($wrong);
if (
(
$ans->{score} < 1
|| $options{checkCorrect}
|| AnswerHints::Compare($correct, $wrong, $ans)
)
&& ($ans->{ans_message} eq "" || $options{replaceMessage})
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} })
)
unless (Value::isValue($wrong)) {
$wrong = main::Formula($wrong);
$wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute};
}
if (($ans->{ans_message} eq "" || $options{replaceMessage})
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} }))
{
$ans->{ans_message} = $ans->{error_message} = $message;
$ans->{score} = $options{score} if defined $options{score};
Expand All @@ -197,13 +193,13 @@ package AnswerHints;
# and returns true if the two values match and false otherwise.
#
sub Compare {
my $self = shift;
my $other = shift;
my $ans = shift;
$ans = bless { %{$ans}, @_ }, ref($ans); # make a copy
my ($self, $other, $ans, @options) = @_;
return 0 unless $self->typeMatch($other); # make sure these can be compared
$ans = bless { %{$ans}, @options }, ref($ans); # make a copy
$ans->{typeError} = 0;
$ans->{ans_message} = $ans->{error_message} = "";
$ans->{score} = 0;

if (sprintf("%p", $self) ne sprintf("%p", $ans->{correct_value})) {
$ans->{correct_ans} = $self->string;
$ans->{correct_value} = $self;
Expand Down

0 comments on commit 9bc48db

Please sign in to comment.