much-factory 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d589599e24247e2427e4c65151ce83ba44b72350234d3494db28cdb474f56b94
4
- data.tar.gz: fbb5c776815c9dd74c0b5e6af0d552868089a18cc47bbfa9fffddcd95280a572
3
+ metadata.gz: 9b387fe94e2dabf5a5ab3984c5523ecd6b63c4187bb6a0c806924a33e934fa10
4
+ data.tar.gz: 9e515898f2148d7df486ec257f16aaa193d0f4e09b646577f837b18666508a97
5
5
  SHA512:
6
- metadata.gz: 2b055422318f8c22e69a627e6f2ae4ed5dade088e97bfd0fe4db92c96648038105363d09b061987d67a3de51683daad4375289731e101bf78689ea07b06bcaa7
7
- data.tar.gz: a814cd8ed5d12a289e27eef8f16651f7ca68e6ccafb0796d16c4e7224ab94c4b25aef22e9871b63a6b2d071cd40ae8aff360081ac1d795b3d8af3304d1a1c29e
6
+ metadata.gz: 74fe55eed1841c17d93651ca81f129fcbea231821c537d22b416c3abbc7ea483b6ab16eda6a0c0167c52a5ab382cf22a431c98966366803a983b9f2d61ca7efd
7
+ data.tar.gz: 30f0f2d313000a701e5ec4ab65ef015173be0af72d7509810d1b565a29f5dd2f1f3c90eecf9ac104f187161930ef9040bfaaa58d77389044312197a47077cf22
data/lib/much-factory.rb CHANGED
@@ -12,8 +12,9 @@ module MuchFactory
12
12
  type_cast(Random.integer(max), :integer)
13
13
  end
14
14
 
15
- def float(max = nil)
16
- type_cast(Random.float(max), :float)
15
+ def float(max = nil, precision: Factory.integer(5))
16
+ factor = (10 ** precision).to_f
17
+ (type_cast(Random.float(max), :float) * factor).round / factor
17
18
  end
18
19
 
19
20
  DAYS_IN_A_YEAR = 365
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchFactory
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -39,6 +39,14 @@ module MuchFactory
39
39
  assert_that(float).equals(0.0)
40
40
  end
41
41
 
42
+ should "allow passing a precision using `float`" do
43
+ float = subject.float(2, precision: 2)
44
+ assert_that((float * 100).round / 100.0).equals(float)
45
+
46
+ float = subject.float(0, precision: 2)
47
+ assert_that(float).equals(0.00)
48
+ end
49
+
42
50
  should "return a random date using `date`" do
43
51
  assert_that(subject.date).is_kind_of(Date)
44
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-10 00:00:00.000000000 Z
12
+ date: 2021-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert