Skip to content

Commit

Permalink
Added powerof2 example to test (godoc compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Nov 13, 2015
1 parent 598bd56 commit 2168a9e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions powerof2_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sample

import (
"fmt"
"math"
"testing"
)
Expand Down Expand Up @@ -107,3 +108,21 @@ func TestPowerOf2String(t *testing.T) {
t.Error("Expected: &{sampleState:{rate:1024 seed:0 sampleCount:1000 trueCount:100 rnd:<nil>}}, Got:", sampler.String())
}
}

func ExampleNewPowerOf2Seeded() {
s, err := NewPowerOf2Seeded(16, 0)
if err != nil {
fmt.Println("Unable to initialize sampler", err)
}
for i := 0; i < 100; i++ {
if s.Sample() {
fmt.Println(i, "got sampled by PowerOf2 sampler")
}
}
fmt.Println(Stats(s))
// Output:
// 26 got sampled by PowerOf2 sampler
// 45 got sampled by PowerOf2 sampler
// Rate: 16, SampleCount: 100, TrueCount: 2, Deviation: -212.5000%

}

0 comments on commit 2168a9e

Please sign in to comment.