The zip file below contains a small C# program that performs high-volume testing of a sorting routine called "ShearSort".
The test program works as follows:
- Generate an ordered list;
- Shuffle the list;
- Send the shuffled list to the ShearSort routine;
- Verify that the sorted output is correct;
- Repeat.
Steps to run the program:
- Download and unzip ShearSortHighVolumeTest.zip.
- Open ShearSortHighVolumeTest.cs in an editor.
- Create a new C# console project in Visual Studio.
- Paste the contents of ShearSortHighVolumeTest.cs
over the Program.cs content in Visual Studio.
- Save Program.cs.
- Build and run the solution.
Test results will show up in a prompt window, of the form:
Sort fail! size=9
input [6, 9, 1, 4, 7, 5, 8, 2, 3]
output [1, 2, 4, 3, 6, 7, 5, 8, 9]
Points of interest:
- The program tests lists from size 2 to size 10.
- The program tests 500 random shuffles at each list size.
- You can increase the upper bound of list size by changing the variable largeSetSize.
- The bug first shows up at list size 9.
- You can fix the bug by changing the “<” to “<=” in line 90 (see comment in the code)
Enjoy!
Harry and Doug
PS: We simplified the pseudo-code listings after our article went to press.
|