contracts-gen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/contracts-gen.gemspec +38 -0
- data/lib/contracts/builtin_ext.rb +96 -0
- data/lib/contracts/gen.rb +51 -0
- data/lib/contracts/gen/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4f16e3702e3deb6d8a8febfc9594fdbec2b588e4f44bd4c7df168205d51bac4c
|
4
|
+
data.tar.gz: fbe52184b65a1a230c282064b88aaab8604efd6793956b03db050f371ce881a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c4c9abdd7a86b8e86027b4c6274377d109efbc4f86271d041aa8a0991316f1cf81a21c4df54d4dc4c8282ad8ab7dac0b68995cd1cdf8c7e914a4faefc9b0765
|
7
|
+
data.tar.gz: bea2d47332693dedf696f8e87858b8139dd953b855e8b49373824ffb2b38319df71c851b1e62c845278900ff492f4f03c74b7fa2af8fa7b19a9d00531af77603
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
contracts-gen (0.1.0)
|
5
|
+
contracts (~> 0.16.0)
|
6
|
+
faker (~> 1.9.6)
|
7
|
+
gen-test (~> 0.1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
concurrent-ruby (1.1.5)
|
13
|
+
contracts (0.16.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
faker (1.9.6)
|
16
|
+
i18n (>= 0.7)
|
17
|
+
gen-test (0.1.1)
|
18
|
+
faker (~> 1.9.6)
|
19
|
+
regexp-examples (~> 1.5.0)
|
20
|
+
i18n (1.8.2)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
regexp-examples (1.5.1)
|
24
|
+
rspec (3.8.0)
|
25
|
+
rspec-core (~> 3.8.0)
|
26
|
+
rspec-expectations (~> 3.8.0)
|
27
|
+
rspec-mocks (~> 3.8.0)
|
28
|
+
rspec-core (3.8.2)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-expectations (3.8.4)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-mocks (3.8.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-support (3.8.2)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 2.0)
|
43
|
+
contracts-gen!
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec (~> 3.0)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Delon Newman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Contracts::Gen
|
2
|
+
==============
|
3
|
+
|
4
|
+
An extension for [Gen::Test][1], defining generators for [Contracts][2].
|
5
|
+
|
6
|
+
Synopsis
|
7
|
+
========
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'gen/test'
|
11
|
+
require 'contracts'
|
12
|
+
require 'contracts/gen'
|
13
|
+
|
14
|
+
Sum = lambda { |xs| xs.reduce(:+) }
|
15
|
+
|
16
|
+
C = Contracts
|
17
|
+
|
18
|
+
class SumTest < Minitest::Test
|
19
|
+
include Gen::Test
|
20
|
+
|
21
|
+
def test_sum_for_all_arrays_of_integers
|
22
|
+
for_all C::ArrayOf[Integer] do |xs|
|
23
|
+
y = Sum[xs]
|
24
|
+
assert_equal(y, xs.reduce(:+))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Install
|
31
|
+
=======
|
32
|
+
|
33
|
+
> gem install contracts-gen
|
34
|
+
|
35
|
+
or, add:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'contracts-gen'
|
39
|
+
```
|
40
|
+
|
41
|
+
to your Gemfile, and then execute:
|
42
|
+
|
43
|
+
> bundle
|
44
|
+
|
45
|
+
|
46
|
+
See Also
|
47
|
+
========
|
48
|
+
|
49
|
+
- [Gen::Test][1]
|
50
|
+
- [Contracts][2]
|
51
|
+
|
52
|
+
[1]: https://github.com/delonnewman/gen-test
|
53
|
+
[2]: https://github.com/egonSchiele/contracts.ruby
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "contracts/gen/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "contracts-gen"
|
7
|
+
spec.version = Contracts::Gen::VERSION
|
8
|
+
spec.authors = ["Delon Newman"]
|
9
|
+
spec.email = ["contact@delonnewman.name"]
|
10
|
+
|
11
|
+
spec.summary = %q{Contracts for generative testing}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/delonnewman/contracts-gen"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}#changelog"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "faker", "~> 1.9.6"
|
32
|
+
spec.add_runtime_dependency "gen-test", "~> 0.1.0"
|
33
|
+
spec.add_runtime_dependency "contracts", "~> 0.16.0"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
|
3
|
+
module Contracts::Builtin
|
4
|
+
class Bool
|
5
|
+
def self.generate(true_ratio: 0.5)
|
6
|
+
Random.rand < true_ratio
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Num
|
11
|
+
def self.generate(min: -2e31.to_f, max: (2e31 - 1).to_f)
|
12
|
+
raise 'min should not be greater than max' if min > max
|
13
|
+
Random.rand(min..max)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Int
|
18
|
+
def self.generate(min: -2e31, max: 2e31 - 1, neg_ratio: 0.5)
|
19
|
+
min_pos = min < 0 ? 0 : min
|
20
|
+
max_neg = max > -1 ? -1 : max
|
21
|
+
|
22
|
+
if Bool.generate(true_ratio: neg_ratio)
|
23
|
+
Num.generate(min: min, max: max_neg).to_i
|
24
|
+
else
|
25
|
+
Num.generate(min: min_pos, max: max).to_i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class BigInt < Int
|
31
|
+
def self.generate(min: -2e63, max: 2e63 - 1)
|
32
|
+
super(min: min, max: max)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class SmallInt < Int
|
37
|
+
def self.generate(min: -2e15, max: 2e15 - 1)
|
38
|
+
super(min: min, max: max)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class TinyInt < Int
|
43
|
+
def self.generate(min: 0, max: 255)
|
44
|
+
super(min: min, max: max)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Neg
|
49
|
+
def self.generate(min: -1_000, max: -1)
|
50
|
+
raise 'max should not be greater than -1' if max > -1
|
51
|
+
Num.generate(min: min, max: max).to_i
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Pos
|
56
|
+
def self.generate(min: 1, max: 1_000)
|
57
|
+
raise 'min should not be less than 1' if min < 1
|
58
|
+
Num.generate(min: min, max: max).to_i
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Nat
|
63
|
+
def self.generate(min: 0, max: 1_000)
|
64
|
+
raise 'min should not be less than 0' if min < 0
|
65
|
+
Num.generate(min: min, max: max).to_i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Maybe
|
70
|
+
def generate(nil_ratio: 0.5)
|
71
|
+
if Bool.generate(true_ratio: nil_ratio)
|
72
|
+
@vals.reject(&:nil?).first.generate
|
73
|
+
else
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class CollectionOf
|
80
|
+
def generate(min: 0, max: 30)
|
81
|
+
@collection_class.generate(min: min, max: max, type: @contract)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class HashOf
|
86
|
+
def generate(min: 0, max: 30)
|
87
|
+
Hash.generate(min: min, max: max, value_type: @value, key_type: @key)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class Or
|
92
|
+
def generate
|
93
|
+
@vals.sample.generate
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "contracts/gen/version"
|
2
|
+
require "contracts/builtin_ext"
|
3
|
+
require 'gen/test'
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
module Contracts
|
7
|
+
class Keys
|
8
|
+
def self.[](spec)
|
9
|
+
if spec[:required] and spec[:optional]
|
10
|
+
new(spec[:required], spec[:optional])
|
11
|
+
elsif spec[:required]
|
12
|
+
new(spec[:required], nil)
|
13
|
+
elsif spec[:optional]
|
14
|
+
new(nil, spec[:optional])
|
15
|
+
else
|
16
|
+
raise "Invalid hash spec: #{spec.inspect}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(required, optional)
|
21
|
+
@required = required
|
22
|
+
@optional = optional
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?(value)
|
26
|
+
if not value.respond_to?(:[])
|
27
|
+
false
|
28
|
+
else
|
29
|
+
@required.all? { |(k, v)| Contract.valid?(value[k], v) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate
|
34
|
+
h = {}
|
35
|
+
unless @required.nil? or @required.empty?
|
36
|
+
@required.each do |(k, contract)|
|
37
|
+
h[k] = ::Gen.generate(contract)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
unless @optional.nil? or @optional.empty?
|
41
|
+
n = Faker::Number.between(0, @optional.keys.length)
|
42
|
+
keys = @optional.keys.sample(n)
|
43
|
+
keys.each do |k|
|
44
|
+
contract = @optional[k]
|
45
|
+
h[k] = ::Gen.generate(contract)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
h
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contracts-gen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Delon Newman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faker
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.9.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.9.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gen-test
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: contracts
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.16.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.16.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Contracts for generative testing
|
98
|
+
email:
|
99
|
+
- contact@delonnewman.name
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- contracts-gen.gemspec
|
112
|
+
- lib/contracts/builtin_ext.rb
|
113
|
+
- lib/contracts/gen.rb
|
114
|
+
- lib/contracts/gen/version.rb
|
115
|
+
homepage: https://github.com/delonnewman/contracts-gen
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata:
|
119
|
+
allowed_push_host: https://rubygems.org
|
120
|
+
homepage_uri: https://github.com/delonnewman/contracts-gen
|
121
|
+
source_code_uri: https://github.com/delonnewman/contracts-gen
|
122
|
+
changelog_uri: https://github.com/delonnewman/contracts-gen#changelog
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.0.6
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Contracts for generative testing
|
142
|
+
test_files: []
|