Skip to content

Commit

Permalink
Moved LessThan example to test (godoc compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Nov 10, 2015
1 parent bd2b3bf commit 72af4c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ _testmain.go
*.out

# gogitignore start
example/example
# gogitignore end
19 changes: 0 additions & 19 deletions example/example.go

This file was deleted.

22 changes: 22 additions & 0 deletions lessthan_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,24 @@ func TestLessThanString(t *testing.T) {
t.Error("Expected: &{sampleState:{rate:10 seed:0 sampleCount:1000 trueCount:100 rnd:<nil>} boundary:1844674407370955161}, Got:", sampler.String())
}
}

func ExampleNewLessThanSeeded() {
s, err := NewLessThanSeeded(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 LessThan sampler")
}
}
fmt.Println(Stats(s))
// Output:
// 25 got sampled by LessThan sampler
// 27 got sampled by LessThan sampler
// 29 got sampled by LessThan sampler
// 43 got sampled by LessThan sampler
// 54 got sampled by LessThan sampler
// 73 got sampled by LessThan sampler
// Rate: 10, SampleCount: 100, TrueCount: 6, Deviation: -66.6667%
}

0 comments on commit 72af4c4

Please sign in to comment.