prop_check 0.10.4 → 0.11.0

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: f8f707bae1dadf800e667376a749c7d5de3f3d741d13e63118de79dfb7233fb5
4
- data.tar.gz: e86ac3b096bff66cfa88c0a66b1fc8ea91dc8452ded41c417fb1452c33c2b1d7
3
+ metadata.gz: 6938e33edff09860d467d560675d04173ac8f44c487f65f22a4253bcad01a465
4
+ data.tar.gz: 1ed4f6b097d008461e251f285ad52fcd32dfce27cc306862b250cea45e0b954a
5
5
  SHA512:
6
- metadata.gz: e0985469e34e0b353aab0fac657a073fadfe135c03029187d3f7824ebded0bfd244122aa2ae4361b5ccad3fb05ca52162e3967e9f46a6e43674e7d7626a700f7
7
- data.tar.gz: 0b0505768ea68855beaf9c8954cb973215dd392c40975e7f581e7faa9d7570c9e4fb76402227c5b0f223f96e87f72d58decfb7dffd2744897c22db3ba0959ac6
6
+ metadata.gz: e8d7498c00b09f17ec90fced0b130158e1919270837bad1af82ca7f4140f8904816c377cdd3489aea38d6ef36b911a128a92ca956c598daf9f0f88654ca4ac64
7
+ data.tar.gz: b05e4c9364808468af3c5b9807cc8cc8e036a780e449efd0468f7b577853bd3a286371a3312073c0cf5952c5debb12dd6b13ad2d3e8d0fed0952839db680757c
@@ -100,17 +100,15 @@ module PropCheck
100
100
  def map(&proc)
101
101
  Generator.new do |size, rng|
102
102
  result = self.generate(size, rng)
103
- result.map do |*val|
104
- proc.call(*val)
105
- end
103
+ result.map(&proc)
106
104
  end
107
105
  end
108
106
 
109
107
  ##
110
108
  # Creates a new Generator that only produces a value when the block `condition` returns a truthy value.
111
109
  def where(&condition)
112
- self.map do |*result|
113
- if condition.call(*result)
110
+ self.map do |result|
111
+ if condition.call(result)
114
112
  result
115
113
  else
116
114
  :"_PropCheck.filter_me"
@@ -227,19 +227,45 @@ module PropCheck
227
227
  # is generated by `element_generator`.
228
228
  #
229
229
  # Shrinks to shorter arrays (with shrunken elements).
230
+ # Accepted keyword arguments:
230
231
  #
232
+ # `empty:` When false, behaves the same as `min: 1`
233
+ # `min:` Ensures at least this many elements are generated. (default: 0)
234
+ # `max:` Ensures at most this many elements are generated. When nil, an arbitrary count is used instead. (default: nil)
235
+ #
236
+ #
237
+ # >> Generators.array(Generators.positive_integer).sample(5, size: 1, rng: Random.new(42))
238
+ # => [[2], [2], [2], [1], [2]]
231
239
  # >> Generators.array(Generators.positive_integer).sample(5, size: 10, rng: Random.new(42))
232
240
  # => [[10, 5, 1, 4], [5, 9, 1, 1, 11, 8, 4, 9, 11, 10], [6], [11, 11, 2, 2, 7, 2, 6, 5, 5], [2, 10, 9, 7, 9, 5, 11, 3]]
233
- def array(element_generator)
234
- nonnegative_integer.bind do |generator|
235
- generators = (0...generator).map do
241
+ #
242
+ # >> Generators.array(Generators.positive_integer, empty: true).sample(5, size: 1, rng: Random.new(1))
243
+ # => [[], [2], [], [], [2]]
244
+ # >> Generators.array(Generators.positive_integer, empty: false).sample(5, size: 1, rng: Random.new(1))
245
+ # => [[2], [1], [2], [1], [1]]
246
+
247
+
248
+ def array(element_generator, min: 0, max: nil, empty: true)
249
+ min = 1 if min.zero? && !empty
250
+
251
+ res = proc do |count|
252
+ count = min + 1 if count < min
253
+ count += 1 if count == min && min != 0
254
+ generators = (min...count).map do
236
255
  element_generator.clone
237
256
  end
238
257
 
239
258
  tuple(*generators)
240
259
  end
