Skip to content

Commit

Permalink
Adds FFaker::Number.between (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
professor committed Aug 30, 2023
1 parent 4bb1f08 commit 58c0f02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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 comments on commit 58c0f02

Please sign in to comment.