hypothesis-specs 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/Cargo.toml +11 -0
- data/LICENSE.txt +8 -0
- data/README.markdown +86 -0
- data/Rakefile +145 -0
- data/ext/Makefile +7 -0
- data/ext/extconf.rb +5 -0
- data/lib/hypothesis.rb +223 -0
- data/lib/hypothesis/engine.rb +85 -0
- data/lib/hypothesis/errors.rb +28 -0
- data/lib/hypothesis/possible.rb +369 -0
- data/lib/hypothesis/testcase.rb +44 -0
- data/lib/hypothesis/world.rb +9 -0
- data/src/data.rs +99 -0
- data/src/distributions.rs +238 -0
- data/src/engine.rs +400 -0
- data/src/lib.rs +170 -0
- metadata +91 -0
data/src/lib.rs
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
// "Bridging" root code that exists exclusively to provide
|
2
|
+
// a ruby -> Hypothesis engine binding. Long term the code
|
3
|
+
// in here is the only code that is going to stay in this
|
4
|
+
// crate, and everything else is going to get factored out
|
5
|
+
// into its own.
|
6
|
+
|
7
|
+
#![recursion_limit = "256"]
|
8
|
+
#![deny(warnings, missing_debug_implementations)]
|
9
|
+
|
10
|
+
extern crate core;
|
11
|
+
#[macro_use]
|
12
|
+
extern crate helix;
|
13
|
+
extern crate rand;
|
14
|
+
|
15
|
+
mod engine;
|
16
|
+
mod data;
|
17
|
+
mod distributions;
|
18
|
+
|
19
|
+
use std::mem;
|
20
|
+
|
21
|
+
use engine::Engine;
|
22
|
+
use data::{DataSource, Status};
|
23
|
+
use distributions::Repeat;
|
24
|
+
|
25
|
+
ruby! {
|
26
|
+
class HypothesisCoreDataSource {
|
27
|
+
struct {
|
28
|
+
source: Option<DataSource>,
|
29
|
+
}
|
30
|
+
|
31
|
+
def initialize(helix, engine: &mut HypothesisCoreEngine){
|
32
|
+
let mut result = HypothesisCoreDataSource{helix, source: None};
|
33
|
+
mem::swap(&mut result.source, &mut engine.pending);
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
class HypothesisCoreEngine {
|
39
|
+
struct {
|
40
|
+
engine: Engine,
|
41
|
+
pending: Option<DataSource>,
|
42
|
+
}
|
43
|
+
|
44
|
+
def initialize(helix, seed: u64, max_examples: u64){
|
45
|
+
let xs: [u32; 2] = [seed as u32, (seed >> 32) as u32];
|
46
|
+
HypothesisCoreEngine{
|
47
|
+
helix,
|
48
|
+
engine: Engine::new(max_examples, &xs),
|
49
|
+
pending: None,
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
def new_source(&mut self) -> Option<HypothesisCoreDataSource> {
|
54
|
+
match self.engine.next_source() {
|
55
|
+
None => None,
|
56
|
+
Some(source) => {
|
57
|
+
self.pending = Some(source);
|
58
|
+
Some(HypothesisCoreDataSource::new(self))
|
59
|
+
},
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
def failing_example(&mut self) -> Option<HypothesisCoreDataSource> {
|
64
|
+
if let Some(source) = self.engine.best_source() {
|
65
|
+
self.pending = Some(source);
|
66
|
+
return Some(HypothesisCoreDataSource::new(self));
|
67
|
+
} else {
|
68
|
+
return None;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
def was_unsatisfiable(&mut self) -> bool {
|
73
|
+
self.engine.was_unsatisfiable()
|
74
|
+
}
|
75
|
+
|
76
|
+
def finish_overflow(&mut self, child: &mut HypothesisCoreDataSource){
|
77
|
+
mark_child_status(&mut self.engine, child, Status::Overflow);
|
78
|
+
}
|
79
|
+
|
80
|
+
def finish_invalid(&mut self, child: &mut HypothesisCoreDataSource){
|
81
|
+
mark_child_status(&mut self.engine, child, Status::Invalid);
|
82
|
+
}
|
83
|
+
|
84
|
+
def finish_interesting(&mut self, child: &mut HypothesisCoreDataSource){
|
85
|
+
mark_child_status(&mut self.engine, child, Status::Interesting);
|
86
|
+
}
|
87
|
+
|
88
|
+
def finish_valid(&mut self, child: &mut HypothesisCoreDataSource){
|
89
|
+
mark_child_status(&mut self.engine, child, Status::Valid);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
class HypothesisCoreBitPossible{
|
94
|
+
struct {
|
95
|
+
n_bits: u64,
|
96
|
+
}
|
97
|
+
|
98
|
+
def initialize(helix, n_bits: u64){
|
99
|
+
return HypothesisCoreBitPossible{helix, n_bits: n_bits};
|
100
|
+
}
|
101
|
+
|
102
|
+
def provide(&mut self, data: &mut HypothesisCoreDataSource) -> Option<u64>{
|
103
|
+
match &mut data.source {
|
104
|
+
&mut None => None,
|
105
|
+
&mut Some(ref mut source) => source.bits(self.n_bits).ok(),
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
class HypothesisCoreRepeatValues{
|
111
|
+
struct {
|
112
|
+
repeat: Repeat,
|
113
|
+
}
|
114
|
+
|
115
|
+
def initialize(helix, min_count: u64, max_count: u64, expected_count: f64){
|
116
|
+
return HypothesisCoreRepeatValues{
|
117
|
+
helix, repeat: Repeat::new(min_count, max_count, expected_count)
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
def _should_continue(&mut self, data: &mut HypothesisCoreDataSource) -> Option<bool>{
|
122
|
+
return data.source.as_mut().and_then(|ref mut source| {
|
123
|
+
self.repeat.should_continue(source).ok()
|
124
|
+
})
|
125
|
+
}
|
126
|
+
|
127
|
+
def reject(&mut self){
|
128
|
+
self.repeat.reject();
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
class HypothesisCoreIntegers{
|
133
|
+
struct {
|
134
|
+
bitlengths: distributions::Sampler,
|
135
|
+
}
|
136
|
+
def initialize(helix){
|
137
|
+
return HypothesisCoreIntegers{helix,bitlengths: distributions::good_bitlengths()};
|
138
|
+
}
|
139
|
+
def provide(&mut self, data: &mut HypothesisCoreDataSource) -> Option<i64>{
|
140
|
+
data.source.as_mut().and_then(|ref mut source| {
|
141
|
+
distributions::integer_from_bitlengths(source, &self.bitlengths).ok()
|
142
|
+
})
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
class HypothesisCoreBoundedIntegers{
|
147
|
+
struct {
|
148
|
+
max_value: u64,
|
149
|
+
}
|
150
|
+
def initialize(helix, max_value: u64){
|
151
|
+
return HypothesisCoreBoundedIntegers{helix, max_value: max_value};
|
152
|
+
}
|
153
|
+
|
154
|
+
def provide(&mut self, data: &mut HypothesisCoreDataSource) -> Option<u64>{
|
155
|
+
data.source.as_mut().and_then(|ref mut source| {
|
156
|
+
distributions::bounded_int(source, self.max_value).ok()
|
157
|
+
})
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
fn mark_child_status(engine: &mut Engine, child: &mut HypothesisCoreDataSource, status: Status) {
|
163
|
+
let mut replacement = None;
|
164
|
+
mem::swap(&mut replacement, &mut child.source);
|
165
|
+
|
166
|
+
match replacement {
|
167
|
+
Some(source) => engine.mark_finished(source, status),
|
168
|
+
None => (),
|
169
|
+
}
|
170
|
+
}
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hypothesis-specs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David R. Maciver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: helix_runtime
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.0
|
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: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: 'A port of the Hypothesis property-based testing library to Ruby
|
42
|
+
|
43
|
+
'
|
44
|
+
email: david@drmaciver.com
|
45
|
+
executables: []
|
46
|
+
extensions:
|
47
|
+
- ext/extconf.rb
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Cargo.toml
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.markdown
|
54
|
+
- Rakefile
|
55
|
+
- ext/Makefile
|
56
|
+
- ext/extconf.rb
|
57
|
+
- lib/hypothesis.rb
|
58
|
+
- lib/hypothesis/engine.rb
|
59
|
+
- lib/hypothesis/errors.rb
|
60
|
+
- lib/hypothesis/possible.rb
|
61
|
+
- lib/hypothesis/testcase.rb
|
62
|
+
- lib/hypothesis/world.rb
|
63
|
+
- src/data.rs
|
64
|
+
- src/distributions.rs
|
65
|
+
- src/engine.rs
|
66
|
+
- src/lib.rs
|
67
|
+
homepage: http://github.com/HypothesisWorks/hypothesis-ruby
|
68
|
+
licenses:
|
69
|
+
- MPL-2.0
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.6.14
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A port of the Hypothesis property-based testing library to Ruby
|
91
|
+
test_files: []
|