Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions simple/simple_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019, LightStep Inc.

package simple_test

import (
"math/rand"
"testing"

"github.com/lightstep/varopt/simple"
"github.com/stretchr/testify/require"
)

type iRec int

func TestSimple(t *testing.T) {
const (
popSize = 1e6
sampleProb = 0.1
sampleSize int = popSize * sampleProb
epsilon = 0.01
)

rnd := rand.New(rand.NewSource(17167))

ss := simple.New(sampleSize, rnd)

psum := 0.
for i := 0; i < popSize; i++ {
ss.Add(iRec(i))
psum += float64(i)
}

require.Equal(t, ss.Size(), sampleSize)

ssum := 0.0
for i := 0; i < sampleSize; i++ {
ssum += float64(ss.Get(i).(iRec))
}

require.InEpsilon(t, ssum/float64(ss.Size()), psum/popSize, epsilon)
}
2 changes: 1 addition & 1 deletion varopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (s *Varopt) TotalCount() int {
}

// Tau returns the current large-weight threshold. Weights larger
// than Tau() carry their exact weight int he sample. See the VarOpt
// than Tau() carry their exact weight in the sample. See the VarOpt
// paper for details.
func (s *Varopt) Tau() float64 {
return s.tau
Expand Down