1 // Copyright ©2016 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "gonum.org/v1/gonum/floats"
11 "gonum.org/v1/gonum/lapack"
14 type Dlasrter interface {
15 Dlasrt(s lapack.Sort, n int, d []float64)
18 func DlasrtTest(t *testing.T, impl Dlasrter) {
19 for ti, test := range []struct {
36 wantInc: []float64{1},
37 wantDec: []float64{1},
40 data: []float64{1, 2},
41 wantInc: []float64{1, 2},
42 wantDec: []float64{2, 1},
45 data: []float64{1, 2, -3},
46 wantInc: []float64{-3, 1, 2},
47 wantDec: []float64{2, 1, -3},
50 data: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
51 wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
52 wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
55 data: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
56 wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
57 wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
60 data: []float64{-2, 4, -1, 2, -4, 0, 3, 5, -5, 1, -3},
61 wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
62 wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
66 ds := make([]float64, n)
69 impl.Dlasrt(lapack.SortIncreasing, n, ds)
70 if !floats.Equal(ds, test.wantInc) {
71 t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)
75 impl.Dlasrt(lapack.SortDecreasing, n, ds)
76 if !floats.Equal(ds, test.wantDec) {
77 t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)