1 // Copyright ©2017 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.
11 "golang.org/x/exp/rand"
14 type Zswaper interface {
15 Zswap(n int, x []complex128, incX int, y []complex128, incY int)
18 func ZswapTest(t *testing.T, impl Zswaper) {
19 rnd := rand.New(rand.NewSource(1))
20 for n := 0; n < 20; n++ {
21 for _, inc := range allPairs([]int{-5, -1, 1, 2, 5, 10}, []int{-3, -1, 1, 3, 7, 12}) {
29 x = make([]complex128, (n-1)*aincX+1)
30 y = make([]complex128, (n-1)*aincY+1)
38 for i := 0; i < n; i++ {
39 x[i*aincX] = complex(rnd.NormFloat64(), rnd.NormFloat64())
40 y[i*aincY] = complex(rnd.NormFloat64(), rnd.NormFloat64())
43 xWant := make([]complex128, len(x))
44 for i := range xWant {
47 yWant := make([]complex128, len(y))
48 for i := range yWant {
52 for i := 0; i < n; i++ {
53 xWant[i*aincX] = y[i*aincY]
54 yWant[i*aincY] = x[i*aincX]
57 for i := 0; i < n; i++ {
58 xWant[(n-i-1)*aincX] = y[i*aincY]
59 yWant[(n-i-1)*aincY] = x[i*aincX]
63 impl.Zswap(n, x, incX, y, incY)
65 prefix := fmt.Sprintf("Case n=%v,incX=%v,incY=%v:", n, incX, incY)
67 t.Errorf("%v: unexpected x:\nwant %v\ngot %v", prefix, xWant, x)
70 t.Errorf("%v: unexpected y:\nwant %v\ngot %v", prefix, yWant, y)