Skip to content

Round PG score eariler in logic chain to avoid floating point errors. #739

Open
@somiaj

Description

@somiaj

I ran across an issue where lib/WeBWorK/PG/Translator.pm (line 1514) in avg_problem_grader is warning that Error in grading this problem the total 1 is larger than 1, which should only trigger if $total > $count which appear to both be 1 when using a single MultiAnswer grader.

Here is my test problem:

DOCUMENT();
loadMacros(
    'PGstandard.pl',
    'PGML.pl',
    'parserMultiAnswer.pl',
);
$showPartialCorrectAnswers = 1;

$ans1 = Compute("pi");
$ans2 = Compute("x^2");
$ans3 = Compute("3");
$ans4 = Compute("4");
$ans5 = Compute("5");
$ans6 = Compute("6");

$ma = MultiAnswer($ans1, $ans2, $ans3, $ans4, $ans5, $ans6)->with(
    singleResult => 1,
    allowBlankAnswer => 1,
    checkTypes => 1,
    format => '%s; %s; %s; %s; %s; %s',
    tex_format => '%s; %s; %s; %s; %s; %s',
    checker => sub {
        my ($correct, $student, $self, $ansHash) = @_;
        my @c = @{$correct};
        my @s = @{$student};
        my $score = 0;
        $score += 0.3 if ($c[0] == $s[0]);
        $score += 0.5 if ($c[1] == $s[1]);
        foreach (2..5) {
            $score += 0.05 if ($c[$_] == $s[$_]);
        }
        #Value->Error($score);
        return $score;
    }
);

BEGIN_PGML
+ Enter [`\pi`]: [_]{$ma}
+ Enter [`x^2`]: [_]{$ma}
+ Enter [`3`]: [_]{$ma}
+ Enter [`4`]: [_]{$ma}
+ Enter [`5`]: [_]{$ma}
+ Enter [`6`]: [_]{$ma}
END_PGML
ENDDOCUMENT();

The warning only happens if the problem has all answers parts correct. I have tried this with both 2 and 4 answer boxes and the warning doesn't occur, so it is something subtle in the grader I wrote, but can't track it down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions