diff options
Diffstat (limited to 'src/slices/sort_test.go')
-rw-r--r-- | src/slices/sort_test.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/slices/sort_test.go b/src/slices/sort_test.go index 7aaf954214..2e045e2af8 100644 --- a/src/slices/sort_test.go +++ b/src/slices/sort_test.go @@ -92,7 +92,8 @@ func (d intPairs) initB() { } // InOrder checks if a-equal elements were not reordered. -func (d intPairs) inOrder() bool { +// If reversed is true, expect reverse ordering. +func (d intPairs) inOrder(reversed bool) bool { lastA, lastB := -1, 0 for i := 0; i < len(d); i++ { if lastA != d[i].a { @@ -100,8 +101,14 @@ func (d intPairs) inOrder() bool { lastB = d[i].b continue } - if d[i].b <= lastB { - return false + if !reversed { + if d[i].b <= lastB { + return false + } + } else { + if d[i].b >= lastB { + return false + } } lastB = d[i].b } @@ -127,7 +134,7 @@ func TestStability(t *testing.T) { if !IsSortedFunc(data, intPairCmp) { t.Errorf("Stable didn't sort %d ints", n) } - if !data.inOrder() { + if !data.inOrder(false) { t.Errorf("Stable wasn't stable on %d ints", n) } @@ -137,7 +144,7 @@ func TestStability(t *testing.T) { if !IsSortedFunc(data, intPairCmp) { t.Errorf("Stable shuffled sorted %d ints (order)", n) } - if !data.inOrder() { + if !data.inOrder(false) { t.Errorf("Stable shuffled sorted %d ints (stability)", n) } @@ -150,7 +157,7 @@ func TestStability(t *testing.T) { if !IsSortedFunc(data, intPairCmp) { t.Errorf("Stable didn't sort %d ints", n) } - if !data.inOrder() { + if !data.inOrder(false) { t.Errorf("Stable wasn't stable on %d ints", n) } } |