github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/stat/distmv/uniform_test.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 distmv 6 7 import ( 8 "math" 9 "testing" 10 11 "github.com/jingcheng-WU/gonum/spatial/r1" 12 ) 13 14 func TestUniformEntropy(t *testing.T) { 15 for _, test := range []struct { 16 Uniform *Uniform 17 Entropy float64 18 }{ 19 { 20 NewUniform([]r1.Interval{{Min: 0, Max: 1}, {Min: 0, Max: 1}}, nil), 21 0, 22 }, 23 { 24 NewUniform([]r1.Interval{{Min: -1, Max: 3}, {Min: 2, Max: 8}, {Min: -5, Max: -3}}, nil), 25 math.Log(48), 26 }, 27 } { 28 ent := test.Uniform.Entropy() 29 if math.Abs(ent-test.Entropy) > 1e-14 { 30 t.Errorf("Entropy mismatch. Got %v, want %v", ent, test.Entropy) 31 } 32 } 33 }