github.com/jgbaldwinbrown/perf@v0.1.1/pkg/stats/normaldist_test.go (about)

     1  // Copyright 2015 The Go 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 stats
     6  
     7  import (
     8  	"fmt"
     9  	"math"
    10  	"testing"
    11  )
    12  
    13  func TestNormalDist(t *testing.T) {
    14  	d := StdNormal
    15  
    16  	testFunc(t, fmt.Sprintf("%+v.PDF", d), d.PDF, map[float64]float64{
    17  		-10000: 0, // approx
    18  		-1:     1 / math.Sqrt(2*math.Pi) * math.Exp(-0.5),
    19  		0:      1 / math.Sqrt(2*math.Pi),
    20  		1:      1 / math.Sqrt(2*math.Pi) * math.Exp(-0.5),
    21  		10000:  0, // approx
    22  	})
    23  
    24  	testFunc(t, fmt.Sprintf("%+v.CDF", d), d.CDF, map[float64]float64{
    25  		-10000: 0, // approx
    26  		0:      0.5,
    27  		10000:  1, // approx
    28  	})
    29  
    30  	d2 := NormalDist{Mu: 2, Sigma: 5}
    31  	testInvCDF(t, d, false)
    32  	testInvCDF(t, d2, false)
    33  }