random_data 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +20 -0
- data/History.txt +6 -0
- data/README.rdoc +2 -2
- data/Rakefile +10 -6
- data/lib/random_data/locations.rb +2 -2
- data/lib/random_data/names.rb +27 -0
- data/lib/random_data/version.rb +1 -1
- data/test/test_random_data.rb +308 -298
- metadata +28 -42
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
json (1.6.3)
|
5
|
+
json (1.6.3-java)
|
6
|
+
metaclass (0.0.1)
|
7
|
+
mocha (0.10.0)
|
8
|
+
metaclass (~> 0.0.1)
|
9
|
+
rake (0.9.2)
|
10
|
+
rdoc (3.11)
|
11
|
+
json (~> 1.4)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
java
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
mocha
|
19
|
+
rake
|
20
|
+
rdoc
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -23,7 +23,7 @@ Random.phone, Random.international_phone, Random.email
|
|
23
23
|
Random.date, Random.date_between
|
24
24
|
|
25
25
|
=== Location Methods
|
26
|
-
Random.address_line_1, Random.address_line_2, Random.zipcode, Random.uk_post_code, Random.
|
26
|
+
Random.address_line_1, Random.address_line_2, Random.zipcode, Random.uk_post_code, Random.state_code, Random.state_full, Random.country, Random.city
|
27
27
|
|
28
28
|
=== Name Methods
|
29
29
|
Random.firstname, Random.firstname_male, Random.firstname_female, Random.initial, Random.lastname
|
@@ -111,7 +111,7 @@ Note that some methods take parameters to bound or limit the amount of data retu
|
|
111
111
|
|
112
112
|
(Note that the zipcodes are totally random and may not be real zipcodes)
|
113
113
|
|
114
|
-
>> Random.
|
114
|
+
>> Random.state_code
|
115
115
|
=> "MD"
|
116
116
|
|
117
117
|
>> Random.state_full
|
data/Rakefile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
RDoc::Task.new do |rdoc|
|
6
|
+
end
|
7
|
+
|
8
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
9
|
+
# task :default => [:spec, :features]
|
10
|
+
task :default => :test
|
@@ -78,9 +78,9 @@ module RandomData
|
|
78
78
|
["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]]
|
79
79
|
|
80
80
|
# Returns a state 2-character abbreviation
|
81
|
-
# Random.
|
81
|
+
# Random.state_code = "IL"
|
82
82
|
|
83
|
-
def
|
83
|
+
def state_code
|
84
84
|
@@us_states.rand[1]
|
85
85
|
end
|
86
86
|
|
data/lib/random_data/names.rb
CHANGED
@@ -14,7 +14,34 @@ module RandomData
|
|
14
14
|
KIRBY KIRK LAKE LEE LEWIS MARTIN MARTINEZ MAJOR MILLER MOORE OATES PETERS PETERSON ROBERTSON
|
15
15
|
ROBINSON RODRIGUEZ SMITH SMYTHE STEVENS TAYLOR THATCHER THOMAS THOMPSON WALKER WASHINGTON WHITE
|
16
16
|
WILLIAMS WILSON YORKE)
|
17
|
+
@@incorporation_types = %w{LLC Inc Inc. Ltd. LP LLP Corp. PLLC}
|
18
|
+
@@company_types = %w{Clothier Publishing Computing Consulting Engineering Industries Marketing Manufacturing}
|
17
19
|
|
20
|
+
# Returns a random company name
|
21
|
+
#
|
22
|
+
# >> Random.company_name
|
23
|
+
#
|
24
|
+
# "Harris & Thomas"
|
25
|
+
|
26
|
+
def companyname
|
27
|
+
num = rand(5)
|
28
|
+
if num == 0
|
29
|
+
num = 1
|
30
|
+
end
|
31
|
+
final = num.times.collect { @@lastnames.rand.capitalize }
|
32
|
+
|
33
|
+
if final.count == 1
|
34
|
+
"#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}"
|
35
|
+
else
|
36
|
+
incorporation_type = rand(17) % 2 == 0 ? @@incorporation_types.rand : nil
|
37
|
+
company_type = rand(17) % 2 == 0 ? @@company_types.rand : nil
|
38
|
+
trailer = company_type.nil? ? "" : " #{company_type}"
|
39
|
+
trailer << ", #{incorporation_type}" unless incorporation_type.nil?
|
40
|
+
"#{final[0..-1].join(', ')} & #{final.last}#{trailer}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
alias company_name companyname
|
18
45
|
# Returns a random lastname
|
19
46
|
#
|
20
47
|
# >> Random.lastname
|
data/lib/random_data/version.rb
CHANGED
data/test/test_random_data.rb
CHANGED
@@ -1,298 +1,308 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestRandomData < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# to make random numbers deterministic for testing purposes
|
7
|
-
srand(100)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_return_random_phone_number
|
11
|
-
assert_equal "620-892-9039", Random.phone
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_return_random_international_phone
|
15
|
-
assert_equal "011-9-34-9039", Random.international_phone
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_return_random_email
|
19
|
-
assert_equal "ijones@webmail.com", Random.email
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_should_return_random_date
|
23
|
-
Date.expects(:today).returns(Date.civil(2007,9,15))
|
24
|
-
assert_equal "2007-09-13", Random.date.to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_return_random_date_with_range
|
28
|
-
Date.expects(:today).returns(Date.civil(2007,9,15))
|
29
|
-
assert_equal "2007-10-29", Random.date(1500).to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_return_random_address_line_1
|
33
|
-
assert_equal "38408 Highland Blvd", Random.address_line_1
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_return_random_address_line_2
|
37
|
-
assert_equal "Lot 792", Random.address_line_2
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_return_random_zipcode
|
41
|
-
assert_equal "38408", Random.zipcode
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_return_random_uk_post_code
|
45
|
-
assert_equal "BM8 24DB", Random.uk_post_code
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_return_random_state
|
49
|
-
assert_equal "DE", Random.
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_return_random_state_full
|
53
|
-
assert_equal "Delaware", Random.state_full
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_return_random_country
|
57
|
-
assert_equal "Armenia", Random.country
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_return_random_city
|
61
|
-
assert_equal "Georgetown", Random.city
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_should_return_random_firstname
|
65
|
-
assert_equal "Donald", Random.firstname
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_should_return_random_first_name
|
69
|
-
assert_equal "Donald", Random.first_name
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def test_should_return_random_firstnamemale
|
74
|
-
assert_equal "Donald", Random.firstname_male
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_should_return_random_first_name_male
|
78
|
-
assert_equal "Donald", Random.first_name_male
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_should_return_random_firstnamefemale
|
82
|
-
assert_equal "Charlotte", Random.firstname_female
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_return_random_first_name_female
|
86
|
-
assert_equal "Charlotte", Random.first_name_female
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_should_return_random_initial
|
90
|
-
assert_equal "I", Random.initial
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_should_return_random_lastname
|
94
|
-
assert_equal "Clarke", Random.lastname
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_should_return_random_last_name
|
98
|
-
assert_equal "Clarke", Random.last_name
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_should_return_random_full_name
|
102
|
-
assert_equal "Donald Jones", Random.full_name
|
103
|
-
end
|
104
|
-
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
def
|
128
|
-
|
129
|
-
assert_equal
|
130
|
-
end
|
131
|
-
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
assert_equal '
|
140
|
-
end
|
141
|
-
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
x=
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
File.
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
def
|
247
|
-
|
248
|
-
Random.sport
|
249
|
-
end
|
250
|
-
|
251
|
-
def
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
Random.
|
265
|
-
end
|
266
|
-
|
267
|
-
def
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
text.
|
290
|
-
markov_machine.insert(word)
|
291
|
-
end
|
292
|
-
assert_equal(["
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestRandomData < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# to make random numbers deterministic for testing purposes
|
7
|
+
srand(100)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_return_random_phone_number
|
11
|
+
assert_equal "620-892-9039", Random.phone
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_return_random_international_phone
|
15
|
+
assert_equal "011-9-34-9039", Random.international_phone
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_return_random_email
|
19
|
+
assert_equal "ijones@webmail.com", Random.email
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_return_random_date
|
23
|
+
Date.expects(:today).returns(Date.civil(2007,9,15))
|
24
|
+
assert_equal "2007-09-13", Random.date.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_random_date_with_range
|
28
|
+
Date.expects(:today).returns(Date.civil(2007,9,15))
|
29
|
+
assert_equal "2007-10-29", Random.date(1500).to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_return_random_address_line_1
|
33
|
+
assert_equal "38408 Highland Blvd", Random.address_line_1
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_return_random_address_line_2
|
37
|
+
assert_equal "Lot 792", Random.address_line_2
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_return_random_zipcode
|
41
|
+
assert_equal "38408", Random.zipcode
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_return_random_uk_post_code
|
45
|
+
assert_equal "BM8 24DB", Random.uk_post_code
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_return_random_state
|
49
|
+
assert_equal "DE", Random.state_code
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_return_random_state_full
|
53
|
+
assert_equal "Delaware", Random.state_full
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_return_random_country
|
57
|
+
assert_equal "Armenia", Random.country
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_return_random_city
|
61
|
+
assert_equal "Georgetown", Random.city
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_return_random_firstname
|
65
|
+
assert_equal "Donald", Random.firstname
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_return_random_first_name
|
69
|
+
assert_equal "Donald", Random.first_name
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_should_return_random_firstnamemale
|
74
|
+
assert_equal "Donald", Random.firstname_male
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_should_return_random_first_name_male
|
78
|
+
assert_equal "Donald", Random.first_name_male
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_return_random_firstnamefemale
|
82
|
+
assert_equal "Charlotte", Random.firstname_female
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_should_return_random_first_name_female
|
86
|
+
assert_equal "Charlotte", Random.first_name_female
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_should_return_random_initial
|
90
|
+
assert_equal "I", Random.initial
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_return_random_lastname
|
94
|
+
assert_equal "Clarke", Random.lastname
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_return_random_last_name
|
98
|
+
assert_equal "Clarke", Random.last_name
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_should_return_random_full_name
|
102
|
+
assert_equal "Donald Jones", Random.full_name
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_should_return_random_companyname
|
106
|
+
srand(17)
|
107
|
+
assert_equal "Garcia Marketing, Corp.", Random.companyname
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_should_return_random_company_name
|
111
|
+
srand(9999999999)
|
112
|
+
assert_equal "Anthony, Edwards & Edwards Publishing", Random.company_name
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_return_random_alphanumeric
|
116
|
+
assert_equal "8O3dNFmAUqYr2YEY", Random.alphanumeric
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_should_return_random_alphanumeric_with_range
|
120
|
+
assert_equal "8O3dNFm", Random.alphanumeric(7)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_return_random_paragraphs
|
124
|
+
assert_equal 2, Random.paragraphs(2).scan(/\n\n/).size
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_return_random_paragraphs_with_limit
|
128
|
+
num_paragraphs = 5
|
129
|
+
assert_equal num_paragraphs, Random.paragraphs(num_paragraphs).scan(/\n\n/).size
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_initial_should_not_return_nil
|
133
|
+
srand(11) #This would force the nil case in the old implementation
|
134
|
+
assert_not_nil Random.initial
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_should_return_random_date_using_range
|
138
|
+
Date.expects(:today).returns(Date.civil(2007,9,15))
|
139
|
+
assert_equal '1998-03-30', Random.date(-5000..-1000).to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_should_return_random_date_between_using_range_of_dates
|
143
|
+
min = Date.parse('1966-11-15')
|
144
|
+
max = Date.parse('1990-01-01')
|
145
|
+
assert_equal '1982-04-25', Random.date_between(min..max).to_s
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_should_return_random_date_between_using_range_of_strings
|
149
|
+
assert_equal '1982-04-25', Random.date_between('1966-11-15'..'1990-01-01').to_s
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_should_return_random_boolean_true
|
153
|
+
srand(99)
|
154
|
+
assert_equal true, Random.boolean
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_should_return_random_boolean_false
|
158
|
+
assert_equal false, Random.boolean
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_should_return_random_number_less_than_10
|
162
|
+
assert_equal 8, Random.number(9)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_should_return_random_bit
|
166
|
+
assert_equal 0, Random.bit
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_should_return_random_bits
|
170
|
+
assert_equal 10, Random.bits(10).size
|
171
|
+
assert_equal [0, 1, 0, 0, 0, 0, 1, 0, 0, 1], Random.bits(10)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_should_return_random_number_within_range
|
175
|
+
assert_equal 13, Random.number(5..15)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_should_return_random_grammatical_construct
|
179
|
+
assert_equal "Bob bites Rex",
|
180
|
+
Random::grammatical_construct({:story => [:man, " bites ", :dog],
|
181
|
+
:man => { :bob => "Bob"},
|
182
|
+
:dog => {:a =>"Rex", :b =>"Rover"}},
|
183
|
+
:story)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_roulette_wheel_with_positive_weights
|
187
|
+
weights=[10,5,1,1];
|
188
|
+
results = []
|
189
|
+
17.times do
|
190
|
+
results << weights.roulette
|
191
|
+
end
|
192
|
+
assert_equal([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0],
|
193
|
+
results);
|
194
|
+
results = []
|
195
|
+
weights.roulette(17) do |i|
|
196
|
+
results << i
|
197
|
+
end
|
198
|
+
assert_equal([0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
199
|
+
results);
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_roulette_wheel_with_zero_weights
|
203
|
+
weights=[0,0,0];
|
204
|
+
assert_raise RuntimeError do
|
205
|
+
weights.roulette
|
206
|
+
end
|
207
|
+
assert_raise RuntimeError do
|
208
|
+
x=0
|
209
|
+
weights.roulette(1){|i| x=i}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_roulette_wheel_with_negative_weights
|
214
|
+
weights=[2,-1,2];
|
215
|
+
assert_raise RuntimeError do
|
216
|
+
weights.roulette
|
217
|
+
end
|
218
|
+
assert_raise RuntimeError do
|
219
|
+
x=0
|
220
|
+
weights.roulette(1){|i| x=i}
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class TestRandomDataMethodMissing < Test::Unit::TestCase
|
226
|
+
|
227
|
+
def sports
|
228
|
+
@sports ||= %w(hockey basketball water\ polo five-a-side football judo pole\ vault steeple\ chase)
|
229
|
+
end
|
230
|
+
|
231
|
+
def lines
|
232
|
+
@lines ||= sports.join("\r\n")
|
233
|
+
end
|
234
|
+
|
235
|
+
def path
|
236
|
+
@path ||= File.join("lib","sport.dat")
|
237
|
+
end
|
238
|
+
|
239
|
+
def setup
|
240
|
+
@file = stub('file', :read => lines)
|
241
|
+
$:.stubs(:each).yields("lib")
|
242
|
+
File.stubs(:exist?).returns(true)
|
243
|
+
File.stubs(:open).yields(@file)
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_should_search_load_path_for_file
|
247
|
+
$:.expects(:each).yields("lib")
|
248
|
+
Random.sport
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_should_join_path_with_methodname_dot_dat
|
252
|
+
File.expects(:join).with("lib","sport.dat").returns("lib/sport.dat")
|
253
|
+
Random.sport
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_should_test_for_existence_of_filename_matching_method_missing_call
|
257
|
+
File.expects(:exist?).with(path).returns(true)
|
258
|
+
Random.sport
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_should_call_super_if_unable_to_find_file
|
262
|
+
# can't test super call directly, so we test whether MethodMissing gets raised properly
|
263
|
+
File.stubs(:exist?).returns(false)
|
264
|
+
assert_raise(NoMethodError) { Random.horse }
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_should_open_file_matching_method_missing_call
|
268
|
+
File.expects(:open).with(path,"r").yields(@file)
|
269
|
+
Random.sport
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_should_read_lines_from_file
|
273
|
+
@file.expects(:read).returns(@lines)
|
274
|
+
Random.sport
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_should_return_random_line_from_a_file
|
278
|
+
srand(101)
|
279
|
+
assert_equal 'steeple chase', Random.sport
|
280
|
+
assert_equal 'five-a-side', Random.sport
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
class TestRandomDataMarkovGenerator < Test::Unit::TestCase
|
286
|
+
def test_markov_generator
|
287
|
+
markov_machine = RandomData::MarkovGenerator.new(3)
|
288
|
+
text = IO.read "#{File.dirname(__FILE__)}/henry_v_prolog.txt"
|
289
|
+
text.split(/\s+/).each do |word|
|
290
|
+
markov_machine.insert(word)
|
291
|
+
end
|
292
|
+
assert_equal(["PROLOGUE", "Enter", "CHORUS",
|
293
|
+
"CHORUS.", "O", "for", "a", "Muse",
|
294
|
+
"of", "fire,", "that", "would", "ascend",
|
295
|
+
"The", "brightest", "heaven", "of",
|
296
|
+
"invention,", "A", "kingdom"],
|
297
|
+
markov_machine.generate(20));
|
298
|
+
markov_machine = RandomData::MarkovGenerator.new(3)
|
299
|
+
text.scan(/\S{2}|\s+/).each do |word|
|
300
|
+
markov_machine.insert(word)
|
301
|
+
end
|
302
|
+
assert_equal(["PR", "OL", "OG", "UE", "\n\n", "En",
|
303
|
+
"te", " ", "CH", "OR", "US", "\n\n",
|
304
|
+
"CH", "OR", "US", "\n\n", "CH", "OR",
|
305
|
+
"US", "\n\n"],
|
306
|
+
markov_machine.generate(20));
|
307
|
+
end
|
308
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,27 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: random_data
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 2
|
10
|
-
version: 1.5.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mike Subelsky
|
14
9
|
- Tom Harris
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2010-11-16 00:00:00 -05:00
|
20
|
-
default_executable:
|
13
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
21
14
|
dependencies: []
|
22
|
-
|
23
15
|
description: Random data generator
|
24
16
|
email: thomas.e.harris@gmail.com
|
25
17
|
executables: []
|
26
|
-
|
27
18
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
30
20
|
- README.rdoc
|
31
|
-
files:
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
32
25
|
- History.txt
|
33
26
|
- License.txt
|
34
27
|
- PostInstall.txt
|
@@ -55,41 +48,34 @@ files:
|
|
55
48
|
- test/henry_v_prolog.txt
|
56
49
|
- test/test_helper.rb
|
57
50
|
- test/test_random_data.rb
|
58
|
-
has_rdoc: true
|
59
51
|
homepage: http://github.com/tomharris/random_data
|
60
52
|
licenses: []
|
61
|
-
|
62
53
|
post_install_message:
|
63
|
-
rdoc_options:
|
54
|
+
rdoc_options:
|
64
55
|
- --charset=UTF-8
|
65
|
-
require_paths:
|
56
|
+
require_paths:
|
66
57
|
- lib
|
67
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
59
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
76
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
65
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
85
70
|
requirements: []
|
86
|
-
|
87
71
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.8.24
|
89
73
|
signing_key:
|
90
74
|
specification_version: 3
|
91
|
-
summary: A Ruby gem that provides a Random class with a series of methods for generating
|
92
|
-
|
75
|
+
summary: A Ruby gem that provides a Random class with a series of methods for generating
|
76
|
+
random test data including names, mailing addresses, dates, phone numbers, e-mail
|
77
|
+
addresses, and text.
|
78
|
+
test_files:
|
93
79
|
- test/henry_v_prolog.txt
|
94
80
|
- test/test_helper.rb
|
95
81
|
- test/test_random_data.rb
|