Skip to content

Commit

Permalink
testing/quick: use Uint64 instead of Int63
Browse files Browse the repository at this point in the history
Followup to CL 39152.

Change-Id: I9bfed0c6071ea3d3a43294a6c4a50edc131368cf
Reviewed-on: https://go-review.googlesource.com/39313
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
rsc committed Apr 5, 2017
1 parent 476f55f commit a7b51cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/testing/quick/quick.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ func randFloat64(rand *rand.Rand) float64 {

// randInt64 returns a random int64.
func randInt64(rand *rand.Rand) int64 {
x := rand.Int63() - 1<<62
// x in [-2⁶²,2⁶²), so top two bits are 00 or 11, never 10 or 01.
// Mix in some bits from the middle.
x ^= x<<29 ^ x<<43
return x
return int64(rand.Uint64())
}

// complexSize is the maximum length of arbitrary values that contain other
Expand Down
18 changes: 18 additions & 0 deletions src/testing/quick/quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,21 @@ func TestNonZeroSliceAndMap(t *testing.T) {
t.Fatal(err)
}
}

func TestInt64(t *testing.T) {
var lo, hi int64
f := func(x int64) bool {
if x < lo {
lo = x
}
if x > hi {
hi = x
}
return true
}
cfg := &Config{MaxCount: 100000}
Check(f, cfg)
if uint64(lo)>>62 == 0 || uint64(hi)>>62 == 0 {
t.Errorf("int64 returned range %#016x,%#016x; does not look like full range", lo, hi)
}
}

0 comments on commit a7b51cf

Please sign in to comment.