Skip to content

Commit 08dc129

Browse files
authored
Merge pull request #7 from lightstep/jmacd/typos_missing_files
Restore the simple test
2 parents 8fa9c70 + 2afca79 commit 08dc129

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

simple/simple_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2019, LightStep Inc.
2+
3+
package simple_test
4+
5+
import (
6+
"math/rand"
7+
"testing"
8+
9+
"github.com/lightstep/varopt/simple"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
type iRec int
14+
15+
func TestSimple(t *testing.T) {
16+
const (
17+
popSize = 1e6
18+
sampleProb = 0.1
19+
sampleSize int = popSize * sampleProb
20+
epsilon = 0.01
21+
)
22+
23+
rnd := rand.New(rand.NewSource(17167))
24+
25+
ss := simple.New(sampleSize, rnd)
26+
27+
psum := 0.
28+
for i := 0; i < popSize; i++ {
29+
ss.Add(iRec(i))
30+
psum += float64(i)
31+
}
32+
33+
require.Equal(t, ss.Size(), sampleSize)
34+
35+
ssum := 0.0
36+
for i := 0; i < sampleSize; i++ {
37+
ssum += float64(ss.Get(i).(iRec))
38+
}
39+
40+
require.InEpsilon(t, ssum/float64(ss.Size()), psum/popSize, epsilon)
41+
}

varopt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (s *Varopt) TotalCount() int {
171171
}
172172

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

0 commit comments

Comments
 (0)