OSDN Git Service

test (#52)
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / testlapack / dlasrt.go
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.
4
5 package testlapack
6
7 import (
8         "testing"
9
10         "gonum.org/v1/gonum/floats"
11         "gonum.org/v1/gonum/lapack"
12 )
13
14 type Dlasrter interface {
15         Dlasrt(s lapack.Sort, n int, d []float64)
16 }
17
18 func DlasrtTest(t *testing.T, impl Dlasrter) {
19         for ti, test := range []struct {
20                 data    []float64
21                 wantInc []float64
22                 wantDec []float64
23         }{
24                 {
25                         data:    nil,
26                         wantInc: nil,
27                         wantDec: nil,
28                 },
29                 {
30                         data:    []float64{},
31                         wantInc: []float64{},
32                         wantDec: []float64{},
33                 },
34                 {
35                         data:    []float64{1},
36                         wantInc: []float64{1},
37                         wantDec: []float64{1},
38                 },
39                 {
40                         data:    []float64{1, 2},
41                         wantInc: []float64{1, 2},
42                         wantDec: []float64{2, 1},
43                 },
44                 {
45                         data:    []float64{1, 2, -3},
46                         wantInc: []float64{-3, 1, 2},
47                         wantDec: []float64{2, 1, -3},
48                 },
49                 {
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},
53                 },
54                 {
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},
58                 },
59                 {
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},
63                 },
64         } {
65                 n := len(test.data)
66                 ds := make([]float64, n)
67
68                 copy(ds, test.data)
69                 impl.Dlasrt(lapack.SortIncreasing, n, ds)
70                 if !floats.Equal(ds, test.wantInc) {
71                         t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)
72                 }
73
74                 copy(ds, test.data)
75                 impl.Dlasrt(lapack.SortDecreasing, n, ds)
76                 if !floats.Equal(ds, test.wantDec) {
77                         t.Errorf("Case #%v: unexpected result of SortIncreasing", ti)
78                 }
79         }
80 }