Skip to content

Commit

Permalink
Merge pull request #7 from lightstep/jmacd/typos_missing_files
Browse files Browse the repository at this point in the history
Restore the simple test
  • Loading branch information
jmacd authored Nov 8, 2019
2 parents 8fa9c70 + 2afca79 commit 08dc129
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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

0 comments on commit 08dc129

Please sign in to comment.