Package randoop.test

Class ContractCheckingGenerator

java.lang.Object
randoop.test.TestCheckGenerator
randoop.test.ContractCheckingGenerator

public final class ContractCheckingGenerator extends TestCheckGenerator
An execution visitor that generates checks for error-revealing tests.

If execution of the visited sequence is normal, it will generate checks for contracts over the values from the execution. Contracts will be checked on all values except for boxed primitives or Strings. For each contract violation, the visitor adds a Check to the TestChecks object that is returned.

If the execution throws an exception considered to be an error, the visitor generates a NoExceptionCheck indicating that the statement should not throw the exception.

  • Field Details

  • Constructor Details

    • ContractCheckingGenerator

      public ContractCheckingGenerator(ContractSet contracts)
      Create a new visitor that checks the given contracts after the last statement in a sequence is executed.
      Parameters:
      contracts - expected to be unary contracts, i.e. for each contract c, c.getArity() == 1.
  • Method Details

    • generateTestChecks

      public TestChecks<?> generateTestChecks(ExecutableSequence eseq)
      Generate a TestChecks object for the executed sequence eseq based on the criteria of this generator.

      Adds checks to final statement of sequence. Looks for failure exceptions, and violations of contracts in contracts.

      Specified by:
      generateTestChecks in class TestCheckGenerator
      Parameters:
      eseq - the sequence for which checks are generated
      Returns:
      the generated check set for the sequence
    • singletonTestCheck

      private TestChecks<?> singletonTestCheck(Check check)
      Return a TestChecks that contains only the given check.
      Parameters:
      check - the sole member of the singleton TestChecks
      Returns:
      a TestChecks that contains only the given check
    • checkContracts

      Check checkContracts(List<ObjectContract> contracts, ExecutableSequence eseq, TupleSet<ReferenceValue> tuples)
      If a contract fails for some tuple, returns some such failing check.
      Parameters:
      contracts - the contracts to check
      eseq - the executable sequence that is the source of values for checking contracts
      tuples - the value tuples to use as input to the contracts
      Returns:
      a Check of the first contract+tuple that did not succeed, or null if all contracts succeeded. More specifically, returns a ObjectCheck if a contract fails, an InvalidExceptionCheck if a contract throws an exception indicating that the sequence is invalid, null otherwise.
    • typesMatch

      public static boolean typesMatch(TypeTuple inputTypes, List<ReferenceValue> valueTuple)
      Indicates whether the given list of values matches the types in the type tuple. Contracts may have generic input types, so this method checks for consistent substitutions across value types.
      Parameters:
      inputTypes - the expected types for contract input
      valueTuple - the values to match against input types
      Returns:
      true if the types of the values are assignable to the expected types, false otherwise
    • getValues

      private static Object[] getValues(List<ReferenceValue> tuple)
      Creates an Object array for the given value list.
      Parameters:
      tuple - the list of values
      Returns:
      the Object array for the values