Skip to content

Commit

Permalink
Fix: Faker::Number.hexadecimal should include characters within the…
Browse files Browse the repository at this point in the history
… range of `[0-9a-f]` (#2942)

* Include 'f' character within Faker::Number.hexadecimal
  • Loading branch information
alextaujenis authored Apr 28, 2024
1 parent ff49989 commit 74b2a7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faker/default/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def digit
# @faker.version 1.0.0
def hexadecimal(digits: 6)
hex = ''
digits.times { hex += rand(15).to_s(16) }
digits.times { hex += rand(16).to_s(16) }
hex
end

Expand Down
7 changes: 7 additions & 0 deletions test/faker/default/test_faker_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def test_hexadecimal
assert_match(/[0-9a-f]{7}/, @tester.hexadecimal(digits: 7))
end

def test_hexadecimal_range
random_hex = @tester.hexadecimal(digits: 1000)
expected_range = Array('0'..'9') + Array('a'..'f')

expected_range.each { |char| assert_include(random_hex, char) }
end

def test_binary
assert_match(/^[0-1]{4}$/, @tester.binary(digits: 4))
assert_match(/^[0-1]{8}$/, @tester.binary(digits: 8))
Expand Down

0 comments on commit 74b2a7f

Please sign in to comment.