github.com/gopherd/gonum@v0.0.4/blas/testblas/izamax.go (about) 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. 4 5 package testblas 6 7 import ( 8 "testing" 9 10 "math/rand" 11 ) 12 13 type Izamaxer interface { 14 Izamax(n int, x []complex128, incX int) int 15 } 16 17 func IzamaxTest(t *testing.T, impl Izamaxer) { 18 rnd := rand.New(rand.NewSource(1)) 19 for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 50, 100} { 20 for _, incX := range []int{-5, 1, 2, 10} { 21 aincX := abs(incX) 22 var x []complex128 23 if n > 0 { 24 x = make([]complex128, (n-1)*aincX+1) 25 } 26 for i := range x { 27 x[i] = znan 28 } 29 for i := 0; i < n; i++ { 30 re := 2*rnd.Float64() - 1 31 im := 2*rnd.Float64() - 1 32 x[i*aincX] = complex(re, im) 33 } 34 35 want := -1 36 if incX > 0 && n > 0 { 37 want = rnd.Intn(n) 38 x[want*incX] = 10 + 10i 39 } 40 got := impl.Izamax(n, x, incX) 41 42 if got != want { 43 t.Errorf("Case n=%v,incX=%v: unexpected result. want %v, got %v", n, incX, want, got) 44 } 45 } 46 } 47 }