forked from gonum/gonum
/
dlasrt.go
80 lines (73 loc) · 1.86 KB
/
dlasrt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright ©2016 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testlapack
import (
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/lapack"
)
type Dlasrter interface {
Dlasrt(s lapack.Sort, n int, d []float64)
}
func DlasrtTest(t *testing.T, impl Dlasrter) {
for ti, test := range []struct {
data []float64
wantInc []float64
wantDec []float64
}{
{
data: nil,
wantInc: nil,
wantDec: nil,
},
{
data: []float64{},
wantInc: []float64{},
wantDec: []float64{},
},
{
data: []float64{1},
wantInc: []float64{1},
wantDec: []float64{1},
},
{
data: []float64{1, 2},
wantInc: []float64{1, 2},
wantDec: []float64{2, 1},
},
{
data: []float64{1, 2, -3},
wantInc: []float64{-3, 1, 2},
wantDec: []float64{2, 1, -3},
},
{
data: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
},
{
data: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
},
{
data: []float64{-2, 4, -1, 2, -4, 0, 3, 5, -5, 1, -3},
wantInc: []float64{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
wantDec: []float64{5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5},
},
} {
n := len(test.data)
ds := make([]float64, n)
copy(ds, test.data)
impl.Dlasrt(lapack.SortIncreasing, n, ds)
if !floats.Equal(ds, test.wantInc) {
t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)
}
copy(ds, test.data)
impl.Dlasrt(lapack.SortDecreasing, n, ds)
if !floats.Equal(ds, test.wantDec) {
t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)
}
}
}