WeBWorK Problems

Customizing List answer checkers

Re: Customizing List answer checkers

by Davide Cervone -
Number of replies: 0
It occurs to me this may not actually do what you want. Note that it will say you are close if any ONE point is close. You may want to say that only if ALL the points are either correct or close. To do that, you can set $student->{isEqual} = 1 in addition to clearing $student->{isClose} in the checker and modify the answer hint routine to return 0 if neither is set and 1 otherwise.

Alternatively, since the answer hint routine is only called if the answer is not correct, you could just set $student->{isClose} = 1 when it is actually equal (rather than using a separate field isEqual) and that will simplify both the checker and the testing in the answer hint routine.

Untested code:


    ANS($anser_list->cmp
      (checker => sub {
        my ($correct,$student,$ans) = @_;
        $student->{isClose} = 1 if Vector($correct-$student)->norm < .3*$tolerance;
        return $correct == $student;
      })->withPostFilter(AnswerHints(sub {
        my ($correct,$student,$ans) = @_;
        $student = List($student) unless $student->class eq "List";
        foreach $point ($student->value) {return 0 unless $point->{isClose}}
        return 1;
      } => ["You're close.  You need to position at least one dot more precisely"]
    )));

Davide