/home/jaubrey/webwork//pg_TRUNK/lib/Value/AnswerChecker.pm

From WeBWorK

Jump to: navigation


DESCRIPTION

 #############################################################
 #
 #  Implements the ->cmp method for Value objects.
 #  Otherwise known as MathObjects.  This produces
 #  an answer checker appropriate for the type of object.
 #  Additional options can be passed to the cmp method to
 #  modify its action.
 #
 #   Usage:  $num = Real(3.45); # Real can be replaced by any other MathObject
 #                       ANS($num->cmp(compareOptionName => compareOptionValue, ... ))
 #
 #  The individual Value packages are modified below to add the
 #  needed methods.
 #
 #############################################################

$mathObject->cmp_defaults()

# Internal use. # Set default flags for the answer checker in this object # showTypeWarnings => 1 # showEqualErrors => 1 # ignoreStrings => 1 # studentsMustReduceUnions => 1 # showUnionReduceWarnings => 1 #

Value::Real

        Usage ANS( Real(3.56)->cmp() )
                Compares response to a real value using 'fuzzy' comparison
                compareOptions and default values:
                          showTypeWarnings => 1,
                          showEqualErrors  => 1,
                          ignoreStrings    => 1,

Value::String

        Usage:  $s = String("pole");
                ANS($s->cmp(typeMatch => Complex("4+i")));
                    # compare to response 'pole', don't complain about complex number responses.
                compareOptions and default values:
                  showTypeWarnings => 1,
                  showEqualErrors  => 1,
                  ignoreStrings    => 1,  # don't complain about string-valued responses
                  typeMatch        => 'Value::Real'
        Initial and final spaces are ignored when comparing strings.

Value::Point

        Usage: $pt = Point("(3,6)"); # preferred
               or $pt = Point(3,6);
               or $pt = Point([3,6]);
               ANS($pt->cmp());
                compareOptions:
                  showTypeWarnings => 1,   # warns if student response is of incorrect type
                  showEqualErrors  => 1,
                  ignoreStrings    => 1,
                  showDimensionHints => 1, # reports incorrect number of coordinates
                  showCoordinateHints =>1, # flags individual coordinates that are incorrect

Value::Vector

        Usage:  $vec = Vector("<3,6,7>");
                or $vec = Vector(3,6,7);
                or $vec = Vector([3,6,7]);
                ANS($vec->cmp());
                compareOptions:
                  showTypeWarnings    => 1,   # warns if student response is of incorrect type
                  showEqualErrors     => 1,
                  ignoreStrings       => 1,
                  showDimensionHints  => 1, # reports incorrect number of coordinates
                  showCoordinateHints => 1, # flags individual coordinates which are incorrect
                  promotePoints       => 0, # allow students to enter vectors as points (3,5,6)
                  parallel            => 1, # response is correct if it is parallel to correct answer
                  sameDirection       => 1, # response is correct if it has same orientation as correct answer
                                            #  (only has an effect when parallel => 1 is specified)

Value::Matrix

        Usage   $ma = Matrix([[3,6],[2,5]]) or $ma =Matrix([3,6],[2,5])
                ANS($ma->cmp());
                compareOptions:
                  showTypeWarnings    => 1, # warns if student response is of incorrect type
                  showEqualErrors     => 1, # reports messages that occur during element comparisons
                  ignoreStrings       => 1,
                  showDimensionHints  => 1, # reports incorrect number of coordinates
                  showCoordinateHints => 1, # flags individual coordinates which are incorrect

Value::Interval

        Usage:    $interval = Interval("(1,2]");
                  or $interval = Interval('(',1,2,']');
                  ANS($inteval->cmp);
                  compareOptions and defaults:
                        showTypeWarnings  => 1,
                        showEqualErrors   => 1,
                        ignoreStrings     => 1,
                        showEndpointHints => 1, # show hints about which end point values are correct
                        showEndTypeHints  => 1, # show hints about endpoint types
                        requireParenMatch => 1,

Value::Set

        Usage:   $set = Set(5,6,'a', 'b')
              or $set = Set("{5, 6, a, b}")
              The object is a finite set of real numbers. It can be used with Union and
              Interval.
        Examples:  Interval("(-inf,inf)") - Set(0)
                   Compute("R-{0}")   # in Interval context: Context("Interval");

Value::Union

        Usage: $union = Union("[4,5] U [6,7]");
               or $union = Union(Interval("[4,5]",Interval("[6,7]"));
               ANS($union->cmp());

Value::List

        Usage:  $lst = List("1, x, <4,5,6>"); # list of a real, a formula and a vector.
                or $lst = List(Real(1), Formula("x"), Vector(4,5,6));
                ANS($lst->cmp(showHints=>1));
                compareOptions and defaults:
                        showTypeWarnings => 1,
                        showEqualErrors  => 1,         # show errors produced when checking equality of entries
                        ignoreStrings    => 1,         # don't show type warnings for strings
                        studentsMustReduceUnions => 1,
                        showUnionReduceWarnings => 1,
                        showHints => undef,            # automatically set to 1 if $showPartialCorrectAnswers == 1
                        showLengthHints => undef,      # automatically set to 1 if $showPartialCorrectAnswers == 1
                        showParenHints => undef,       # automatically set to 1 if $showPartialCorrectAnswers == 1
                        partialCredit => undef,        # automatically set to 1 if $showPartialCorrectAnswers == 1
                        ordered => 0,                  # 1 = must be in same order as correct answer
                        entry_type => undef,           # determined from first entry
                        list_type => undef,            # determined automatically
                        typeMatch => $element,         # used for type checking the entries
                        firstElement => $element,
                        extra => undef,                # used to check syntax of incorrect answers
                        requireParenMatch => 1,        # student parens must match correct parens
                        removeParens => 1,             # remove outermost parens, if any
                        implicitList => 1,             # force single answers to be lists (even if they ARE lists)

Value::Formula

        Usage: $fun = Formula("x^2-x+1");
               $set = Formula("[-1, x) U (x, 2]");
        A formula can have any of the other math object types as its range.
                Union, List, Number (Complex or Real),