Package randoop.contract
Class ObserverEqValue
java.lang.Object
randoop.contract.ObjectContract
randoop.contract.ObserverEqValue
A check recording the value that an observer method returned during execution, e.g. a check
recording that a collection's
size()
method returned 3
.
ObserverEqValue checks are not checks that must hold of all objects of a given class (unlike a
check like EqualsReflexive
, which must hold for any objects, no matter its execution
context).
-
Field Summary
Modifier and TypeFieldDescription(package private) static TypeTuple
The arguments to which this contract can be applied.The observer method.The run-time result of calling the observer: a primitive value or String. -
Constructor Summary
ConstructorDescriptionObserverEqValue
(TypedOperation observer, Object value) Create a new ObserverEqValue. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Evaluates the contract on the given values.Returns a string describing the observer.int
getArity()
The number of values that this contract is over.Returns the input types for this contract.int
hashCode()
static boolean
isLiteralValue
(Object value) Returns true if the argument can be written as a literal in Java source code.A string that can be used as Java source code and will result in the expression being evaluated.A string that will be inserted as a comment in the test before the code corresponding to this contract.toString()
Methods inherited from class randoop.contract.ObjectContract
checkContract, failedContract, toStringHandleExceptions
-
Field Details
-
observer
The observer method. -
value
The run-time result of calling the observer: a primitive value or String. -
inputTypes
The arguments to which this contract can be applied.
-
-
Constructor Details
-
ObserverEqValue
Create a new ObserverEqValue.- Parameters:
observer
- the observer methodvalue
- the run-time result of calling the observer: a primitive value or String
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
isLiteralValue
Returns true if the argument can be written as a literal in Java source code.- Parameters:
value
- the value to be tested- Returns:
- true if the argument can be written as a literal in Java source code
-
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 classObjectContract
- Returns:
- the code string representation of this contract; must be non-null
-
evaluate
Description copied from class:ObjectContract
Evaluates the contract on the given values. Returnsfalse
if the contract was violated. Returnstrue
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 anynull
objects, and thatobjects.length == getArity()
.- Specified by:
evaluate
in classObjectContract
- 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 classObjectContract
- Returns:
- the number of arguments to the contract
-
getInputTypes
Description copied from class:ObjectContract
Returns the input types for this contract.- Specified by:
getInputTypes
in classObjectContract
- Returns:
- the input types for this contract
-
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 classObjectContract
- Returns:
- the comment string representation of this contract
-
get_observer_str
Description copied from class:ObjectContract
Returns a string describing the observer.- Specified by:
get_observer_str
in classObjectContract
- Returns:
- a string description of the contract
-
toString
-