rantly 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -9
- data/VERSION.yml +1 -1
- data/lib/rantly.rb +8 -0
- data/lib/rantly/generator.rb +2 -2
- data/lib/rantly/silly.rb +2 -2
- data/rantly.gemspec +2 -2
- data/test/rantly_test.rb +6 -6
- metadata +2 -2
data/README.textile
CHANGED
@@ -194,7 +194,7 @@ Rant#sized(n,&block)
|
|
194
194
|
Rant provides two methods that depends on the size
|
195
195
|
|
196
196
|
<pre><code>
|
197
|
-
Rant#array(
|
197
|
+
Rant#array(size=default_size)
|
198
198
|
returns a sized array consisted of elements by Rant#calling random branches.
|
199
199
|
Rant#string(char_class=:print)
|
200
200
|
returns a sized random string, consisted of only chars from a char_class.
|
@@ -220,13 +220,8 @@ The avaiable char classes for strings are:
|
|
220
220
|
|
221
221
|
<pre><code>
|
222
222
|
# sized 10 array of integer or float
|
223
|
-
> gen.value {
|
223
|
+
> gen.value { array(10) { branch(:integer,:float)}}
|
224
224
|
=> [417733046, -375385433, 0.967812380000118, 26478621, 0.888588160450082, 250944144, 305584916, -151858342, 0.308123867823313, 0.316824642414253]
|
225
|
-
|
226
|
-
# fails if you forget to set the size.
|
227
|
-
> gen.value { array(:integer,:float)}
|
228
|
-
RuntimeError: size not set
|
229
|
-
|
230
225
|
</code></pre>
|
231
226
|
|
232
227
|
If you set the size once, it applies to all subsequent recursive structures. Here's a sized 10 array of sized 10 strings,
|
@@ -239,7 +234,7 @@ If you set the size once, it applies to all subsequent recursive structures. Her
|
|
239
234
|
Or a sized 10 array of sized 5 strings,
|
240
235
|
|
241
236
|
<pre><code>
|
242
|
-
> gen.value {
|
237
|
+
> gen.value { array(10) { array(5) { string}}}
|
243
238
|
=> ["S\"jf ", "d\\F-$", "-_8pa", "IN0iF", "SxRV$", ".{kQ7", "6>;fo", "}.D8)", "P(tS'", "y0v/v"]
|
244
239
|
</code></pre>
|
245
240
|
|
@@ -281,7 +276,7 @@ The check block takes the generated data as its argument. One idiom I find usefu
|
|
281
276
|
should "generate right sized array" do
|
282
277
|
property_of {
|
283
278
|
len = integer
|
284
|
-
[len,
|
279
|
+
[len,array(len){integer}]
|
285
280
|
}.check { |(len,arr)|
|
286
281
|
assert_equal len, arr.length
|
287
282
|
}
|
data/VERSION.yml
CHANGED
data/lib/rantly.rb
CHANGED
data/lib/rantly/generator.rb
CHANGED
data/lib/rantly/silly.rb
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
module Rantly::Silly::Love
|
11
11
|
|
12
12
|
def letter(n=3)
|
13
|
-
body =
|
13
|
+
body = array(n){paragraph}.join "\n\n"
|
14
14
|
<<-EOS
|
15
15
|
#{address}:
|
16
16
|
|
@@ -43,7 +43,7 @@ EOS
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def paragraph
|
46
|
-
|
46
|
+
array(range(2,4)){ sentence}.join " "
|
47
47
|
end
|
48
48
|
|
49
49
|
def sentence
|
data/rantly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rantly}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Howard Yeh"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-12}
|
13
13
|
s.email = %q{hayeah@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
data/test/rantly_test.rb
CHANGED
@@ -189,14 +189,14 @@ class RantlyTest::Generator < Test::Unit::TestCase
|
|
189
189
|
assert o == 1 || o == 2
|
190
190
|
}
|
191
191
|
property_of {
|
192
|
-
arr = sized(10) { array
|
192
|
+
arr = sized(10) { array { integer } }
|
193
193
|
choose(*arr)
|
194
194
|
}.check { |o|
|
195
195
|
assert o.is_a?(Fixnum)
|
196
196
|
}
|
197
197
|
property_of {
|
198
198
|
# array of array of ints
|
199
|
-
arr = sized(10) { array
|
199
|
+
arr = sized(10) { array { array { integer }}}
|
200
200
|
# choose an array from an array of arrays of ints
|
201
201
|
choose(*arr)
|
202
202
|
}.check { |arr|
|
@@ -210,7 +210,7 @@ class RantlyTest::Generator < Test::Unit::TestCase
|
|
210
210
|
should "not pick an element with 0 frequency" do
|
211
211
|
property_of {
|
212
212
|
sized(10) {
|
213
|
-
array
|
213
|
+
array { freq([0,:string],[1,:integer]) }
|
214
214
|
}
|
215
215
|
}.check { |arr|
|
216
216
|
assert arr.all? { |o| o.is_a?(Integer)}
|
@@ -235,7 +235,7 @@ class RantlyTest::Generator < Test::Unit::TestCase
|
|
235
235
|
|
236
236
|
should "generate empty array" do
|
237
237
|
property_of {
|
238
|
-
sized(0) { array
|
238
|
+
sized(0) { array { integer }}
|
239
239
|
}.check { |o|
|
240
240
|
assert o.empty?
|
241
241
|
}
|
@@ -245,7 +245,7 @@ class RantlyTest::Generator < Test::Unit::TestCase
|
|
245
245
|
property_of {
|
246
246
|
size1 = range(5,10)
|
247
247
|
size2 = range(0,size1-1)
|
248
|
-
array = sized(size1) { array
|
248
|
+
array = sized(size1) { array { array(size2) { integer }}}
|
249
249
|
[size1,array]
|
250
250
|
}.check { |(size1,outter_array)|
|
251
251
|
assert_equal size1, outter_array.size
|
@@ -255,7 +255,7 @@ class RantlyTest::Generator < Test::Unit::TestCase
|
|
255
255
|
|
256
256
|
should "generate array with right types" do
|
257
257
|
property_of {
|
258
|
-
sized(10) { array :integer,:string,:float
|
258
|
+
sized(10) { array { freq(:integer,:string,:float)} }
|
259
259
|
}.check { |arr|
|
260
260
|
assert arr.all? { |o|
|
261
261
|
case o
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rantly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Howard Yeh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|