fakir 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 184a6f296f2df935f0082901182ea06d57a244d9
4
+ data.tar.gz: 4b3ce4deb9a8e9a2a08dbabe34e42171707f9bd1
5
+ SHA512:
6
+ metadata.gz: 06fb3a6f6292d1cfabb1796d4f4d77fb1357c9b79a8d50e2a52be9e8cb5667c020100d00e2f7d40d23289e3249103a8491e9e7f94e95f785018c8e7098db0ae8
7
+ data.tar.gz: 024d9fd5ba2da49349054b324b2c3d114031e47040d8256ad13d8f0789ac5beef19d2a5038c94b587cb35bffd023a1d31da990d767934f1e293fdbcabeb5cb1e
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fakir.gemspec
4
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fakir (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.4.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.7)
16
+ fakir!
17
+ rake (~> 10.0)
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,80 @@
1
+ # Fakir
2
+
3
+ Fakir generates pseudo-random data.
4
+
5
+ Fakir::Random, a random number generator, can be defined to never return the same random number, or
6
+ to not return the same random number within N invocations. Thus one will not get the (random, but
7
+ appearing to not be) sequence of [ 1, 8, 3, 3, 3, 5, 2, 2 ], with repeating values (3 and 2).
8
+
9
+ Similarly, Fakir::Array wraps a Ruby Array, extending it with a `rand` method, which will not return
10
+ the same element during any sequences of calling `rand` (until `rand_reset` is called). Thus with
11
+ the array [ "apple", "banana", "cherry" ] one will not get the sequence [ "apple", "apple", "banana"
12
+ ]. This functionality supports seeding data uniquely, such that two elements will not have the same
13
+ content.
14
+
15
+ Fakir::EmailAddress generates valid email addresses of several formats, using, by default, the
16
+ domain "example.com" (thus not actually using a possibly-taken email address). The domain can be
17
+ specified to a different value.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'fakir'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install fakir
34
+
35
+ ## Usage
36
+
37
+ ### Random numbers
38
+
39
+ rnd = Fakir::Random.new 4, 2
40
+ nums = 20.times.collect { rnd.rand }
41
+ => [0, 2, 3, 1, 2, 1, 3, 0, 2, 3, 1, 2, 0, 3, 0, 1, 0, 3, 1, 3]
42
+
43
+ Note that there are no sequences of length 2 with repeated values.
44
+
45
+ rnd = Fakir::Random.new 4, 3
46
+ nums = 20.times.collect { rnd.rand }
47
+ => [1, 0, 2, 1, 0, 2, 3, 0, 2, 3, 0, 2, 3, 0, 2, 1, 3, 2, 1, 0]
48
+
49
+ No sequences of length 3 have repeated values.
50
+
51
+ ### Arrays
52
+
53
+ ary = %w{ this is a test }
54
+ fary = Fakir::Array.new ary
55
+ 4.times { |n| puts fary.rand }
56
+
57
+ Each of the elements in the original array will be returned, with none repeating.
58
+
59
+ ary = %w{ this is a test }
60
+ fary = Fakir::Array.new ary
61
+ 4.times { |n| puts fary.rand }
62
+ fary.rand_reset
63
+ 4.times { |n| puts fary.rand }
64
+
65
+ After `rand_reset` is invoked, the contents of the wrapped array are reset and can be "consumed"
66
+ again.
67
+
68
+ ### Email addresses
69
+
70
+ This generates email addresses based on the first and last names, using the default domain of
71
+ "example.com'. For "John Smith", a few examples: john.smith@example.com, jsmith@example.com,
72
+ jsmith9@example.com, jsmith17@example.com, smithj@example.com, smithj10@example.com, smithj88@example.com
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/jpace/fakir/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require 'fileutils'
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new("test") do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.warning = true
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fakir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fakir"
8
+ spec.version = Fakir::VERSION
9
+ spec.authors = ["Jeff Pace"]
10
+ spec.email = ["jeugenepace@gmail.com"]
11
+ spec.summary = %q{Generates less-random fake data.}
12
+ spec.description = %q{Generates data using less-than-random data, such as non-sequential random numbers.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "fakir/version"
2
+
3
+ module Fakir
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Fakir
5
+ # Extends the ::Array class to return random elements, where an element is returned only once.
6
+ # +rand_reset+ resets the +rand+ method to return elements from the original array, i.e., to
7
+ # possibly repeat elements from before +rand_reset+ was invoked.
8
+ class Array < ::Array
9
+ def initialize(*args)
10
+ @used = ::Array.new
11
+ rand_reset
12
+ super
13
+ end
14
+
15
+ def rand_reset
16
+ concat @used
17
+ @used = ::Array.new
18
+ end
19
+
20
+ def rand
21
+ if size == 0
22
+ raise "error: cannot get random element from an empty array"
23
+ end
24
+ idx = Kernel::rand size
25
+ val = delete_at idx
26
+ @used << val
27
+ val
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'pathname'
5
+
6
+ module Fakir
7
+ # Returns an email address based on the given name. By default, uses "example.com" as the domain,
8
+ # to not use actual existing email accounts. Returns "simple" email addresses, i.e., without
9
+ # valid-yet-rare characters, such as "very.unusual.@.unusual.com"@example.com (per
10
+ # https://en.wikipedia.org/wiki/Email_address). The email address is downcased and non-word
11
+ # characters are removed. Randomly, a trailing number is added. Thus the formats are:
12
+ # - john.smith@example.com
13
+ # - jsmith@example.com
14
+ # - jsmith24@example.com
15
+ # - smithj@example.com
16
+ # - smithj17@example.com
17
+
18
+ class EmailAddress < String
19
+ def initialize firstname, lastname, domain = "example.com"
20
+ formats = Array.new
21
+ formats << "%s.%s"
22
+ formats << "%.1s%s"
23
+ formats << "%2$s%1$.1s"
24
+ formats << "%.1s%s%d"
25
+ formats << "%2$s%1$.1s%3$d"
26
+
27
+ formats.collect! { |fmt| fmt + "@" + domain }
28
+
29
+ fname = clean_word firstname
30
+ lname = clean_word lastname
31
+ fidx = rand(formats.size)
32
+ format = formats[fidx]
33
+ args = [ fname, lname ]
34
+ if format.count("%") >= 3
35
+ args << rand(100)
36
+ end
37
+ addr = sprintf format, *args
38
+ super addr
39
+ end
40
+
41
+ def clean_word str
42
+ str.gsub(Regexp.new('[^\w]'), '').downcase
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Fakir
5
+ # Returns not-quite-random numbers: if +window+ is nil, then an instance will never return the
6
+ # same number. If +window+ is an integer N, then a random number will not be returned within N
7
+ # invocations of +rand+. Thus with +window+ == 2, the same number won't be returned twice in a
8
+ # row. If +number+ is 5, then the same number will not be returned within 5 subsequent invocations
9
+ # of +rand+ times than +max+. If +number+ is 1, then the number can be repeated subsequently.
10
+ class Random
11
+ def initialize max, window = nil
12
+ raise "window #{window} should be less than maximum #{max}" if window && window >= max
13
+ @used = Array.new
14
+ @max = max
15
+ @window = window
16
+ end
17
+
18
+ def rand
19
+ iters = 0
20
+ while iters < @max ** 4
21
+ num = Kernel::rand @max
22
+ if @used.include?(num)
23
+ iters += 1
24
+ else
25
+ @used << num
26
+ if @window
27
+ @used = @used.drop [ @used.length - @window + 1, 0 ].max
28
+ end
29
+ return num
30
+ end
31
+ end
32
+ nil
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Fakir
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'test/unit'
5
+ require_relative '../lib/fakir/array'
6
+
7
+ class ArrayTest < Test::Unit::TestCase
8
+ def test_within_data_limit
9
+ ary = %w{ this is a test }
10
+ fary = Fakir::Array.new ary
11
+ rands = 4.times.collect { |n| fary.rand }
12
+ assert_equal ary.sort, rands.sort
13
+ end
14
+
15
+ def test_over_data_limit
16
+ ary = %w{ this is a test }
17
+ fary = Fakir::Array.new ary
18
+ 4.times.collect { |n| fary.rand }
19
+ assert_raises RuntimeError, "error: cannot get random element from an empty array" do
20
+ fary.rand
21
+ end
22
+ end
23
+
24
+ def test_reset_at_data_limit
25
+ ary = %w{ this is a test }
26
+ fary = Fakir::Array.new ary
27
+ rands = 4.times.collect { |n| fary.rand }
28
+ fary.rand_reset
29
+ rands = 4.times.collect { |n| fary.rand }
30
+ fary.rand_reset
31
+ rands = 4.times.collect { |n| fary.rand }
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'test/unit'
5
+ require_relative '../lib/fakir/email'
6
+
7
+ class EmailTest < Test::Unit::TestCase
8
+ def run_email_test firstname, lastname, domain = nil
9
+ dom = domain || "example.com"
10
+ formats = Array.new
11
+ formats << Regexp.new('john.smith@' + dom)
12
+ formats << Regexp.new('jsmith@' + dom)
13
+ formats << Regexp.new('jsmith\d+@' + dom)
14
+ formats << Regexp.new('smithj@' + dom)
15
+ formats << Regexp.new('smithj\d+@' + dom)
16
+
17
+ 100.times do
18
+ email = domain ? Fakir::EmailAddress.new(firstname, lastname, domain) : Fakir::EmailAddress.new(firstname, lastname)
19
+ assert formats.find { |fmt| fmt.match(email) }, "email: #{email}"
20
+ end
21
+ end
22
+
23
+ def test_default_domain_simple_name
24
+ run_email_test "john", "smith"
25
+ end
26
+
27
+ def test_default_domain_uppercase_name
28
+ run_email_test "John", "Smith"
29
+ end
30
+
31
+ def test_default_domain_non_alpha_characters
32
+ run_email_test "Jo-hn", "S'mi.th"
33
+ end
34
+
35
+ def test_different_domain_simple_characters
36
+ run_email_test "john", "smith", "foo.bar.com"
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'test/unit'
5
+ require_relative '../lib/fakir/random'
6
+
7
+ class RandomTest < Test::Unit::TestCase
8
+ def assert_not_in_window nums, num, idx, window
9
+ if num
10
+ prev = nums[0 ... idx].rindex num
11
+ if prev
12
+ assert_not_nil window, "prev: #{prev}"
13
+ diff = idx - prev
14
+ assert diff >= window, "diff: #{diff}; window: #{window}"
15
+ end
16
+ end
17
+ end
18
+
19
+ def run_window_test max, window
20
+ rnd = Fakir::Random.new max, window
21
+ nums = 20.times.collect { rnd.rand }
22
+ nums.each_with_index do |num, idx|
23
+ assert_not_in_window nums, num, idx, window
24
+ end
25
+ end
26
+
27
+ def test_window_1
28
+ run_window_test 4, 1
29
+ end
30
+
31
+ def test_window_2
32
+ run_window_test 4, 2
33
+ end
34
+
35
+ def test_window_3
36
+ run_window_test 4, 3
37
+ end
38
+
39
+ def test_no_window
40
+ run_window_test 4, nil
41
+ end
42
+
43
+ def test_invalid_window
44
+ assert_raises RuntimeError, "window 10 should be less than maximum 10" do
45
+ Fakir::Random.new 10, 10
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'test/unit'
5
+ require_relative '../lib/fakir'
6
+
7
+ class VersionTest < Test::Unit::TestCase
8
+ def test_version
9
+ assert_equal "0.0.1", Fakir::VERSION
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Pace
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Generates data using less-than-random data, such as non-sequential random
42
+ numbers.
43
+ email:
44
+ - jeugenepace@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - fakir.gemspec
56
+ - lib/fakir.rb
57
+ - lib/fakir/array.rb
58
+ - lib/fakir/email.rb
59
+ - lib/fakir/random.rb
60
+ - lib/fakir/version.rb
61
+ - test/array_test.rb
62
+ - test/email_test.rb
63
+ - test/random_test.rb
64
+ - test/version_test.rb
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Generates less-random fake data.
89
+ test_files:
90
+ - test/array_test.rb
91
+ - test/email_test.rb
92
+ - test/random_test.rb
93
+ - test/version_test.rb