File: gen_parameter_test.go

package info (click to toggle)
golang-github-leanovate-gopter 0.2.9%2Bgit20210201.bbbf00e-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 696 kB
  • sloc: makefile: 37
file content (63 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package gopter_test

import (
	"math/rand"
	"testing"

	"github.com/leanovate/gopter"
)

type fixedSeed struct {
	fixed int64
}

func (f *fixedSeed) Int63() int64    { return f.fixed }
func (f *fixedSeed) Seed(seed int64) { f.fixed = seed }

func TestGenParameters(t *testing.T) {
	parameters := &gopter.GenParameters{
		MaxSize: 100,
		Rng:     rand.New(&fixedSeed{}),
	}

	if !parameters.NextBool() {
		t.Error("Bool should be true")
	}
	if parameters.NextInt64() != 0 {
		t.Error("int64 should be 0")
	}
	if parameters.NextUint64() != 0 {
		t.Error("uint64 should be 0")
	}

	parameters.Rng.Seed(1)
	if parameters.NextBool() {
		t.Error("Bool should be false")
	}
	if parameters.NextInt64() != 1 {
		t.Error("int64 should be 1")
	}
	if parameters.NextUint64() != 3 {
		t.Error("uint64 should be 3")
	}

	parameters.Rng.Seed(2)
	if !parameters.NextBool() {
		t.Error("Bool should be true")
	}
	if parameters.NextInt64() != -2 {
		t.Error("int64 should be -2")
	}
	if parameters.NextUint64() != 6 {
		t.Error("uint64 should be 6")
	}

	param1 := parameters.CloneWithSeed(1024)
	param2 := parameters.CloneWithSeed(1024)

	for i := 0; i < 100; i++ {
		if param1.NextInt64() != param2.NextInt64() {
			t.Error("cloned parameters create different random numbers")
		}
	}
}