Class Value


  • public class Value
    extends Object
    Utility methods to work with values in test sequences.
    • Field Detail

      • OBJECT_TOSTRING_PATTERN

        private static final Pattern OBJECT_TOSTRING_PATTERN
        The pattern for strings that look like the output of a call to Object.toString().

        This regex is more efficient than a more complete one that matches against "<em>classname</em>@<em>hex</em>". This regex almost always works and is a faster check.

      • escapedStringLengthOkCached

        private static Map<String,​Boolean> escapedStringLengthOkCached
        Used to increase performance of stringLengthOk method.
    • Constructor Detail

      • Value

        public Value()
    • Method Detail

      • toCodeString

        public static String toCodeString​(Object value)
        Given a primitive, boxed primitive, String, Enum, or Class, or the value null, returns a String that can be used in Java source to represent it.
        Parameters:
        value - the value to create a String representation for. The value's type must be a primitive type, a String, Enum, Class, or null.
        Returns:
        a string representing code for the given value
      • isUnassertableString

        public static boolean isUnassertableString​(Object o)
        Returns true if the value is a string that may NOT be asserted over, because it is (likely to be) nondeterministic or is too long.
        Parameters:
        o - the value to test, which may or may not be a string
        Returns:
        true if the value is an unassertable string, false if not a string, false if a string that may be asserted over
      • looksLikeObjectToString

        public static boolean looksLikeObjectToString​(String s)
        Returns true if the given string looks like it came from a call of Object.toString(); in other words, it contains "@<em>hex</em>". Such strings are rarely useful in generation because they contain non-reproducible hash strings.
        Parameters:
        s - the string
        Returns:
        true if string appears to be default toString output, false otherwise
      • stringLengthOk

        public static boolean stringLengthOk​(String s)
        Returns true if the given string is no longer than the --string-maxlen=N parameter.
        Parameters:
        s - the string
        Returns:
        true if the string length is reasonable for generated tests, false otherwise
        See Also:
        GenInputsAbstract.string_maxlen
      • escapedStringLengthOk

        public static boolean escapedStringLengthOk​(String s)
        Returns true if the given string, when quoted for inclusion in a Java program, is no longer than the --string-maxlen=N parameter.

        If Randoop generates tests using strings that are too long, this can result in non-compilable tests due to the JVM's limit on the length of a string.

        Parameters:
        s - the string
        Returns:
        true if the string length is reasonable for generated tests, false otherwise
        See Also:
        GenInputsAbstract.string_maxlen
      • arrayLengthOk

        public static boolean arrayLengthOk​(Object a)
        Returns true if the given array is shorter than the --string-maxlen=N parameter.
        Parameters:
        a - the string
        Returns:
        true if the array length is less than the bound
      • valueSizeOk

        public static boolean valueSizeOk​(Object v)
        Returns true if the given value is not longer than the --string-maxlen=N parameter.
        Parameters:
        v - a value
        Returns:
        true if the value's size is less than the bound
      • lastValueSizeOk

        public static boolean lastValueSizeOk​(ExecutableSequence eseq)
        Returns true if the value returned by the last statement is not too large.
        Parameters:
        eseq - an executable sequence that has been executed
        Returns:
        true if the final result value's size is less than the bound