Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Allow charRange.choose to pick the last rune
Browse files Browse the repository at this point in the history
Before this change, choose would never pick the last character of the set. This
is not the expected behavior: if the range is a-z, we expect a,b,...,y,z to be
picked in a uniform way.
  • Loading branch information
punkeel committed Feb 9, 2020
1 parent 25ae8f6 commit df5e810
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ type charRange struct {
// choose returns a random unicode character from the given range, using the
// given randomness source.
func (cr charRange) choose(r int63nPicker) rune {
count := int64(cr.last - cr.first)
count := int64(cr.last - cr.first + 1)
return cr.first + rune(r.Int63n(count))
}

Expand Down
4 changes: 2 additions & 2 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ func Test_charRange_choose(t *testing.T) {
t.Run("Picks last", func(t *testing.T) {
r := alwaysLast{}
letter := lowercaseLetters.choose(r)
if letter != 'y' {
t.Errorf("Expected y, got %v", letter)
if letter != 'z' {
t.Errorf("Expected z, got %v", letter)
}
})
}

0 comments on commit df5e810

Please sign in to comment.