github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/num/quat/inf_test.go (about) 1 // Copyright ©2018 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 quat 6 7 import ( 8 "math" 9 "testing" 10 ) 11 12 var inf = math.Inf(1) 13 14 var infTests = []struct { 15 q Number 16 want bool 17 }{ 18 {q: Inf(), want: true}, 19 {q: Number{Real: inf, Imag: inf, Jmag: inf, Kmag: inf}, want: true}, 20 {q: Number{Real: -inf, Imag: -inf, Jmag: -inf, Kmag: -inf}, want: true}, 21 {q: Number{Real: inf, Imag: nan, Jmag: nan, Kmag: nan}, want: true}, 22 {q: Number{Real: nan, Imag: inf, Jmag: nan, Kmag: nan}, want: true}, 23 {q: Number{Real: nan, Imag: nan, Jmag: inf, Kmag: nan}, want: true}, 24 {q: Number{Real: nan, Imag: nan, Jmag: nan, Kmag: inf}, want: true}, 25 {q: Number{Real: -inf, Imag: nan, Jmag: nan, Kmag: nan}, want: true}, 26 {q: Number{Real: nan, Imag: -inf, Jmag: nan, Kmag: nan}, want: true}, 27 {q: Number{Real: nan, Imag: nan, Jmag: -inf, Kmag: nan}, want: true}, 28 {q: Number{Real: nan, Imag: nan, Jmag: nan, Kmag: -inf}, want: true}, 29 {q: Number{Real: inf}, want: true}, 30 {q: Number{Imag: inf}, want: true}, 31 {q: Number{Jmag: inf}, want: true}, 32 {q: Number{Kmag: inf}, want: true}, 33 {q: Number{Real: -inf}, want: true}, 34 {q: Number{Imag: -inf}, want: true}, 35 {q: Number{Jmag: -inf}, want: true}, 36 {q: Number{Kmag: -inf}, want: true}, 37 {q: Number{}, want: false}, 38 } 39 40 func TestIsInf(t *testing.T) { 41 t.Parallel() 42 for _, test := range infTests { 43 got := IsInf(test.q) 44 if got != test.want { 45 t.Errorf("unexpected result for IsInf(%v): got:%t want:%t", test.q, got, test.want) 46 } 47 } 48 }