260
+
261
+ if max.nil?
262
+ nonnegative_integer.bind(&res)
263
+ else
264
+ proc.call(max)
265
+ end
241
266
  end
242
267
 
268
+
243
269
  ##
244
270
  # Generates a hash of key->values,
245
271
  # where each of the keys is made using the `key_generator`
@@ -249,8 +275,8 @@ module PropCheck
249
275
  #
250
276
  # >> Generators.hash(Generators.printable_ascii_string, Generators.positive_integer).sample(5, size: 3, rng: Random.new(42))
251
277
  # => [{""=>2, "g\\4"=>4, "rv"=>2}, {"7"=>2}, {"!"=>1, "E!"=>1}, {"kY5"=>2}, {}]
252
- def hash(key_generator, value_generator)
253
- array(tuple(key_generator, value_generator))
278
+ def hash(key_generator, value_generator, **kwargs)
279
+ array(tuple(key_generator, value_generator), **kwargs)
254
280
  .map(&:to_h)
255
281
  end
256
282
 
@@ -276,8 +302,8 @@ module PropCheck
276
302
  #
277
303
  # >> Generators.alphanumeric_string.sample(5, size: 10, rng: Random.new(42))
278
304
  # => ["ZCoQ", "8uM", "wkkx0JNx", "v0bxRDLb", "Gl5v8RyWA6"]
279
- def alphanumeric_string
280
- array(alphanumeric_char).map(&:join)
305
+ def alphanumeric_string(**kwargs)
306
+ array(alphanumeric_char, **kwargs).map(&:join)
281
307
  end
282
308
 
283
309
  @printable_ascii_chars = (' '..'~').to_a.freeze
@@ -302,8 +328,8 @@ module PropCheck
302
328
  #
303
329
  # >> Generators.printable_ascii_string.sample(5, size: 10, rng: Random.new(42))
304
330
  # => ["S|.g", "rvjjw7\"5T!", "=", "!_[4@", "Y"]
305
- def printable_ascii_string
306
- array(printable_ascii_char).map(&:join)
331
+ def printable_ascii_string(**kwargs)
332
+ array(printable_ascii_char, **kwargs).map(&:join)
307
333
  end
308
334
 
309
335
  @ascii_chars = [
@@ -341,8 +367,8 @@ module PropCheck
341
367
  #
342
368
  # >> Generators.ascii_string.sample(5, size: 10, rng: Random.new(42))
343
369
  # => ["S|.g", "drvjjw\b\a7\"", "!w=E!_[4@k", "x", "zZI{[o"]
344
- def ascii_string
345
- array(ascii_char).map(&:join)
370
+ def ascii_string(**kwargs)
371
+ array(ascii_char, **kwargs).map(&:join)
346
372
  end
347
373
 
348
374
  @printable_chars = [
@@ -372,8 +398,8 @@ module PropCheck
372
398
  #
373
399
  # >> Generators.printable_string.sample(5, size: 10, rng: Random.new(42))
374
400
  # => ["", "Ȍ", "𐁂", "Ȕ", ""]
375
- def printable_string
376
- array(printable_char).map(&:join)
401
+ def printable_string(**kwargs)
402
+ array(printable_char, **kwargs).map(&:join)
377
403
  end
378
404
 
379
405
  ##
@@ -398,8 +424,8 @@ module PropCheck
398
424
  #
399
425
  # >> Generators.string.sample(5, size: 10, rng: Random.new(42))
400
426
  # => ["\u{A3DB3}𠍜\u{3F46A}\u{1AEBC}", "􍙦𡡹󴇒\u{DED74}𪱣\u{43E97}ꂂ\u{50695}􏴴\u{C0301}", "\u{4FD9D}", "\u{C14BF}\u{193BB}𭇋󱣼\u{76B58}", "𦐺\u{9FDDB}\u{80ABB}\u{9E3CF}𐂽\u{14AAE}"]
401
- def string
402
- array(char).map(&:join)
427
+ def string(**kwargs)
428
+ array(char, **kwargs).map(&:join)
403
429
  end
404
430
 
405
431
  ##
@@ -1,3 +1,3 @@
1
1
  module PropCheck
2
- VERSION = '0.10.4'
2
+ VERSION = '0.11.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prop_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qqwy/Wiebe-Marten Wijnja