Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore the simple test #7

Merged
merged 1 commit into from
Nov 8, 2019
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