github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/num/quat/nan_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 nan = math.NaN()
    13  
    14  var nanTests = []struct {
    15  	q    Number
    16  	want bool
    17  }{
    18  	{q: NaN(), want: true},
    19  	{q: Number{Real: nan, Imag: nan, Jmag: nan, Kmag: nan}, want: true},
    20  	{q: Number{Real: nan, Imag: 0, Jmag: 0, Kmag: 0}, want: true},
    21  	{q: Number{Real: 0, Imag: nan, Jmag: 0, Kmag: 0}, want: true},
    22  	{q: Number{Real: 0, Imag: 0, Jmag: nan, Kmag: 0}, want: true},
    23  	{q: Number{Real: 0, Imag: 0, Jmag: 0, Kmag: nan}, want: true},
    24  	{q: Number{Real: inf, Imag: nan, Jmag: nan, Kmag: nan}, want: false},
    25  	{q: Number{Real: nan, Imag: inf, Jmag: nan, Kmag: nan}, want: false},
    26  	{q: Number{Real: nan, Imag: nan, Jmag: inf, Kmag: nan}, want: false},
    27  	{q: Number{Real: nan, Imag: nan, Jmag: nan, Kmag: inf}, want: false},
    28  	{q: Number{Real: -inf, Imag: nan, Jmag: nan, Kmag: nan}, want: false},
    29  	{q: Number{Real: nan, Imag: -inf, Jmag: nan, Kmag: nan}, want: false},
    30  	{q: Number{Real: nan, Imag: nan, Jmag: -inf, Kmag: nan}, want: false},
    31  	{q: Number{Real: nan, Imag: nan, Jmag: nan, Kmag: -inf}, want: false},
    32  	{q: Number{}, want: false},
    33  }
    34  
    35  func TestIsNaN(t *testing.T) {
    36  	t.Parallel()
    37  	for _, test := range nanTests {
    38  		got := IsNaN(test.q)
    39  		if got != test.want {
    40  			t.Errorf("unexpected result for IsNaN(%v): got:%t want:%t", test.q, got, test.want)
    41  		}
    42  	}
    43  }