Skip to content

Commit

Permalink
Use fixed seed for one_of_test and weighted_test
Browse files Browse the repository at this point in the history
  • Loading branch information
untoldwind committed Feb 1, 2021
1 parent 9abe234 commit 8868e78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion gen/one_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ func TestOneGenOf(t *testing.T) {
}

func commonOneOfTest(t *testing.T, gen gopter.Gen) {
parameters := gopter.DefaultGenParameters()
parameters.Rng.Seed(1234)

generated := make(map[string]bool, 0)
for i := 0; i < 100; i++ {
value, ok := gen.Sample()
value, ok := gen(parameters).Retrieve()

if !ok || value == nil {
t.Errorf("Invalid consts: %#v", value)
Expand Down
6 changes: 5 additions & 1 deletion gen/weighted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package gen_test
import (
"testing"

"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
)

func TestWeighted(t *testing.T) {
parameters := gopter.DefaultGenParameters()
parameters.Rng.Seed(1234)

weighted := gen.Weighted([]gen.WeightedGen{
{Weight: 1, Gen: gen.Const("A")},
{Weight: 2, Gen: gen.Const("B")},
{Weight: 7, Gen: gen.Const("C")},
})
results := make(map[string]int)
for i := int64(0); i < int64(1000); i++ {
result, ok := weighted.Sample()
result, ok := weighted(parameters).Retrieve()
if !ok {
t.FailNow()
}
Expand Down

0 comments on commit 8868e78

Please sign in to comment.