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.
10 "golang.org/x/exp/rand"
12 "gonum.org/v1/gonum/floats"
15 type Dzasumer interface {
16 Dzasum(n int, x []complex128, incX int) float64
19 func DzasumTest(t *testing.T, impl Dzasumer) {
21 rnd := rand.New(rand.NewSource(1))
22 for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 50, 100} {
23 for _, incX := range []int{-5, 1, 2, 10} {
27 x = make([]complex128, (n-1)*aincX+1)
32 for i := 0; i < n; i++ {
33 re := float64(2*i + 1)
37 im := float64(2 * (i + 1))
41 x[i*aincX] = complex(re, im)
44 want := float64(n * (2*n + 1))
45 got := impl.Dzasum(n, x, incX)
49 t.Errorf("Case n=%v,incX=%v: non-zero result when incX < 0. got %v", n, incX, got)
53 if !floats.EqualWithinAbsOrRel(got, want, tol, tol) {
54 t.Errorf("Case n=%v,incX=%v: unexpected result. want %v, got %v", n, incX, want, got)