github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/gnum/gnum_test.go (about)

     1  package gnum
     2  
     3  import "testing"
     4  
     5  func TestEntropy(t *testing.T) {
     6  	input1 := []int{1, 2, 3, 4}
     7  	input2 := []uint{1, 2, 3, 4}
     8  	input3 := []float32{1, 2, 3, 4}
     9  	input4 := []float64{1, 2, 3, 4}
    10  	want := 1.8464393
    11  	if got := Entropy(input1); Diff(got, want) > 0.00000005 {
    12  		t.Errorf("Entropy(%v)=%v, want %v", input1, got, want)
    13  	}
    14  	if got := Entropy(input2); Diff(got, want) > 0.00000005 {
    15  		t.Errorf("Entropy(%v)=%v, want %v", input2, got, want)
    16  	}
    17  	if got := Entropy(input3); Diff(got, want) > 0.00000005 {
    18  		t.Errorf("Entropy(%v)=%v, want %v", input3, got, want)
    19  	}
    20  	if got := Entropy(input4); Diff(got, want) > 0.00000005 {
    21  		t.Errorf("Entropy(%v)=%v, want %v", input4, got, want)
    22  	}
    23  }