rantly 0.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +94 -0
- data/Gemfile +11 -0
- data/LICENSE +3 -0
- data/README.md +417 -0
- data/Rakefile +13 -30
- data/VERSION.yml +4 -4
- data/lib/rantly/data.rb +1 -1
- data/lib/rantly/generator.rb +126 -112
- data/lib/rantly/minitest.rb +1 -0
- data/lib/rantly/minitest_extensions.rb +15 -0
- data/lib/rantly/property.rb +60 -29
- data/lib/rantly/rspec.rb +1 -0
- data/lib/rantly/rspec_extensions.rb +8 -0
- data/lib/rantly/shrinks.rb +192 -0
- data/lib/rantly/silly.rb +42 -42
- data/lib/rantly/spec.rb +4 -4
- data/lib/rantly/testunit_extensions.rb +8 -0
- data/lib/rantly.rb +10 -2
- data/rantly.gemspec +36 -49
- data/test/rantly_test.rb +103 -225
- data/test/shrinks_test.rb +104 -0
- data/test/test_helper.rb +12 -8
- metadata +50 -45
- data/.gitignore +0 -5
- data/README.textile +0 -296
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 406db7ec111ce8f3580b6f76970b4baf110bae5926a5cc476f55ee435d857b4a
|
4
|
+
data.tar.gz: 5e42ee8b71cd692f7cd330fce8e3b65807ee9405afeb5ef2a847111da8ebefea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d83625897b4e83a7fed19c07922d2f456e14e69f86d56fdc0d13e7e0651ac71f28d897f2208815c383e602c7ab2093c3e28b33fd9b9eb957869764d117009c7a
|
7
|
+
data.tar.gz: d2362962331c07a90c37622ef9cef880de4cbb982daa04cc4cf5c38b178202616b6637527d03249e6941beeab588a57329fc982a09237041bdb231bbca467c9a
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to rantly will be documented in this file. The curated log begins at changes to version 0.4.0.
|
3
|
+
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [Master](https://github.com/rantly-rb/rantly/compare/2.0.0...master) (unreleased)
|
7
|
+
|
8
|
+
### New features
|
9
|
+
|
10
|
+
### Bug fixes
|
11
|
+
|
12
|
+
### Changes
|
13
|
+
|
14
|
+
|
15
|
+
## [2.0.0](https://github.com/rantly-rb/rantly/compare/1.2.0...2.0.0) - 2019-01-08
|
16
|
+
|
17
|
+
### New features
|
18
|
+
- Add support for float ranges to `range` generator
|
19
|
+
- [Issue #60](https://github.com/rantly-rb/rantly/issues/60)
|
20
|
+
- thanks [Trevor Brown][Trevor Brown]
|
21
|
+
|
22
|
+
### Bug fixes
|
23
|
+
- `range` generator returns `nil` for invalid ranges
|
24
|
+
- [Issue #60](https://github.com/rantly-rb/rantly/issues/60)
|
25
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
26
|
+
- `choose` generator returns `nil` when no values are given
|
27
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
28
|
+
|
29
|
+
### Changes
|
30
|
+
- Only support for Ruby >= 2.4 and JRuby >= 9.2
|
31
|
+
- [Issue #42](https://github.com/rantly-rb/rantly/issues/42) and [issue #37](https://github.com/rantly-rb/rantly/issues/37)
|
32
|
+
- Do not render all shrinking levels, only the failing case and the minimal failed data.
|
33
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
34
|
+
- Improve failure/success messages
|
35
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
36
|
+
|
37
|
+
|
38
|
+
## [1.2.0](https://github.com/abargnesi/rantly/compare/1.1.0...1.2.0) - 2018-08-29
|
39
|
+
### New features
|
40
|
+
- Allow to generate floats using Gaussian distribution
|
41
|
+
- [Issue #29](https://github.com/rantly-rb/rantly/issues/29)
|
42
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez] and [Víctor Gallego][Víctor Gallego]
|
43
|
+
### Bug fixes
|
44
|
+
- `NoMethodError` - undefined method `retry?` - when a test using `dict` fails
|
45
|
+
- [Issue #39](https://github.com/rantly-rb/rantly/issues/39)
|
46
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
47
|
+
### Changes
|
48
|
+
- Correct typo in _Too many tries_ message
|
49
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
50
|
+
|
51
|
+
|
52
|
+
## [1.1.0][1.1.0] - 2017-04-18
|
53
|
+
### Improved
|
54
|
+
- Include failed example and number of example run in failure message.
|
55
|
+
- [Issue #21][21]
|
56
|
+
- thanks [Ana María Martínez Gómez][Ana María Martínez Gómez]
|
57
|
+
- Improve run-time for generation of strings.
|
58
|
+
- [Issue #19][19]
|
59
|
+
|
60
|
+
## [1.0.0][1.0.0] - 2016-07-06
|
61
|
+
### Added
|
62
|
+
- Trying harder to shrink collections instead of giving up on first success of property.
|
63
|
+
- thanks [Eric Bischoff][Eric Bischoff]
|
64
|
+
- Added convenience classes Deflating and Tuple for more control on shrinking.
|
65
|
+
- thanks [Eric Bischoff][Eric Bischoff]
|
66
|
+
- Added usage examples for Deflating and Tuple shrinking strategies.
|
67
|
+
- thanks [Oleksii Fedorov][Oleksii Fedorov]
|
68
|
+
- `Property#check` will now use the `RANTLY_COUNT` environment variable to control the number of values generated.
|
69
|
+
- thanks [Jamie English][Jamie English]
|
70
|
+
|
71
|
+
### Major changes
|
72
|
+
- Array shrink was removed in favor of Tuple and Deflating.
|
73
|
+
|
74
|
+
## [0.3.2][0.3.2] - 2015-09-16
|
75
|
+
### Added
|
76
|
+
- Ability to shrink an object (`Integer`, `String`, `Array`, `Hash`). This is useful in finding the minimum value that fails a property check condition.
|
77
|
+
|
78
|
+
### Changed
|
79
|
+
- Improved RSpec and Minitest test extensions.
|
80
|
+
- Improved readability and execution of test suite.
|
81
|
+
- [Issue #4][4]
|
82
|
+
- Updates to documentation.
|
83
|
+
|
84
|
+
[1.0.0]: https://github.com/abargnesi/rantly/compare/0.3.2...1.0.0
|
85
|
+
[0.3.2]: https://github.com/abargnesi/rantly/compare/0.3.1...0.3.2
|
86
|
+
[4]: https://github.com/abargnesi/rantly/issues/4
|
87
|
+
[19]: https://github.com/abargnesi/rantly/issues/19
|
88
|
+
[21]: https://github.com/abargnesi/rantly/issues/21
|
89
|
+
[Eric Bischoff]: https://github.com/Bischoff
|
90
|
+
[Jamie English]: https://github.com/english
|
91
|
+
[Oleksii Fedorov]: https://github.com/waterlink
|
92
|
+
[Ana María Martínez Gómez]: https://github.com/Ana06
|
93
|
+
[Víctor Gallego]: https://github.com/vicgalle
|
94
|
+
[Trevor Brown]: https://github.com/Stratus3D
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,417 @@
|
|
1
|
+
[](https://badge.fury.io/rb/rantly)
|
2
|
+
[](https://travis-ci.org/rantly-rb/rantly)
|
3
|
+
[](https://coveralls.io/github/rantly-rb/rantly?branch=master)
|
4
|
+
|
5
|
+
# Imperative Random Data Generator and Quickcheck
|
6
|
+
|
7
|
+
You can use Rantly to generate random test data, and use its Test::Unit extension for property-based testing.
|
8
|
+
|
9
|
+
Rantly is basically a recursive descent interpreter, each of its method returns a random value of some type (string, integer, float, etc.).
|
10
|
+
|
11
|
+
Its implementation has no alien mathematics inside. Completely side-effect-free-free.
|
12
|
+
|
13
|
+

|
14
|
+
|
15
|
+
|
16
|
+
# Install
|
17
|
+
|
18
|
+
Rantly requires Ruby 3.2 or higher. To install Rantly add it to your Gemfile or run:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
$ gem install rantly
|
22
|
+
```
|
23
|
+
|
24
|
+
You can try it in the console by running:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
$ irb -rrantly
|
28
|
+
> Rantly { [integer,float] } # same as Rantly.value { integer }
|
29
|
+
=> [20991307, 0.025756845811823]
|
30
|
+
> Rantly { [integer,float]}
|
31
|
+
=> [-376856492, 0.452245765751706]
|
32
|
+
> Rantly(5) { integer } # same as Rantly.map(5) { integer }
|
33
|
+
=> [-1843396915550491870, -1683855015308353854, -2291347782549033959, -951461511269053584, 483265231542292652]
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
# Data Generation
|
38
|
+
|
39
|
+
## Getting Random Data Values
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Rantly#map(n,limit=10,&block)
|
43
|
+
call the generator n times, and collect values
|
44
|
+
Rantly#each(n,limit=10,&block)
|
45
|
+
call a random block n times
|
46
|
+
Rantly#value(limit=10,&block)
|
47
|
+
call a random block once, and get its value.
|
48
|
+
```
|
49
|
+
|
50
|
+
To collect an array of random data,
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# we want 5 random integers
|
54
|
+
> Rantly(5) { integer }
|
55
|
+
=> [-380638946, -29645239, 344840868, 308052180, -154360970]
|
56
|
+
```
|
57
|
+
|
58
|
+
To iterate over random data,
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
> Rantly.each(5) { puts integer }
|
62
|
+
296971291
|
63
|
+
504994512
|
64
|
+
-402790444
|
65
|
+
113152364
|
66
|
+
502842783
|
67
|
+
=> nil
|
68
|
+
```
|
69
|
+
|
70
|
+
To get one value of random data,
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
> Rantly { integer }
|
74
|
+
=> 278101042
|
75
|
+
```
|
76
|
+
|
77
|
+
The optional argument `limit` is used with generator guard. By default, if you want to generate n items, the generator tries at most n * 10 times.
|
78
|
+
|
79
|
+
This almost always succeeds,
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
> Rantly(5) { i = integer; guard i > 0; i }
|
83
|
+
=> [511765059, 250554234, 305947804, 127809156, 285960387]
|
84
|
+
```
|
85
|
+
|
86
|
+
This always fails,
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
> Rantly(10) { guard integer.is_a?(Float) }
|
90
|
+
Rantly::TooManyTries: Exceed gen limit 100: 101 failed guards)
|
91
|
+
```
|
92
|
+
|
93
|
+
## Random Generating Methods
|
94
|
+
|
95
|
+
The API is similiar to QuickCheck, but not exactly the same. In particular `choose` picks a random element from an array, and `range` picks a integer from an interval.
|
96
|
+
|
97
|
+
## Simple Randomness
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Rantly#integer(n=nil)
|
101
|
+
random positive or negative integer. Fixnum only.
|
102
|
+
Rantly#range(lo,hi)
|
103
|
+
random integer between lo and hi.
|
104
|
+
Rantly#float
|
105
|
+
random float
|
106
|
+
Rantly#boolean
|
107
|
+
true or false
|
108
|
+
Rantly#literal(value)
|
109
|
+
No-op. returns value.
|
110
|
+
Rantly#choose(*vals)
|
111
|
+
Pick one value from among vals.
|
112
|
+
```
|
113
|
+
|
114
|
+
## Meta Randomness
|
115
|
+
|
116
|
+
A rant generator is just a mini interpreter. It's often useful to go meta,
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
Rantly#call(gen)
|
120
|
+
If gen is a Symbol, just do a method call with send.
|
121
|
+
If gen is an Array, the first element of the array is the method name, the rest are args.
|
122
|
+
If gen is a Proc, instance_eval it with the generator.
|
123
|
+
```
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
> Rantly { call(:integer) }
|
127
|
+
=> -240998958
|
128
|
+
```
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
> Rantly { call([:range,0,10]) }
|
132
|
+
=> 2
|
133
|
+
```
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
> Rantly { call(Proc.new { [integer] })}
|
137
|
+
=> [522807620]
|
138
|
+
```
|
139
|
+
|
140
|
+
The `call` method is useful to implement other abstractions (See next subsection).
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
Rantly#branch(*args)
|
144
|
+
Pick a random arg among args, and Rantly#call it.
|
145
|
+
```
|
146
|
+
|
147
|
+
50-50 chance getting an integer or float,
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
> Rantly { branch :integer, :float }
|
151
|
+
=> 0.0489446702931332
|
152
|
+
> Rantly { branch :integer, :float }
|
153
|
+
=> 494934533
|
154
|
+
```
|
155
|
+
|
156
|
+
|
157
|
+
## Frequencies
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
Rantly#freq(*pairs)
|
161
|
+
Takes a list of 2-tuples, the first of which is the weight, and the second a Rantly#callable value, and returns a random value picked from the pairs. Follows the distribution pattern specified by the weights.
|
162
|
+
```
|
163
|
+
|
164
|
+
Twice as likely to get a float than integer. Never gets a ranged integer.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
> Rantly { freq [1,:integer], [2,:float], [0,:range,0,10] }
|
168
|
+
```
|
169
|
+
|
170
|
+
If the "pair" is not an array, but just a symbol, `freq` assumes that the weight is 1.
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
# 50-50 between integer and float
|
174
|
+
> Rantly { freq :integer, :float }
|
175
|
+
```
|
176
|
+
|
177
|
+
If a "pair" is an Array, but the first element is not an Integer, `freq` assumes that it's a Rantly method-call with arguments, and the weight is one.
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
# 50-50 chance generating integer limited by 10, or by 20.
|
181
|
+
> Rantly { freq [:integer,10], [:integer 20] }
|
182
|
+
```
|
183
|
+
|
184
|
+
|
185
|
+
## Sized Structure
|
186
|
+
|
187
|
+
A Rantly generator keeps track of how large a datastructure it should generate with its `size` attribute.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
Rantly#size
|
191
|
+
returns the current size
|
192
|
+
Rantly#sized(n,&block)
|
193
|
+
sets the size for the duration of recursive call of block. Block is instance_eval with the generator.
|
194
|
+
```
|
195
|
+
|
196
|
+
Rantly provides two methods that depends on the size
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
Rantly#array(size=default_size,&block)
|
200
|
+
returns a sized array consisted of elements by Rantly#calling random branches.
|
201
|
+
Rantly#string(char_class=:print)
|
202
|
+
returns a sized random string, consisted of only chars from a char_class.
|
203
|
+
Rantly#dict(size=default_size,&block)
|
204
|
+
returns a sized random hash. The generator block should generate tuples of keys and values (arrays that have two elements, the first one is used as key, and the second as value).
|
205
|
+
```
|
206
|
+
|
207
|
+
The avaiable char classes for strings are:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
:alnum
|
211
|
+
:alpha
|
212
|
+
:blank
|
213
|
+
:cntrl
|
214
|
+
:digit
|
215
|
+
:graph
|
216
|
+
:lower
|
217
|
+
:print
|
218
|
+
:punct
|
219
|
+
:space
|
220
|
+
:upper
|
221
|
+
:xdigit
|
222
|
+
:ascii
|
223
|
+
```
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
# sized 10 array of integers
|
227
|
+
> Rantly { array(10) { integer }}
|
228
|
+
=> [417733046, -375385433, 0.967812380000118, 26478621, 0.888588160450082, 250944144, 305584916, -151858342, 0.308123867823313, 0.316824642414253]
|
229
|
+
```
|
230
|
+
|
231
|
+
If you set the size once, it applies to all subsequent recursive structures. Here's a sized 10 array of sized 10 strings,
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
> Rantly { sized(10) { array {string}} }
|
235
|
+
=> ["1c}C/,9I#}", "hpA/UWPJ\\j", "H'~ERtI`|]", "%OUaW\\%uQZ", "Z2QdY=G~G!", "H<o|<FARGQ", "g>ojnxGDT3", "]a:L[B>bhb", "_Kl=&{tH^<", "ly]Yfb?`6c"]
|
236
|
+
```
|
237
|
+
|
238
|
+
Or a sized 10 array of sized 5 strings,
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
> Rantly {array(10){sized(5) {string}}}
|
242
|
+
=> ["S\"jf ", "d\\F-$", "-_8pa", "IN0iF", "SxRV$", ".{kQ7", "6>;fo", "}.D8)", "P(tS'", "y0v/v"]
|
243
|
+
```
|
244
|
+
|
245
|
+
Generate a hash that has 5 elements,
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
> Rantly { dict { [string,integer] }}
|
249
|
+
{"bR\\qHn"=>247003509502595457,
|
250
|
+
"-Mp '."=>653206579583741142,
|
251
|
+
"gY%<SV"=>-888111605212388599,
|
252
|
+
"+SMn:r"=>-1159506450084197716,
|
253
|
+
"^3gYfQ"=>-2154064981943219558,
|
254
|
+
"= :/\\,"=>433790301059833691}
|
255
|
+
```
|
256
|
+
|
257
|
+
The `dict` generator retries if a key is duplicated. If it fails to generate a unique key after too many tries, it gives up by raising an error:
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
> Rantly { dict { ["a",integer] }}
|
261
|
+
Rantly::TooManyTries: Exceed gen limit 60: 60 failed guards)
|
262
|
+
```
|
263
|
+
|
264
|
+
|
265
|
+
# Property Testing
|
266
|
+
|
267
|
+
Rantly extends Test::Unit and MiniTest::Test (5.0)/MiniTest::Unit::TestCase (< 5.0) for property testing. The extensions are in their own modules. So you need to require them explicitly:
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
require 'rantly/testunit_extensions' # for 'test/unit'
|
271
|
+
require 'rantly/minitest_extensions' # for 'minitest'
|
272
|
+
require 'rantly/rspec_extensions' # for RSpec
|
273
|
+
```
|
274
|
+
|
275
|
+
They define:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
Test::Unit::Assertions#property_of(&block)
|
279
|
+
The block is used to generate random data with a generator. The method returns a Rantly::Property instance, that has the method 'check'.
|
280
|
+
```
|
281
|
+
|
282
|
+
Property assertions within Test::Unit could be done like this,
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
# checks that integer only generates fixnum.
|
286
|
+
property_of {
|
287
|
+
integer
|
288
|
+
}.check { |i|
|
289
|
+
assert(i.is_a?(Integer), "integer property did not return Integer type")
|
290
|
+
}
|
291
|
+
```
|
292
|
+
|
293
|
+
Property assertions within Minitest could be done like this,
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
# checks that integer only generates fixnum.
|
297
|
+
property_of {
|
298
|
+
integer
|
299
|
+
}.check { |i|
|
300
|
+
assert_kind_of Integer, i, "integer property did not return Integer type"
|
301
|
+
}
|
302
|
+
```
|
303
|
+
|
304
|
+
Property assertions within RSpec could be done like this,
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
# checks that integer only generates fixnum.
|
308
|
+
it "integer property only returns Integer type" do
|
309
|
+
property_of {
|
310
|
+
integer
|
311
|
+
}.check { |i|
|
312
|
+
expect(i).to be_a(Integer)
|
313
|
+
}
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
317
|
+
The check block takes the generated data as its argument. One idiom I find useful is to include a parameter of the random data for the check argument. For example, if I want to check that Rantly#array generates the right sized array, I could say,
|
318
|
+
|
319
|
+
```ruby
|
320
|
+
property_of {
|
321
|
+
len = integer
|
322
|
+
[len,array(len){integer}]
|
323
|
+
}.check { |(len,arr)|
|
324
|
+
assert_equal len, arr.length
|
325
|
+
}
|
326
|
+
```
|
327
|
+
|
328
|
+
To control the number of property tests to generate, you have three options. In order of precedence:
|
329
|
+
|
330
|
+
1. Pass an integer argument to `check`
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
property_of {
|
334
|
+
integer
|
335
|
+
}.check(9000) { |i|
|
336
|
+
assert_kind_of Integer, i
|
337
|
+
}
|
338
|
+
```
|
339
|
+
|
340
|
+
2. Set the `RANTLY_COUNT` environment variable
|
341
|
+
|
342
|
+
```ruby
|
343
|
+
RANTLY_COUNT=9000 ruby my_property_test.rb
|
344
|
+
```
|
345
|
+
|
346
|
+
3. If neither of the above are set, the default will be to run the `check` block 100 times.
|
347
|
+
|
348
|
+
If you wish to have quiet output from Rantly, set environmental variable:
|
349
|
+
```ruby
|
350
|
+
RANTLY_VERBOSE=0 # silent
|
351
|
+
RANTLY_VERBOSE=1 # verbose and default if env is not set
|
352
|
+
```
|
353
|
+
This will silence the puts, print, and pretty_print statements in property.rb.
|
354
|
+
|
355
|
+
# Shrinking
|
356
|
+
|
357
|
+
Shrinking reduces the value of common types to some terminal lower bound. These functions are added to the Ruby types `Integer`, `String`, `Array`, and `Hash`.
|
358
|
+
|
359
|
+
For example a `String` is shrinkable until it is empty (e.g. `""`),
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
"foo".shrinkable? # => true
|
363
|
+
"foo".shrink # => "fo"
|
364
|
+
"fo".shrink # => "f"
|
365
|
+
"f".shrink # => ""
|
366
|
+
"".shrinkable? # => false
|
367
|
+
```
|
368
|
+
|
369
|
+
Shrinking allows `Property#check` to find a reduced value that still fails the condition. The value is not truely minimal because:
|
370
|
+
|
371
|
+
* we do not perform a complete in-depth traversal of the failure tree
|
372
|
+
* we limit the search to a maximum 1024 shrinking operations
|
373
|
+
|
374
|
+
but is usually reduced enough to start debugging.
|
375
|
+
|
376
|
+
Enable shrinking with
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
require 'rantly/shrinks'
|
380
|
+
```
|
381
|
+
|
382
|
+
Use `Tuple` class if you want an array whose elements are individually shrinked, but are not removed. Example:
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
property_of {
|
386
|
+
len = range(0, 10)
|
387
|
+
Tuple.new( array(len) { integer } )
|
388
|
+
}.check {
|
389
|
+
# .. property check here ..
|
390
|
+
}
|
391
|
+
```
|
392
|
+
|
393
|
+
Use `Deflating` class if you want an array whose elements are individully shrinked whenever possible, and removed otherwise. Example:
|
394
|
+
|
395
|
+
```ruby
|
396
|
+
property_of {
|
397
|
+
len = range(0, 10)
|
398
|
+
Deflating.new( array(len) { integer } )
|
399
|
+
}.check {
|
400
|
+
# .. property check here ..
|
401
|
+
}
|
402
|
+
```
|
403
|
+
|
404
|
+
Normal arrays or hashes are not shrinked.
|
405
|
+
|
406
|
+
|
407
|
+
# Contributors
|
408
|
+
|
409
|
+
Thanks to [all contributors](https://github.com/rantly-rb/rantly/graphs/contributors). :cupid: New contributors are welcome! :wink:
|
410
|
+
|
411
|
+
[Logotype](/logo) designed by: [@Richardbmx](https://github.com/richardbmx)
|
412
|
+
|
413
|
+
|
414
|
+
# License
|
415
|
+
|
416
|
+
Code published under MIT License, Copyright (c) 2009 Howard Yeh. See [LICENSE](/LICENSE).
|
417
|
+
|
data/Rakefile
CHANGED
@@ -1,51 +1,35 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake'
|
3
2
|
|
4
|
-
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "rantly"
|
8
|
-
gem.summary = %Q{Ruby Imperative Random Data Generator and Quickcheck}
|
9
|
-
gem.email = "hayeah@gmail.com"
|
10
|
-
gem.homepage = "http://github.com/hayeah/rantly"
|
11
|
-
gem.authors = ["Howard Yeh"]
|
12
|
-
|
13
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
-
end
|
15
|
-
rescue LoadError
|
16
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
-
end
|
3
|
+
task default: %i[test rubocop]
|
18
4
|
|
19
5
|
require 'rake/testtask'
|
6
|
+
|
20
7
|
Rake::TestTask.new(:test) do |test|
|
21
8
|
test.libs << 'lib' << 'test'
|
22
9
|
test.pattern = 'test/**/*_test.rb'
|
23
10
|
test.verbose = true
|
24
11
|
end
|
25
12
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
test.verbose = true
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
task :rcov do
|
35
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
-
end
|
13
|
+
require 'rubocop/rake_task'
|
14
|
+
|
15
|
+
desc 'Run RuboCop'
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.options = ['--display-cop-names']
|
37
18
|
end
|
38
19
|
|
20
|
+
RuboCop::RakeTask.new('rubocop:auto_gen_config') do |task|
|
21
|
+
task.options = ['--display-cop-names', '--auto-gen-config', '--auto-gen-only-exclude']
|
22
|
+
end
|
39
23
|
|
40
|
-
task
|
24
|
+
require 'rdoc/task'
|
41
25
|
|
42
|
-
require 'rake/rdoctask'
|
43
26
|
Rake::RDocTask.new do |rdoc|
|
27
|
+
require 'yaml'
|
44
28
|
if File.exist?('VERSION.yml')
|
45
29
|
config = YAML.load(File.read('VERSION.yml'))
|
46
30
|
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
31
|
else
|
48
|
-
version =
|
32
|
+
version = ''
|
49
33
|
end
|
50
34
|
|
51
35
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -53,4 +37,3 @@ Rake::RDocTask.new do |rdoc|
|
|
53
37
|
rdoc.rdoc_files.include('README*')
|
54
38
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
39
|
end
|
56
|
-
|
data/VERSION.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
---
|
2
|
-
:build:
|
3
|
-
:major:
|
4
|
-
:minor:
|
1
|
+
---
|
2
|
+
:build:
|
3
|
+
:major: 3
|
4
|
+
:minor: 0
|
5
5
|
:patch: 0
|