-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lightstep/jmacd/typos_missing_files
Restore the simple test
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters