github.com/gopherd/gonum@v0.0.4/internal/testrand/extreme_test.go (about)

     1  // Copyright ©2020 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 testrand
     6  
     7  import (
     8  	"math"
     9  	"testing"
    10  
    11  	"math/rand"
    12  )
    13  
    14  func TestExtreme_NaN(t *testing.T) {
    15  	src := rand.NewSource(1)
    16  	rnd := rand.New(src)
    17  	ext := newExtreme(0, 1, rnd)
    18  
    19  	check64 := func(v float64) {
    20  		if !math.IsNaN(v) {
    21  			t.Errorf("expected NaN, got %v", v)
    22  		}
    23  	}
    24  	check32 := func(v float32) {
    25  		if !math.IsNaN(float64(v)) {
    26  			t.Errorf("expected NaN, got %v", v)
    27  		}
    28  	}
    29  
    30  	check64(ext.ExpFloat64())
    31  	check64(ext.Float64())
    32  	check64(ext.NormFloat64())
    33  	check32(ext.Float32())
    34  }