]> Cypherpunks.ru repositories - gostls13.git/commit
sort: fix TestAdversary
authorTom Levy <tomlevy93@gmail.com>
Thu, 24 Aug 2017 01:44:04 +0000 (13:44 +1200)
committerIan Lance Taylor <iant@golang.org>
Fri, 25 Aug 2017 05:58:57 +0000 (05:58 +0000)
commit3723d080220080dcc5b40737eaf1970af29165b7
treefeb356548ab8e42f03e415c5f6a043e8cafa7571
parentb0ba0b49a023100151ec4b562163615f37b57ad9
sort: fix TestAdversary

There are some major problems with TestAdversary (based on "A Killer
Adversary for Quicksort"[1] by M. D. McIlroy). See #21581 for details.

Rewrite the test to closely match the version in the paper so it can
be verified as correct by virtue of similarity.

The only major difference between this new version and the version in
the paper is that this version swaps the values directly instead of
permuting an array of indices because we don't need to recover the
original permutation.

This new version also counts the number of calls to Less() and fails
the test if there are too many.

Fixes #21581.

[1]: http://www.cs.dartmouth.edu/~doug/mdmspe.pdf

Change-Id: Ia94b5b6d288b8fa3805a5fa27661cebbc5bad9a7
Reviewed-on: https://go-review.googlesource.com/58330
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/sort/sort_test.go