8000 Adds FFaker::Number.between by professor · Pull Request #535 · ffaker/ffaker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds FFaker::Number.between #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ffaker/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def decimal(whole_digits: 1, fractional_digits: 1)
FFaker.numerify("#{whole_part_pattern}.#{fractional_part_pattern}").to_f
end

def between(from: 1.00, to: 5000.00)
fetch_sample(from..to)
end

private

def generate_pattern(digits)
Expand Down
14 changes: 13 additions & 1 deletion test/test_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class TestNumber < Test::Unit::TestCase
include DeterministicHelper

assert_methods_are_deterministic(FFaker::Number, :number, :decimal)
assert_methods_are_deterministic(FFaker::Number, :number, :decimal, :between)

def setup
@tester = FFaker::Number
Expand Down Expand Up @@ -42,4 +42,16 @@ def test_decimal_when_invalid_argument
@tester.decimal(fractional_digits: 0)
end
end

def test_between
from = -50
to = 50
assert_random_between(from..to) { @tester.between(from: from, to: to) }
assert_instance_of Integer, @tester.between(from: from, to: to)

from = -50.0
to = 50.0
assert_random_between(from..to) { @tester.between(from: from, to: to) }
assert_instance_of Float, @tester.between(from: from, to: to)
end
end
0