CSE 127: Lecture 8
The topics covered in this lecture are
software testing (in the context of sorting), and
proofs of correctness (continued in next [few] lecture[s]).
We are going to use the following sort procedure (in C) as the code
which we will look for test cases. We will look at how to select test
inputs for normal execution, boundary cases, and illegal inputs. (In
the case of a simple subroutine, illegal inputs are sometimes covered
by preconditions.)
void swap(void *array,
int i,
int j,
int s)
{
char *lhs = (char *) (array + i * s);
char *rhs = (char *) (array + j * s);
int t;
while (s > 0) {
t = *lhs; *lhs = *rhs; *rhs = t;
lhs++; rhs++; s--;
}
}
void sort(void *array,
unsigned int nelt,
unsigned int eltsize,
int (*fn)(void *, void *))
{
int us, i;
/*
* us is the index of the first unsorted element and divides
* the array into a sorted and a unsorted region.
*/
for (us = 1; us <= nelt; us++) {
for (i = nelt-2; i >= 0; i--) {
if ((*fn)(array + i * eltsize, array + (i+1) * eltsize) > 0) {
swap(array,i,j,eltsize);
}
}
}
}
Preconditions
Preconditions are what we assume to be true when the code is called.
They are part of the contract between the code and its
caller. Often we simply determine the valid input ranges and require
the caller to ensure that the parameters are within these ranges. For
more some code, sometimes we are more careful, and perform run-time
checks to be sure that the inputs do not fall outside of the range of
valid input values.
We will use this sorting procedure to examine proofs as well as for
testing. More in upcoming lectures.
[
search CSE |
CSE |
bsy's home page |
links |
webster |
MRQE |
google |
yahoo |
citeseer |
certserver
]
bsy+cse127w02@cs.ucsd.edu, last updated Mon Mar 25 15:22:10 PST 2002. Copyright 2002 Bennet Yee.
email bsy.