quick-sampler 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 62a7ce51aa6d063591fd221700c752755c531b3a
4
- data.tar.gz: af103d57ff121544eca0b37fd9a1d10925323404
3
+ metadata.gz: 166249b4d99f3c75f161df7c7fcef6b0b544d407
4
+ data.tar.gz: efe98dc471d9e954c0159475dd2c13a8ea60c40a
5
5
  SHA512:
6
- metadata.gz: eee6f10bf27b120548fc945bbd6f923c2f390c28a2d0d665f895fbdcf1d21d202cb649d1c9ad5e23d8f197ba417a93d26af58ee8a4e9cec9c62f518ed37c6944
7
- data.tar.gz: ce4903abb8581d3801a4b513d9a1c60a8bf6934827b379e743d71135354e3190a25a6470aa0352a624594a3750f3b0117160ca4781c897544a9024fb1af258ea
6
+ metadata.gz: 1811619ab4d68251fd2f36ebf7bf23642288162dda1b2e24654e88141b69d543b72366ecd85134e8e93075873716a6547c794c7dfaa1dd8fc06a09df2cdfff17
7
+ data.tar.gz: 169017a885dc058a33b6cea98587c59824f6e97e9ed82c17ce121ad2a9f753bb5f47823a5a30649a9fb8ab8766dd25f957fd47bf7c62389af3dddc114952e18b
@@ -35,7 +35,7 @@ module Quick
35
35
  # iterating when that many original values are tested.
36
36
  #
37
37
  # @return [Quick::Sampler]
38
- # a sampler that filter through only samples that satisfy the
38
+ # a sampler that passes through only samples that satisfy the
39
39
  # predicate given as block
40
40
  # @yieldparam [Anything] sample
41
41
  # a sampled value to be tested
@@ -44,6 +44,21 @@ module Quick
44
44
  def such_that &predicate
45
45
  spawn(unwrap.take(max_iterations).select(&predicate))
46
46
  end
47
+
48
+ # spawn a mapping sampler
49
+ #
50
+ # The produced sampler will yield each original sample to the block and return block
51
+ # result instead.
52
+ #
53
+ # @return [Quick::Sampler]
54
+ # a sampler that maps each original sample through the block
55
+ # @yieldparam [Anything] sample
56
+ # the original sample
57
+ # @yieldreturn [Anything]
58
+ # the mapped sample to return
59
+ def map &block
60
+ spawn(unwrap.map(&block))
61
+ end
47
62
  end
48
63
  end
49
64
  end
@@ -15,8 +15,8 @@ module Quick
15
15
  case source
16
16
  when Range
17
17
  feed { rand(source) }
18
- when Array
19
- feed { source.sample }
18
+ else
19
+ feed { source.to_a.sample }
20
20
  end
21
21
  end
22
22
 
@@ -124,6 +124,16 @@ module Quick
124
124
  }
125
125
  end
126
126
 
127
+ # Arbitrary object sampler.
128
+ #
129
+ # @param [Class, Quick::Sampler<Class>] the_class
130
+ # a class of the object to create (or a sampler producing classes)
131
+ # @param [*Anything] *args
132
+ # arguments to pass to the constructor (may contain samplers)
133
+ def object_like the_class, *args
134
+ send_to(the_class, :new, *args)
135
+ end
136
+
127
137
  private
128
138
 
129
139
  def recursive_sample value
@@ -1,5 +1,5 @@
1
1
  module Quick
2
2
  module Sampler
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick-sampler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Baguinski