Skip to content

Commit

Permalink
Added decrement example to test (godoc compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Nov 12, 2015
1 parent c266014 commit 598bd56
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions decrement_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 @@ -91,3 +92,28 @@ func TestDecrementString(t *testing.T) {
t.Error("Expected: &{sampleState:{rate:10 seed:0 sampleCount:1000 trueCount:100 rnd:<nil>} count:0}, Got:", sampler.String())
}
}

func ExampleNewDecrementSeeded() {
s, err := NewDecrementSeeded(10, 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 Decrement sampler")
}
}
fmt.Println(Stats(s))
// Output:
// 5 got sampled by Decrement sampler
// 23 got sampled by Decrement sampler
// 31 got sampled by Decrement sampler
// 37 got sampled by Decrement sampler
// 45 got sampled by Decrement sampler
// 63 got sampled by Decrement sampler
// 68 got sampled by Decrement sampler
// 79 got sampled by Decrement sampler
// 87 got sampled by Decrement sampler
// Rate: 10, SampleCount: 100, TrueCount: 9, Deviation: -11.1111%

}

0 comments on commit 598bd56

Please sign in to comment.