randomly_generated 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +33 -0
- data/Rakefile +3 -0
- data/lib/randomly_generated.rb +22 -0
- data/lib/randomly_generated/integer.rb +25 -0
- data/lib/randomly_generated/object.rb +24 -0
- data/lib/randomly_generated/string.rb +13 -0
- data/lib/randomly_generated/version.rb +3 -0
- data/randomly_generated.gemspec +25 -0
- data/spec/spec_helper.rb +78 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 704e1a8d3330ea94e721d15afade35fdc0c3a666
|
4
|
+
data.tar.gz: d2f69b402511d3b116838614baff797cc0bde410
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 873ba0c07b3eb06bf89e4f7f9c5df22387c12e32584c47e2d9935a4e89220c78c39cd2669e87bda9163a31d0e19eabdee7736e3484d21e02b781e3b15f73593b
|
7
|
+
data.tar.gz: e084dc58b0a4a52a89a94752a1e937bdd00816816c0f96b130c49fdf778c17aeb61e03126cf407ac4ad25d9f802af7ab79fd31ebaf18e05772926f5707d437fd
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2014 BoochTek, LLC
|
2
|
+
Copyright (c) 2014 Craig Buchek
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# RandomlyGenerated
|
2
|
+
|
3
|
+
Randomly generate data, to use with property-based tests
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'randomly_generated'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install randomly_generated
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This is currently a proof of concept, to be used in conjunction with
|
24
|
+
the rspec-generative gem.
|
25
|
+
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/randomly_generated/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "randomly_generated/version"
|
2
|
+
require "randomly_generated/object"
|
3
|
+
require "randomly_generated/integer"
|
4
|
+
require "randomly_generated/string"
|
5
|
+
|
6
|
+
|
7
|
+
module RandomlyGenerated
|
8
|
+
def self.respond_to?(method_name)
|
9
|
+
class_name = method_name.to_s.split("_").map(&:capitalize).join
|
10
|
+
Object.const_defined?("::RandomlyGenerated::#{class_name}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.method_missing(method_name, *args, &block)
|
14
|
+
if respond_to?(method_name)
|
15
|
+
class_name = method_name.to_s.split("_").map(&:capitalize).join
|
16
|
+
class_const = Object.const_get("::RandomlyGenerated::#{class_name}")
|
17
|
+
class_const.new(*args, &block)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# From https://gist.github.com/pithyless/9738125
|
2
|
+
class Integer
|
3
|
+
N_BYTES = [42].pack('i').size
|
4
|
+
N_BITS = N_BYTES * 16
|
5
|
+
MAX = 2 ** (N_BITS - 2) - 1
|
6
|
+
MIN = -MAX - 1
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
class RandomlyGenerated::Integer < RandomlyGenerated::Object
|
11
|
+
attr_reader :minimum
|
12
|
+
attr_reader :maximum
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
super
|
16
|
+
options[:range] ||= Integer::MIN..Integer::MAX
|
17
|
+
@minimum = options.fetch(:minimum) { options.fetch(:range).first }
|
18
|
+
@maximum = options.fetch(:maximum) { options.fetch(:range).last }
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
# TODO: We should weight this to make more "special edge-case" results show up -- like 0, 1, Integer::MAX, etc.
|
23
|
+
@value ||= rand.rand(minimum..maximum)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This is the base class for all classes used to generate random objects.
|
2
|
+
class RandomlyGenerated::Object
|
3
|
+
attr_reader :seed
|
4
|
+
attr_reader :rand
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@seed = options.fetch(:seed) { Random.new_seed }
|
8
|
+
@rand = Random.new(seed)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the generated object.
|
12
|
+
def call
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns an array of "shrunken" proper subsets of the object.
|
17
|
+
# These subsets are intended to find simpler cases that will reproduce a test failure.
|
18
|
+
# WARNING: This API will likely change. We plan to experiment with it heavily.
|
19
|
+
# One idea is to have it take a block instead, and pass the various subsets to the block.
|
20
|
+
def shrunken_subsets
|
21
|
+
# By default, assume that the object is atomic and cannot be simplified.
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RandomlyGenerated::String < RandomlyGenerated::Object
|
2
|
+
attr_reader :length
|
3
|
+
|
4
|
+
def initialize(options={})
|
5
|
+
super
|
6
|
+
@length = options.fetch(:length) { (1..5000) }
|
7
|
+
@length = rand.rand(@length) if @length.is_a?(Range)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
@value ||= rand.bytes(length) # TODO: This doesn't handle Unicode characters, only code points 0-255.
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'randomly_generated/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "randomly_generated"
|
8
|
+
spec.version = RandomlyGenerated::VERSION
|
9
|
+
spec.authors = ["Craig Buchek"]
|
10
|
+
spec.email = ["craig@boochtek.com"]
|
11
|
+
spec.summary = %q{Randomly generate different kinds of data}
|
12
|
+
spec.description = %q{Randomly generate data, to use with property-based tests}
|
13
|
+
spec.homepage = "https://github.com/boochtek/randomly_generated"
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rubygems-tasks"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
=begin
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# Use the documentation formatter for detailed output,
|
33
|
+
# unless a formatter has already been configured
|
34
|
+
# (e.g. via a command-line flag).
|
35
|
+
config.default_formatter = 'doc'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Print the 10 slowest examples and example groups at the
|
39
|
+
# end of the spec run, to help surface which specs are running
|
40
|
+
# particularly slow.
|
41
|
+
config.profile_examples = 10
|
42
|
+
|
43
|
+
# Run specs in random order to surface order dependencies. If you find an
|
44
|
+
# order dependency and want to debug it, you can fix the order by providing
|
45
|
+
# the seed, which is printed after each run.
|
46
|
+
# --seed 1234
|
47
|
+
config.order = :random
|
48
|
+
|
49
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
+
# test failures related to randomization by passing the same `--seed` value
|
52
|
+
# as the one that triggered the failure.
|
53
|
+
Kernel.srand config.seed
|
54
|
+
|
55
|
+
# rspec-expectations config goes here. You can use an alternate
|
56
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
+
# assertions if you prefer.
|
58
|
+
config.expect_with :rspec do |expectations|
|
59
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
expectations.syntax = :expect
|
63
|
+
end
|
64
|
+
|
65
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
+
config.mock_with :rspec do |mocks|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
mocks.syntax = :expect
|
72
|
+
|
73
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
+
# a real object. This is generally recommended.
|
75
|
+
mocks.verify_partial_doubles = true
|
76
|
+
end
|
77
|
+
=end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: randomly_generated
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Craig Buchek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-25 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubygems-tasks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Randomly generate data, to use with property-based tests
|
70
|
+
email:
|
71
|
+
- craig@boochtek.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/randomly_generated.rb
|
83
|
+
- lib/randomly_generated/integer.rb
|
84
|
+
- lib/randomly_generated/object.rb
|
85
|
+
- lib/randomly_generated/string.rb
|
86
|
+
- lib/randomly_generated/version.rb
|
87
|
+
- randomly_generated.gemspec
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/boochtek/randomly_generated
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Randomly generate different kinds of data
|
113
|
+
test_files:
|
114
|
+
- spec/spec_helper.rb
|