Package randoop.contract
Class ObserverEqArray
- java.lang.Object
-
- randoop.contract.ObjectContract
-
- randoop.contract.ObserverEqArray
-
public final class ObserverEqArray extends ObjectContract
A check recording the current state of an array during execution.ObserverEqArray 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
Fields Modifier and Type Field Description private static double
DOUBLE_DELTA
The maximum difference for which doubles are considered equal.private static float
FLOAT_DELTA
The maximum difference for which floats are considered equal.(package private) static TypeTuple
inputTypes
The arguments to which this contract can be applied.private Object
value
The run-time result of calling the observer: an array of literals.
-
Constructor Summary
Constructors Constructor Description ObserverEqArray(Object value, AccessibilityPredicate isAccessible)
Creates a new ObserverEqArray.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private String
arrayComponentsToString()
Returns a string representation of the components of the array, enclosed in curly braces, as it would appear in Java source code.boolean
equals(Object o)
boolean
evaluate(Object... objects)
Evaluates the contract on the given values.String
get_observer_str()
Returns a string describing the observer.int
getArity()
The number of values that this contract is over.TypeTuple
getInputTypes()
Returns the input types for this contract.int
hashCode()
static boolean
isLiteralType(Object value, AccessibilityPredicate isAccessible)
Returns true if the value can be represented as a literal in Java source code.private String
newArrayExpression()
Returns a Java array constructor expression for this, e.g., "new int[] {1,2,3}".String
toCodeString()
A string that can be used as Java source code and will result in the expression being evaluated.String
toCommentString()
A string that will be inserted as a comment in the test before the code corresponding to this contract.String
toString()
-
Methods inherited from class randoop.contract.ObjectContract
checkContract, failedContract, toStringHandleExceptions
-
-
-
-
Field Detail
-
value
private Object value
The run-time result of calling the observer: an array of literals.
-
DOUBLE_DELTA
private static final double DOUBLE_DELTA
The maximum difference for which doubles are considered equal.- See Also:
- Constant Field Values
-
FLOAT_DELTA
private static final float FLOAT_DELTA
The maximum difference for which floats are considered equal.- See Also:
- Constant Field Values
-
inputTypes
static TypeTuple inputTypes
The arguments to which this contract can be applied.
-
-
Constructor Detail
-
ObserverEqArray
public ObserverEqArray(Object value, AccessibilityPredicate isAccessible)
Creates a new ObserverEqArray.- Parameters:
value
- the run-time result of calling the observer: an array of literalsisAccessible
- the accessibility predicate
-
-
Method Detail
-
isLiteralType
public static boolean isLiteralType(Object value, AccessibilityPredicate isAccessible)
Returns true if the value can be represented as a literal in Java source code. If value is of type Enum or another class that is not built-in, an accessibility check is performed.- Parameters:
value
- an objectisAccessible
- the accessibility predicate- Returns:
- true iff the array elements are primitives, boxed primitives, Strings, Classes, accessible Enums or if the array consists of only null values
-
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 classObjectContract
- Returns:
- the code string representation of this contract; must be non-null
-
newArrayExpression
private String newArrayExpression()
Returns a Java array constructor expression for this, e.g., "new int[] {1,2,3}".- Returns:
- a Java array constructor expression for this
-
arrayComponentsToString
private String arrayComponentsToString()
Returns a string representation of the components of the array, enclosed in curly braces, as it would appear in Java source code.- Returns:
- a String that represents the components of the array
-
evaluate
public boolean evaluate(Object... objects) throws Throwable
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
public TypeTuple 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
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 classObjectContract
- Returns:
- the comment string representation of this contract
-
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 classObjectContract
- Returns:
- a string description of the contract
-
-