/** * generic-testing-tools.h * A variety of tools to make testing easier (or so I hope). * Note: TYPE, PREFIX(FUN), MAY_PRECEDE(X,Y) and EQUALS(X,Y) must be * defined in order for this to work. */ /** * Procedure: * PREFIX(is_in_order) * Parameters: * values[], an array of values of type TYPE * size, an integer * Purpose: * Determine if the first size values in values are in order. * Produces: * in_order, an integer that represents a Boolean * Preconditions: * 0 <= size < length of values * Postconditions: * If values[i] <= values[i+1] for all reasonable i, then * in_order is true (1). * Otherwise, in_order is false (0). */ int PREFIX(is_in_order) (TYPE values[], int size); /** * Procedure: * PREFIX(is_permutation) * Parameters: * a1, an array of TYPE * a2, an array of TYPE * size, an integer * Purpose: * Determine if a2 is a permutation of a1. * Produces: * is_perm, an integer that represents a Boolean * Preconditions: * 0 <= size * size <= length of a1 * size <= length of a2 * Postconditions: * The first size elements of a2 are a permutation of the first size * elements of a2 iff is_perm is true. */ int PREFIX(is_permutation) (TYPE a1[], TYPE a2[], int size); /** * Procedure: * PREFIX(index_of) * Parameters: * a, an array of TYPE * limit, an integer * value, a value of type TYPE * Purpose: * Finds an index of value in a. * Produces: * index, an integer * Preconditions: * 0 <= limit <= length(a) * Postconditions: * a has not been modified * If there exists a j in [0..limit) s.t. EQUALS(a[j], value), then * index >= 0 and EQUALS(a[index],value) * If no such j exists, then * index == -1 */ int PREFIX(index_of) (TYPE a[], int limit, TYPE value); /** * Procedure: * PREFIX(count) * Parameters: * a, an array of TYPE * limit, an integer * value, a value of type TYPE * Purpose: * Count how many times value appears in the first limit elements of a. * Produces: * c, an integer * Preconditions: * 0 <= limit <= length(a) * Postconditions: * a has not been modified * There are exactly c distinct i's s.t. a[i] is value. */ int PREFIX(count) (TYPE a[], int limit, TYPE value);