tekido 1.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.
@@ -0,0 +1,138 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Tekido::Methods do
5
+ describe "numeric methods" do
6
+ describe ".integer" do
7
+ context "with no argument" do
8
+ it "returns integer" do
9
+ expect(Tekido.integer).to be_an(Integer)
10
+ end
11
+ it "at random uniformly" do
12
+ list = TRY_COUNT.times.map { Tekido.integer }
13
+ expect(list.uniq.size).to be >= expected_count
14
+ end
15
+ it "returns random integer value" do
16
+ max = 2 ** 30 - 1
17
+ TRY_COUNT.times do
18
+ expect(0..max).to include(Tekido.integer)
19
+ end
20
+ end
21
+ end
22
+ context "with integer argument" do
23
+ it "returns integer" do
24
+ expect(Tekido.integer(1000)).to be_an(Integer)
25
+ end
26
+ it "at random uniformly" do
27
+ list = TRY_COUNT.times.map { Tekido.integer(1000) }
28
+ expect(list.uniq.size).to be >= expected_count(1001)
29
+ end
30
+ it "returns value not over argument" do
31
+ TRY_COUNT.times do
32
+ expect(0..1000).to include(Tekido.integer(1000))
33
+ end
34
+ end
35
+ end
36
+ context "with integer range" do
37
+ it "returns integer" do
38
+ expect(Tekido.integer(0..1000)).to be_an(Integer)
39
+ end
40
+ it "at random uniformly" do
41
+ list = TRY_COUNT.times.map { Tekido.integer(0..1000) }
42
+ expect(list.uniq.size).to be >= expected_count(1001)
43
+ end
44
+ it "returns value that is included in argument" do
45
+ TRY_COUNT.times do
46
+ expect(0..1000).to include(Tekido.integer(0..1000))
47
+ end
48
+ end
49
+ end
50
+ context "with float range" do
51
+ it "returns integer" do
52
+ expect(Tekido.integer(0.1..1000.1)).to be_an(Integer)
53
+ end
54
+ it "at random uniformly" do
55
+ list = TRY_COUNT.times.map { Tekido.integer(0.1..1000.1) }
56
+ expect(list.uniq.size).to be >= expected_count(1001)
57
+ end
58
+ it "returns value that is included in argument" do
59
+ TRY_COUNT.times do
60
+ expect(0..1000).to include(Tekido.integer(0.1..1000.1))
61
+ end
62
+ end
63
+ end
64
+ end
65
+ describe ".float" do
66
+ context "with no argument" do
67
+ it "returns float" do
68
+ expect(Tekido.float).to be_a(Float)
69
+ end
70
+ it "at random uniformly" do
71
+ list = TRY_COUNT.times.map { Tekido.float }
72
+ expect(list.uniq.size).to be >= expected_count
73
+ end
74
+ it "returns value that is 0 or more, less than 1" do
75
+ TRY_COUNT.times do
76
+ expect(0...1).to include(Tekido.float)
77
+ end
78
+ end
79
+ end
80
+ context "with integer argument" do
81
+ it "returns float" do
82
+ expect(Tekido.float(1000)).to be_an(Float)
83
+ end
84
+ it "at random uniformly" do
85
+ list = TRY_COUNT.times.map { Tekido.float(1000) }
86
+ expect(list.uniq.size).to be >= expected_count
87
+ end
88
+ it "returns value not over argument" do
89
+ TRY_COUNT.times do
90
+ expect(0..1000).to include(Tekido.float(1000))
91
+ end
92
+ end
93
+ end
94
+ context "with float argument" do
95
+ it "returns float" do
96
+ expect(Tekido.float(1000.888)).to be_an(Float)
97
+ end
98
+ it "at random uniformly" do
99
+ list = TRY_COUNT.times.map { Tekido.float(1000.888) }
100
+ expect(list.uniq.size).to be >= expected_count
101
+ end
102
+ it "returns value not over argument" do
103
+ TRY_COUNT.times do
104
+ expect(0..1000.888).to include(Tekido.float(1000.888))
105
+ end
106
+ end
107
+ end
108
+ context "with integer range" do
109
+ it "returns float" do
110
+ expect(Tekido.float(0..1000)).to be_a(Float)
111
+ end
112
+ it "at random uniformly" do
113
+ list = TRY_COUNT.times.map { Tekido.float(0..1000) }
114
+ expect(list.uniq.size).to be >= expected_count
115
+ end
116
+ it "returns value that is included in argument" do
117
+ TRY_COUNT.times do
118
+ expect(0..1000).to include(Tekido.float(0..1000))
119
+ end
120
+ end
121
+ end
122
+ context "with float range" do
123
+ it "returns float" do
124
+ expect(Tekido.float(0.1..1000.1)).to be_a(Float)
125
+ end
126
+ it "at random uniformly" do
127
+ list = TRY_COUNT.times.map { Tekido.float(0.1..1000.1) }
128
+ expect(list.uniq.size).to be >= expected_count
129
+ end
130
+ it "returns value that is included in argument" do
131
+ TRY_COUNT.times do
132
+ expect(0.1..1000.1).to include(Tekido.float(0.1..1000.1))
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Tekido::Methods do
5
+ describe "percentage methods" do
6
+ describe ".percent" do
7
+ it "returns integer" do
8
+ expect(Tekido.percent).to be_an(Integer)
9
+ end
10
+ it "at random uniformly" do
11
+ list = TRY_COUNT.times.map { Tekido.percent }
12
+ expect(list.uniq.size).to be >= expected_count(101)
13
+ end
14
+ it "returns value in range of 0..100" do
15
+ TRY_COUNT.times do
16
+ expect(0..100).to include(Tekido.percent)
17
+ end
18
+ end
19
+ end
20
+ describe ".percent_as" do
21
+ context "with :float argument" do
22
+ it "returns float" do
23
+ expect(Tekido.percent_as(:float)).to be_a(Float)
24
+ end
25
+ it "at random uniformly" do
26
+ list = TRY_COUNT.times.map { Tekido.percent_as(:float) }
27
+ expect(list.uniq.size).to be >= expected_count
28
+ end
29
+ it "returns value in range of 0..100" do
30
+ TRY_COUNT.times do
31
+ expect(0..100).to include(Tekido.percent_as(:float))
32
+ end
33
+ end
34
+ end
35
+ context "with :integer argument" do
36
+ it "returns integer" do
37
+ expect(Tekido.percent_as(:integer)).to be_an(Integer)
38
+ end
39
+ it "at random uniformly" do
40
+ list = TRY_COUNT.times.map { Tekido.percent_as(:integer) }
41
+ expect(list.uniq.size).to be >= expected_count(101)
42
+ end
43
+ it "returns value in range of 0..100" do
44
+ TRY_COUNT.times do
45
+ expect(0..100).to include(Tekido.percent_as(:integer))
46
+ end
47
+ end
48
+ end
49
+ context "with :mo5 argument" do
50
+ it "returns integer" do
51
+ expect(Tekido.percent_as(:mo5)).to be_an(Integer)
52
+ end
53
+ it "at random uniformly" do
54
+ list = TRY_COUNT.times.map { Tekido.percent_as(:mo5) }
55
+ expect(list.uniq.size).to be >= expected_count(21)
56
+ end
57
+ it "returns multiple of 5" do
58
+ TRY_COUNT.times do
59
+ expecteds = 0.upto(20).map { |i| i * 5 }
60
+ expect(expecteds).to include(Tekido.percent_as(:mo5))
61
+ end
62
+ end
63
+ end
64
+ context "with :deca argument" do
65
+ it "returns integer" do
66
+ expect(Tekido.percent_as(:deca)).to be_an(Integer)
67
+ end
68
+ it "at random uniformly" do
69
+ list = TRY_COUNT.times.map { Tekido.percent_as(:deca) }
70
+ expect(list.uniq.size).to be >= expected_count(11)
71
+ end
72
+ it "returns multiple of 10" do
73
+ TRY_COUNT.times do
74
+ expecteds = 0.upto(10).map { |i| i * 10 }
75
+ expect(expecteds).to include(Tekido.percent_as(:deca))
76
+ end
77
+ end
78
+ end
79
+ context "with :mo10 argument" do
80
+ it "returns integer" do
81
+ expect(Tekido.percent_as(:mo10)).to be_an(Integer)
82
+ end
83
+ it "at random uniformly" do
84
+ list = TRY_COUNT.times.map { Tekido.percent_as(:mo10) }
85
+ expect(list.uniq.size).to be >= expected_count(11)
86
+ end
87
+ it "returns multiple of 10" do
88
+ TRY_COUNT.times do
89
+ expecteds = 0.upto(10).map { |i| i * 10 }
90
+ expect(expecteds).to include(Tekido.percent_as(:mo10))
91
+ end
92
+ end
93
+ end
94
+ context "with other argument" do
95
+ it "returns nil" do
96
+ expect(Tekido.percent_as(:decimal)).to be_nil
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,273 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ EXAMPLE_DOMAINS = ["example.com", "exmple.net", "example.org", "example.jp", "example.co.jp", "example.ne.jp"] +
5
+ (0..9).map { |i| ["example#{i}.jp", "example#{i}.co.jp", "example#{i}.ne.jp"] }.flatten
6
+
7
+ describe Tekido::Methods do
8
+ describe "string methods"do
9
+ describe ".string" do
10
+ context "with no argument" do
11
+ it "returns string" do
12
+ expect(Tekido.string).to be_a(String)
13
+ end
14
+ it "at random uniformly" do
15
+ list = TRY_COUNT.times.map { Tekido.string }
16
+ expect(list.uniq.size).to be >= expected_count
17
+ end
18
+ it "returned string length is within 1..255" do
19
+ TRY_COUNT.times do
20
+ expect(1..255).to include(Tekido.string.size)
21
+ end
22
+ end
23
+ it "returned string is constructed by upper chars and lower chars and numeric chars" do
24
+ TRY_COUNT.times do
25
+ expect(Tekido.string).to match(/\A[a-zA-Z0-9]+\z/)
26
+ end
27
+ end
28
+ end
29
+ context "with size option that has integer value (10)" do
30
+ it "returns string" do
31
+ expect(Tekido.string(size: 10)).to be_a(String)
32
+ end
33
+ it "at random uniformly" do
34
+ list = TRY_COUNT.times.map { Tekido.string(size: 10) }
35
+ expect(list.uniq.size).to be >= expected_count
36
+ end
37
+ it "returned string length is 10" do
38
+ TRY_COUNT.times do
39
+ expect(Tekido.string(size: 10).size).to eq 10
40
+ end
41
+ end
42
+ it "returned string is constructed by upper chars and lower chars and numeric chars" do
43
+ TRY_COUNT.times do
44
+ expect(Tekido.string(size: 10)).to match(/\A[a-zA-Z0-9]+\z/)
45
+ end
46
+ end
47
+ end
48
+ context "with size option that has integer range (8..16)" do
49
+ it "returns string" do
50
+ expect(Tekido.string(size: 8..16)).to be_a(String)
51
+ end
52
+ it "at random uniformly" do
53
+ list = TRY_COUNT.times.map { Tekido.string(size: 8..16) }
54
+ expect(list.uniq.size).to be >= expected_count
55
+ end
56
+ it "returned string length is within 8..16" do
57
+ TRY_COUNT.times do
58
+ expect(8..16).to include(Tekido.string(size: 8..16).size)
59
+ end
60
+ end
61
+ it "returned string is constructed by upper chars and lower chars and numeric chars" do
62
+ TRY_COUNT.times do
63
+ expect(Tekido.string(size: 8..16)).to match(/\A[a-zA-Z0-9]+\z/)
64
+ end
65
+ end
66
+ end
67
+ context "with components option" do
68
+ it "returns string" do
69
+ expect(Tekido.string(components: [:upper, :lower])).to be_a(String)
70
+ end
71
+ it "at random uniformly" do
72
+ list = TRY_COUNT.times.map { Tekido.string(components: [:upper, :lower]) }
73
+ expect(list.uniq.size).to be >= expected_count
74
+ end
75
+ context "components value is :upper" do
76
+ it "returned string is constructed by upper chars" do
77
+ TRY_COUNT.times do
78
+ expect(Tekido.string(components: [:upper])).to match(/\A[A-Z]+\z/)
79
+ end
80
+ end
81
+ end
82
+ context "components value is :lower" do
83
+ it "returned string is constructed by lower chars" do
84
+ TRY_COUNT.times do
85
+ expect(Tekido.string(components: :lower)).to match(/\A[a-z]+\z/)
86
+ end
87
+ end
88
+ end
89
+ context "components value is :number" do
90
+ it "returned string is constructed by numeric chars" do
91
+ TRY_COUNT.times do
92
+ expect(Tekido.string(components: :number)).to match(/\A[0-9]+\z/)
93
+ end
94
+ end
95
+ end
96
+ context "components value is :upper and :lower" do
97
+ it "returned string is constructed by upper chars and lower chars" do
98
+ TRY_COUNT.times do
99
+ expect(Tekido.string(components: [:upper, :lower])).to match(/\A[a-zA-Z]+\z/)
100
+ end
101
+ end
102
+ end
103
+ context "components value is :lower and :number" do
104
+ it "returned string is constructed by lower chars and numeric chars" do
105
+ TRY_COUNT.times do
106
+ expect(Tekido.string(components: [:lower, :number])).to match(/\A[a-z0-9]+\z/)
107
+ end
108
+ end
109
+ end
110
+ context "components value is :upper and :number" do
111
+ it "returned string is constructed by upper chars and numeric chars" do
112
+ TRY_COUNT.times do
113
+ expect(Tekido.string(components: [:upper, :number])).to match(/\A[A-Z0-9]+\z/)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ context "with chars option" do
119
+ it "retuens string" do
120
+ expect(Tekido.string(chars: ('a'..'t').to_a)).to be_a(String)
121
+ end
122
+ it "at random uniformly" do
123
+ list = TRY_COUNT.times.map { Tekido.string(chars: ('a'..'t').to_a) }
124
+ expect(list.uniq.size).to be >= expected_count
125
+ end
126
+ it "returned string is constructed by given chars" do
127
+ TRY_COUNT.times do
128
+ expect(Tekido.string(chars: ('a'..'t').to_a)).to match(/\A[a-t]+\z/)
129
+ end
130
+ end
131
+ end
132
+ context "with size and components options" do
133
+ it "returns string" do
134
+ expect(Tekido.string(size: 8..16, components: [:lower, :number])).to be_a(String)
135
+ end
136
+ it "at random uniformly" do
137
+ list = TRY_COUNT.times.map { Tekido.string(size: 8..16, components: [:lower, :number]) }
138
+ expect(list.uniq.size).to be >= expected_count
139
+ end
140
+ it "returned string length is within 8..16" do
141
+ TRY_COUNT.times do
142
+ expect(8..16).to include(Tekido.string(size: 8..16, components: [:lower, :number]).size)
143
+ end
144
+ end
145
+ it "returned string is constructed by lower chars and numeric chars" do
146
+ TRY_COUNT.times do
147
+ expect(Tekido.string(size: 8..16, components: [:lower, :number])).to match(/\A[a-z0-9]+\z/)
148
+ end
149
+ end
150
+ end
151
+ context "with size and chars options" do
152
+ it "returns string" do
153
+ expect(Tekido.string(size: 8..16, chars: "String".chars.to_a)).to be_a(String)
154
+ end
155
+ it "at random uniformly" do
156
+ list = TRY_COUNT.times.map { Tekido.string(size: 8..16, chars: "String".chars.to_a) }
157
+ expect(list.uniq.size).to be >= expected_count
158
+ end
159
+ it "returned string length is within 8..16" do
160
+ TRY_COUNT.times do
161
+ expect(8..16).to include(Tekido.string(size: 8..16, chars: "String".chars.to_a).size)
162
+ end
163
+ end
164
+ it "returned string is constructed by given characters" do
165
+ TRY_COUNT.times do
166
+ expect(Tekido.string(size: 8..16, chars: "String".chars.to_a)).to match(/\A[String]+\z/)
167
+ end
168
+ end
169
+ end
170
+ context "with components and chars options" do
171
+ it "retuens string" do
172
+ expect(Tekido.string(components: [:upper, :lower], chars: %w(1 3 5 7 9))).to be_a(String)
173
+ end
174
+ it "at random uniformly" do
175
+ list = TRY_COUNT.times.map { Tekido.string(components: [:upper, :lower], chars: %w(1 3 5 7 9)) }
176
+ expect(list.uniq.size).to be >= expected_count
177
+ end
178
+ it "returned string is constructed by chars option value (components option value is ignored)" do
179
+ TRY_COUNT.times do
180
+ expect(Tekido.string(components: [:upper, :lower], chars: %w(1 3 5 7 9))).to match(/\A[13579]+\z/)
181
+ end
182
+ end
183
+ end
184
+ end
185
+ describe ".email" do
186
+ context "with no argument" do
187
+ it "returns string as email address" do
188
+ expect(Tekido.email).to be_a(String)
189
+ end
190
+ it "at random uniformly" do
191
+ list = TRY_COUNT.times.map { Tekido.email }
192
+ expect(list.uniq.size).to be >= expected_count
193
+ end
194
+ it "returns email address that has size within 3..32" do
195
+ TRY_COUNT.times do
196
+ expect(3..32).to include(Tekido.email.index("@"))
197
+ end
198
+ end
199
+ it "returns email address that end with example domain" do
200
+ TRY_COUNT.times do
201
+ email = Tekido.email
202
+ expect(EXAMPLE_DOMAINS).to include(email[email.index('@')+1..email.size])
203
+ end
204
+ end
205
+ end
206
+ context "with domain string argument" do
207
+ it "returns string as email address" do
208
+ expect(Tekido.email("foobar.com")).to be_a(String)
209
+ end
210
+ it "at random uniformly" do
211
+ list = TRY_COUNT.times.map { Tekido.email("foobar.com") }
212
+ expect(list.uniq.size).to be >= expected_count
213
+ end
214
+ it "returns email address that has size within 3..32" do
215
+ TRY_COUNT.times do
216
+ expect(3..32).to include(Tekido.email("foobar.com").index("@"))
217
+ end
218
+ end
219
+ it "returns email address that end with given domain" do
220
+ TRY_COUNT.times do
221
+ expect(Tekido.email("foobar.com")).to end_with("foobar.com")
222
+ end
223
+ end
224
+ end
225
+ context "with base address argument" do
226
+ it "returns string" do
227
+ expect(Tekido.email("foo.bar@baz.com")).to be_a(String)
228
+ end
229
+ it "at random uniformly" do
230
+ list = TRY_COUNT.times.map { Tekido.email("foo.bar@baz.com") }
231
+ expect(list.uniq.size).to be >= expected_count
232
+ end
233
+ it "returns email address that has size within 3..32" do
234
+ TRY_COUNT.times do
235
+ expect(3..32).to include(Tekido.email("foo.bar@baz.com").index("@"))
236
+ end
237
+ end
238
+ it "returns email address that end with given domain" do
239
+ TRY_COUNT.times do
240
+ expect(Tekido.email("foo.bar@baz.com")).to end_with("baz.com")
241
+ end
242
+ end
243
+ it "returns email address that not equals given mail" do
244
+ TRY_COUNT.times do
245
+ expect(Tekido.email("foo.bar@baz.com")).to end_with("baz.com")
246
+ end
247
+ end
248
+ end
249
+ context "with multiple address arguments" do
250
+ it "returns string" do
251
+ expect(Tekido.email("test@foo.com", "bar.com", "@baz.com")).to be_a(String)
252
+ end
253
+ it "at random uniformly" do
254
+ list = TRY_COUNT.times.map { Tekido.email("test@foo.com", "bar.com", "@baz.com") }
255
+ expect(list.uniq.size).to be >= expected_count
256
+ end
257
+ it "returns email address that has size within 3..32" do
258
+ TRY_COUNT.times do
259
+ expect(3..32).to include(Tekido.email("test@foo.com", "bar.com", "@baz.com").index("@"))
260
+ end
261
+ end
262
+ it "returns email address that end with given domain" do
263
+ TRY_COUNT.times do
264
+ email = Tekido.email("test@foo.com", "bar.com", "@baz.com")
265
+ expected_domains = ["foo.com", "bar.com", "baz.com"]
266
+ expect(expected_domains).to include(email[email.index("@")+1..email.length])
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
272
+ end
273
+