CPSC 333: Unit Testing - An Example

Location: [CPSC 333] [Listing by Topic] [Listing by Date] [Previous Topic] [Next Topic] Unit Testing Example


This material was covered during lectures on March 24, 1997.


The following sorting algorithm will be used as an example when Unit Testing is discussed. It uses an array A of n integers A[1], A[2], ..., A[n] as input, and returns the same array output, with its contents rearranged in sorted (increasing) order.

Statements and conditions (except for ``end'' statements) will be labeled for future reference.

S1              i := 2
C1              while (i is less than or equal to n) do
S2                j := i - 1
C2                while ((j is greater than or equal to 1) and
                            (A[j] is greater than A[j+1])) do
S3                  temp := A[j]
S4                  A[j] := A[j+1]
S5                  A[j+1] := temp
S6                  j := j-1
                  end while
S7                i := i + 1
                end while

On occasion a final statement labeled S8, ``stop,'' will be used to identify the program's exit point.

Location: [CPSC 333] [Listing by Topic] [Listing by Date] [Previous Topic] [Next Topic] Unit Testing Example


Department of Computer Science
University of Calgary

Office: (403) 220-5073
Fax: (403) 284-4707

eberly@cpsc.ucalgary.ca