queencheck 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Guardfile +2 -1
- data/README.md +119 -0
- data/Rakefile +11 -0
- data/VERSION +1 -1
- data/lib/queencheck.rb +16 -13
- data/lib/queencheck/arbitraries/all.rb +5 -0
- data/lib/queencheck/arbitraries/boolean.rb +5 -0
- data/lib/queencheck/arbitraries/integer.rb +17 -0
- data/lib/queencheck/arbitraries/string.rb +39 -0
- data/lib/queencheck/arbitrary.rb +84 -40
- data/lib/queencheck/condition.rb +112 -0
- data/lib/queencheck/core.rb +82 -97
- data/lib/queencheck/exception.rb +4 -0
- data/lib/queencheck/gen.rb +254 -0
- data/lib/queencheck/result.rb +107 -0
- data/lib/queencheck/rspec.rb +50 -9
- data/queencheck.gemspec +26 -18
- data/spec/queencheck/arbitrary_spec.rb +8 -34
- data/spec/queencheck/core_spec.rb +12 -40
- data/spec/queencheck/gen_spec.rb +68 -0
- data/spec/queencheck/rspec_spec.rb +14 -14
- metadata +76 -42
- data/README.markdown +0 -24
- data/lib/queencheck/array.rb +0 -33
- data/lib/queencheck/boolean.rb +0 -9
- data/lib/queencheck/config.rb +0 -16
- data/lib/queencheck/elements_of.rb +0 -44
- data/lib/queencheck/float.rb +0 -23
- data/lib/queencheck/integer.rb +0 -16
- data/lib/queencheck/rspec/dsl.rb +0 -22
- data/lib/queencheck/string.rb +0 -47
- data/spec/queencheck/elements_of_spec.rb +0 -22
- data/spec/queencheck/integer_spec.rb +0 -17
- data/spec/queencheck/string_spec.rb +0 -13
data/lib/queencheck/integer.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'queencheck/arbitrary'
|
2
|
-
|
3
|
-
class Integer
|
4
|
-
extend QueenCheck::Arbitrary
|
5
|
-
|
6
|
-
@@bound = 25
|
7
|
-
|
8
|
-
set_arbitrary do |seed|
|
9
|
-
if seed == 0
|
10
|
-
0
|
11
|
-
else
|
12
|
-
max = 10 ** ((@@bound * seed).ceil)
|
13
|
-
rand(max) * (rand(2).zero? ? 1 : -1)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/queencheck/rspec/dsl.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Core
|
5
|
-
class ExampleGroup
|
6
|
-
def self.qcheck(instance, method, arbitraries, options = {}, &block)
|
7
|
-
describe "QC: #{instance.class}##{method}(#{arbitraries.join(', ')})" do
|
8
|
-
QueenCheck(instance, method, *arbitraries).run(options) do | result, args, error |
|
9
|
-
it("Gen: #{args.join(', ')}"){
|
10
|
-
begin
|
11
|
-
self.instance_eval_with_args(*[result, args, error], &block)
|
12
|
-
rescue => e
|
13
|
-
e.set_backtrace(e.backtrace.slice(0,6) + e.backtrace.slice(9, 100))
|
14
|
-
raise e
|
15
|
-
end
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/queencheck/string.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'queencheck/arbitrary'
|
2
|
-
|
3
|
-
class String
|
4
|
-
extend QueenCheck::Arbitrary
|
5
|
-
|
6
|
-
@@max_length = 256
|
7
|
-
|
8
|
-
set_arbitrary do | seed |
|
9
|
-
max = (@@max_length * (seed * seed)).ceil
|
10
|
-
|
11
|
-
charset = []
|
12
|
-
if seed == 0
|
13
|
-
return ''
|
14
|
-
elsif seed < 0.1
|
15
|
-
charset = (0x61 ... 0x7b).to_a + (0x41 ... 0x5b).to_a
|
16
|
-
elsif seed < 0.3 # ASCII
|
17
|
-
charset = (0x32 ... 0x7f).to_a
|
18
|
-
elsif seed < 0.5
|
19
|
-
charset = (0x00 ... 0x80).to_a
|
20
|
-
elsif seed < 0.7
|
21
|
-
charset = (0x00 ... 0x80).to_a
|
22
|
-
charset += (0x80 ... 0x800).to_a
|
23
|
-
elsif seed < 0.9
|
24
|
-
charset = (0x00 ... 0x80).to_a
|
25
|
-
charset += (0x80 ... 0x800).to_a
|
26
|
-
charset += (0x800 ... 0x8000).to_a
|
27
|
-
elsif seed <= 1
|
28
|
-
charset = (0x00 ... 0x80).to_a
|
29
|
-
charset += (0x80 ... 0x800).to_a
|
30
|
-
charset += (0x800 ... 0x8000).to_a
|
31
|
-
charset += (0x1000 ... 0x20000).to_a
|
32
|
-
end
|
33
|
-
|
34
|
-
if !charset.respond_to?(:sample)
|
35
|
-
class << charset
|
36
|
-
def sample; self[rand(self.length)]; end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
ret = []
|
41
|
-
(rand(max/2) + (max/2)).ceil.times do
|
42
|
-
ret << charset.sample
|
43
|
-
end
|
44
|
-
|
45
|
-
return ret.pack('U*')
|
46
|
-
end
|
47
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'queencheck/elements_of'
|
2
|
-
|
3
|
-
describe QueenCheck::ElementsOf do
|
4
|
-
before(:each) do
|
5
|
-
@samples = ['a', 'b', 'c']
|
6
|
-
@elements_of = QueenCheck::ElementsOf.new(@samples)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'choose one' do
|
10
|
-
100.times do
|
11
|
-
@samples.should be_include(@elements_of.arbitrary(rand(10).to_f / 10))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'named type' do
|
16
|
-
named = QueenCheck::ElementsOf(:names, ['test', 'sample'])
|
17
|
-
|
18
|
-
named.should be_kind_of(QueenCheck::ElementsOf)
|
19
|
-
QueenCheck::ElementsOf(:names).should eq(named)
|
20
|
-
QueenCheck::Arbitrary(:elements_of_names).should eq(named)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'queencheck/integer'
|
2
|
-
|
3
|
-
describe Integer do
|
4
|
-
it ".arbitrary?" do
|
5
|
-
Integer.arbitrary?.should be_true
|
6
|
-
end
|
7
|
-
|
8
|
-
it ".arbitrary" do
|
9
|
-
100.times do
|
10
|
-
Integer.arbitrary(0).should be_zero
|
11
|
-
end
|
12
|
-
|
13
|
-
100.times do |n|
|
14
|
-
n = n / 100.0
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|