Illustrates the shrinking process when testing a procedure that sorts lists of numbers.
In this example, a generator produces random lists of up to 1,000 elements, each having a value between 0 and 999. Each list is passed to FaultySort#sort(List), and an assertion checks that the resulting list is indeed sorted. The FaultySort class contains a deliberately injected fault, such that any list where the sum of elements at indices 3 and 4 is greater than 500 is incorrectly sorted (the two elements are swapped in the output).
After finding a first randomly generated list revealing the fault, the Assert object will ask for a shrunk picker and repeat the process, eventually finding shorter lists with smaller values that also reveal the fault. You can try running the program multiple times; this will produce different inputs. One can observe that the number of shrinking steps depends on the starting seed. However, most of the time, the list that is found is of minimal length (i.e. 5).
A typical output of the program looks like this:
Assertion is false
[931, 520, 668, 369, 906, 823, 468, 145, 623, 702, 691, 52, 963, 339, 722, 434, 901, 590, 111, 734, 104, 694, 200, 871, 211, 311, 820, 856, 382, 724, 390] produces [52, 104, 111, 200, 145, 211, 311, 339, 369, 382, 390, 434, 468, 520, 590, 623, 668, 691, 694, 702, 722, 724, 734, 820, 823, 856, 871, 901, 906, 931, 963] and is not sorted
25 shrinking steps
[0, 28, 35, 725, 419] produces [0, 28, 35, 725, 419] and is also not sorted
- Author
- Sylvain Hallé
Definition at line 58 of file Sort.java.