File: uniform_test.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (33 lines) | stat: -rw-r--r-- 720 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package distmv

import (
	"math"
	"testing"

	"gonum.org/v1/gonum/spatial/r1"
)

func TestUniformEntropy(t *testing.T) {
	for _, test := range []struct {
		Uniform *Uniform
		Entropy float64
	}{
		{
			NewUniform([]r1.Interval{{Min: 0, Max: 1}, {Min: 0, Max: 1}}, nil),
			0,
		},
		{
			NewUniform([]r1.Interval{{Min: -1, Max: 3}, {Min: 2, Max: 8}, {Min: -5, Max: -3}}, nil),
			math.Log(48),
		},
	} {
		ent := test.Uniform.Entropy()
		if math.Abs(ent-test.Entropy) > 1e-14 {
			t.Errorf("Entropy mismatch. Got %v, want %v", ent, test.Entropy)
		}
	}
}