Class PrimValue


public final class PrimValue extends ObjectContract
A check recording the value of a primitive value (or String) obtained during execution (e.g., var3 == 1 where var3 is an integer-valued variable in a Randoop test).
  • Field Details

    • value

      public final Object value
      The expected run-time value. It is a boxed primitive or String (checked during construction).
    • equalityMode

      private final PrimValue.EqualityMode equalityMode
      Whether to use == or .equals() to test for equality.
    • inputTypes

      static TypeTuple inputTypes
      The arguments to which this contract can be applied.
  • Constructor Details

    • PrimValue

      public PrimValue(Object value, PrimValue.EqualityMode equalityMode)
      Parameters:
      value - the value for the expression: a primitive value or string
      equalityMode - what equality test the assertion uses
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • evaluate

      public boolean evaluate(Object... objects) throws Throwable
      Description copied from class: ObjectContract
      Evaluates the contract on the given values. Returns false if the contract was violated. Returns true if the contract was satisfied or was not applicable.

      When calling this method during execution of a test, Randoop guarantees that objects does not contain any null objects, and that objects.length == getArity().

      Specified by:
      evaluate in class ObjectContract
      Parameters:
      objects - the actual parameters to this contract
      Returns:
      false if the contract is violated, true otherwise
      Throws:
      Throwable - if an exception is thrown in evaluation
    • getArity

      public int getArity()
      Description copied from class: ObjectContract
      The number of values that this contract is over.
      Specified by:
      getArity in class ObjectContract
      Returns:
      the number of arguments to the contract
    • getInputTypes

      public TypeTuple getInputTypes()
      Description copied from class: ObjectContract
      Returns the input types for this contract.
      Specified by:
      getInputTypes in class ObjectContract
      Returns:
      the input types for this contract
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get_observer_str

      public String get_observer_str()
      Description copied from class: ObjectContract
      Returns a string describing the observer.
      Specified by:
      get_observer_str in class ObjectContract
      Returns:
      a string description of the contract
    • toCodeString

      public String toCodeString()
      Description copied from class: ObjectContract
      A string that can be used as Java source code and will result in the expression being evaluated.

      The N-th object that participates in the contract check should be referred to as "xN" (for N one of 0, ... , 9). For example, if the expression of arity 2 represents a call of the equals method between two objects, the code should be something like assert x0.equals(x1);".

      The string does not contain a trailing newline. When there is a leading comment, it should start with a newline.

      Specified by:
      toCodeString in class ObjectContract
      Returns:
      the code string representation of this contract; must be non-null
    • toCommentString

      public String toCommentString()
      Description copied from class: ObjectContract
      A string that will be inserted as a comment in the test before the code corresponding to this contract. Occurrences of variables x0, x1, x2, etc. in the string will be replaced by actual values.
      Specified by:
      toCommentString in class ObjectContract
      Returns:
      the comment string representation of this contract