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
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
module QueenCheck
|
5
|
+
class Result
|
6
|
+
def initialize(properties, is_success, exception = nil)
|
7
|
+
@properties = properties
|
8
|
+
@is_success = is_success == true
|
9
|
+
unless exception.nil?
|
10
|
+
@exception = exception
|
11
|
+
@is_success = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
attr_reader :properties
|
15
|
+
|
16
|
+
def is_success?; @is_success; end
|
17
|
+
def is_failure?; !@is_success; end
|
18
|
+
def is_exception?; !@exception.nil?; end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ResultReport < Array
|
22
|
+
alias :tests :length
|
23
|
+
|
24
|
+
def initialize(*args)
|
25
|
+
super(*args)
|
26
|
+
@labels = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def pretty_report
|
30
|
+
justify = count(:all).to_s.size
|
31
|
+
label_justify = @labels.keys.map{|label| label.size}.max
|
32
|
+
[
|
33
|
+
"Tests: ".green + count(:all).to_s.colorize(count(:all) == count(:success) ? :green : :red),
|
34
|
+
" ✓ Successes : #{count(:success).to_s.rjust(justify)}#{
|
35
|
+
(@labels.empty? ? '' : "\n") + @labels.keys.map { |label|
|
36
|
+
" #{label.ljust(label_justify)} : #{count(label, successes).to_s.rjust(justify)}"
|
37
|
+
}.join("\n")
|
38
|
+
}".green,
|
39
|
+
" ✗ Failures : #{count(:failures).to_s.rjust(justify)}#{
|
40
|
+
(@labels.empty? ? '' : "\n") + @labels.keys.map { |label|
|
41
|
+
" #{label.ljust(label_justify)} : #{count(label, failures).to_s.rjust(justify)}"
|
42
|
+
}.join("\n")
|
43
|
+
}".yellow,
|
44
|
+
" ✷ Exceptions : #{count(:exception).to_s.rjust(justify)}#{
|
45
|
+
(@labels.empty? ? '' : "\n") + @labels.keys.map { |label|
|
46
|
+
" #{label.ljust(label_justify)} : #{count(label, exceptions).to_s.rjust(justify)}"
|
47
|
+
}.join("\n")
|
48
|
+
}".red
|
49
|
+
].join("\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
def report(with_label = true)
|
53
|
+
[
|
54
|
+
["tests", count(:all)],
|
55
|
+
["success", count(:success)],
|
56
|
+
["failure", count(:failure)],
|
57
|
+
["exception", count(:exception)]
|
58
|
+
] + (
|
59
|
+
if with_label
|
60
|
+
report_label
|
61
|
+
else
|
62
|
+
[]
|
63
|
+
end
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def report_label
|
68
|
+
@labels.keys.map { | label |
|
69
|
+
[label, count(label)]
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def count(label = :all, list = self)
|
74
|
+
case label
|
75
|
+
when :all, :tests
|
76
|
+
self.size
|
77
|
+
when :success, :successes
|
78
|
+
self.successes.size
|
79
|
+
when :failure, :failures
|
80
|
+
self.failures.size
|
81
|
+
when :exception, :exceptions
|
82
|
+
self.exceptions.size
|
83
|
+
else
|
84
|
+
raise ArgumentError, "`#{label}` is not valid label" if !@labels.has_key?(label)
|
85
|
+
list.reject {|result|
|
86
|
+
!@labels[label].call(*result.properties)
|
87
|
+
}.size
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def labeling(label, &block)
|
92
|
+
@labels[label] = block
|
93
|
+
end
|
94
|
+
|
95
|
+
def successes
|
96
|
+
self.reject{|result| result.is_failure? }
|
97
|
+
end
|
98
|
+
|
99
|
+
def failures
|
100
|
+
self.reject{|result| result.is_success? }
|
101
|
+
end
|
102
|
+
|
103
|
+
def exceptions
|
104
|
+
self.reject{|result| !result.is_exception? }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/queencheck/rspec.rb
CHANGED
@@ -1,11 +1,52 @@
|
|
1
|
+
require 'queencheck'
|
2
|
+
require 'rspec'
|
1
3
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
module RSpec
|
5
|
+
module Core
|
6
|
+
class ExampleGroup
|
7
|
+
def self.QueenCheck(name, *args, &block)
|
8
|
+
describe(*[name]) {
|
9
|
+
report = nil
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
it "running tests" do
|
12
|
+
report = ::QueenCheck::Testable.new(*args, &block).check
|
13
|
+
end
|
14
|
+
|
15
|
+
it "all tests passes" do
|
16
|
+
report.count(:all).should == report.count(:success)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.verboseQueenCheck(name, *args, &block)
|
22
|
+
describe(*[name]) {
|
23
|
+
assert = proc { | *props |
|
24
|
+
proc{ block.call(*props) }
|
25
|
+
}
|
26
|
+
its = proc { | *props |
|
27
|
+
it("Gen: #{props.map{|i| i.inspect}.join(', ')}", &assert.call(*props))
|
28
|
+
}
|
29
|
+
::QueenCheck::Testable.new(*args, &its).check
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.labelingQueenCheck(name, labels, *args, &block)
|
34
|
+
checker = ::QueenCheck::Testable.new(*args, &block)
|
35
|
+
report = checker.check_with_label(labels)
|
36
|
+
describe(*[name]) {
|
37
|
+
it "all tests passes" do
|
38
|
+
report.count(:all).should == report.count(:success)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "labels" do
|
42
|
+
labels.each_pair do | label, p |
|
43
|
+
it label do
|
44
|
+
report.count(label).should == report.count(label, report.successes)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/queencheck.gemspec
CHANGED
@@ -5,15 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "queencheck"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sho Kusano"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-17"
|
13
13
|
s.description = "QueenCheck is random test library. Inspired by QuickCheck library in Haskell."
|
14
14
|
s.email = "rosylilly@aduca.org"
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"README.
|
16
|
+
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".rspec",
|
@@ -21,40 +21,40 @@ Gem::Specification.new do |s|
|
|
21
21
|
".travis.yml",
|
22
22
|
"Gemfile",
|
23
23
|
"Guardfile",
|
24
|
-
"README.
|
24
|
+
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/queencheck.rb",
|
28
|
+
"lib/queencheck/arbitraries/all.rb",
|
29
|
+
"lib/queencheck/arbitraries/boolean.rb",
|
30
|
+
"lib/queencheck/arbitraries/integer.rb",
|
31
|
+
"lib/queencheck/arbitraries/string.rb",
|
28
32
|
"lib/queencheck/arbitrary.rb",
|
29
|
-
"lib/queencheck/
|
30
|
-
"lib/queencheck/boolean.rb",
|
31
|
-
"lib/queencheck/config.rb",
|
33
|
+
"lib/queencheck/condition.rb",
|
32
34
|
"lib/queencheck/core.rb",
|
33
|
-
"lib/queencheck/
|
34
|
-
"lib/queencheck/
|
35
|
-
"lib/queencheck/
|
36
|
-
"lib/queencheck/string.rb",
|
35
|
+
"lib/queencheck/exception.rb",
|
36
|
+
"lib/queencheck/gen.rb",
|
37
|
+
"lib/queencheck/result.rb",
|
37
38
|
"queencheck.gemspec",
|
38
39
|
"spec/queencheck/arbitrary_spec.rb",
|
39
40
|
"spec/queencheck/core_spec.rb",
|
40
|
-
"spec/queencheck/
|
41
|
-
"spec/queencheck/integer_spec.rb",
|
42
|
-
"spec/queencheck/string_spec.rb",
|
41
|
+
"spec/queencheck/gen_spec.rb",
|
43
42
|
"spec/spec_helper.rb"
|
44
43
|
]
|
45
44
|
s.homepage = "https://github.com/rosylilly/QueenCheck"
|
46
45
|
s.require_paths = ["lib"]
|
47
|
-
s.rubygems_version = "1.8.
|
46
|
+
s.rubygems_version = "1.8.11"
|
48
47
|
s.summary = "like haskell's QuickCheck"
|
49
48
|
|
50
49
|
if s.respond_to? :specification_version then
|
51
50
|
s.specification_version = 3
|
52
51
|
|
53
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
-
s.
|
53
|
+
s.add_runtime_dependency(%q<colorize>, [">= 0.5.8"])
|
55
54
|
s.add_development_dependency(%q<rake>, [">= 0.9.2.2"])
|
56
55
|
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
57
56
|
s.add_development_dependency(%q<fuubar>, [">= 0.0.6"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
|
58
58
|
s.add_development_dependency(%q<growl>, [">= 1.0.3"])
|
59
59
|
s.add_development_dependency(%q<spork>, [">= 0.9.0.rc9"])
|
60
60
|
s.add_development_dependency(%q<rb-fsevent>, [">= 0.9.0"])
|
@@ -64,11 +64,14 @@ Gem::Specification.new do |s|
|
|
64
64
|
s.add_development_dependency(%q<guard-yard>, [">= 1.0.2"])
|
65
65
|
s.add_development_dependency(%q<yard>, [">= 0.7.4"])
|
66
66
|
s.add_development_dependency(%q<yard-tomdoc>, [">= 0.3.0"])
|
67
|
+
s.add_development_dependency(%q<redcarpet>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
67
69
|
else
|
68
|
-
s.add_dependency(%q<
|
70
|
+
s.add_dependency(%q<colorize>, [">= 0.5.8"])
|
69
71
|
s.add_dependency(%q<rake>, [">= 0.9.2.2"])
|
70
72
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
71
73
|
s.add_dependency(%q<fuubar>, [">= 0.0.6"])
|
74
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
72
75
|
s.add_dependency(%q<growl>, [">= 1.0.3"])
|
73
76
|
s.add_dependency(%q<spork>, [">= 0.9.0.rc9"])
|
74
77
|
s.add_dependency(%q<rb-fsevent>, [">= 0.9.0"])
|
@@ -78,12 +81,15 @@ Gem::Specification.new do |s|
|
|
78
81
|
s.add_dependency(%q<guard-yard>, [">= 1.0.2"])
|
79
82
|
s.add_dependency(%q<yard>, [">= 0.7.4"])
|
80
83
|
s.add_dependency(%q<yard-tomdoc>, [">= 0.3.0"])
|
84
|
+
s.add_dependency(%q<redcarpet>, [">= 0"])
|
85
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
81
86
|
end
|
82
87
|
else
|
83
|
-
s.add_dependency(%q<
|
88
|
+
s.add_dependency(%q<colorize>, [">= 0.5.8"])
|
84
89
|
s.add_dependency(%q<rake>, [">= 0.9.2.2"])
|
85
90
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
86
91
|
s.add_dependency(%q<fuubar>, [">= 0.0.6"])
|
92
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
87
93
|
s.add_dependency(%q<growl>, [">= 1.0.3"])
|
88
94
|
s.add_dependency(%q<spork>, [">= 0.9.0.rc9"])
|
89
95
|
s.add_dependency(%q<rb-fsevent>, [">= 0.9.0"])
|
@@ -93,6 +99,8 @@ Gem::Specification.new do |s|
|
|
93
99
|
s.add_dependency(%q<guard-yard>, [">= 1.0.2"])
|
94
100
|
s.add_dependency(%q<yard>, [">= 0.7.4"])
|
95
101
|
s.add_dependency(%q<yard-tomdoc>, [">= 0.3.0"])
|
102
|
+
s.add_dependency(%q<redcarpet>, [">= 0"])
|
103
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
96
104
|
end
|
97
105
|
end
|
98
106
|
|
@@ -1,42 +1,16 @@
|
|
1
1
|
require 'queencheck/arbitrary'
|
2
2
|
|
3
3
|
describe QueenCheck::Arbitrary do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it 'arbitrary' do
|
9
|
-
expect {
|
10
|
-
Example.arbitrary(1)
|
11
|
-
}.to raise_error NotImplementedError
|
12
|
-
|
13
|
-
Example.class_eval do
|
14
|
-
def arbitrary(seed)
|
4
|
+
it "define" do
|
5
|
+
class Klass
|
6
|
+
arbitrary do | progress, rnd |
|
7
|
+
rnd
|
15
8
|
end
|
16
9
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'Original Arbitrary' do
|
20
|
-
it 'new' do
|
21
|
-
arb = QueenCheck::Arbitrary() do | seed |
|
22
|
-
if seed < 0.5
|
23
|
-
10**20
|
24
|
-
else
|
25
|
-
""
|
26
|
-
end
|
27
|
-
end
|
28
10
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
it 'named search' do
|
35
|
-
arb = QueenCheck::Arbitrary(:sample) { (1..10).to_a[rand(10)] }
|
36
|
-
|
37
|
-
QueenCheck::Arbitrary(:sample).should eq(arb)
|
38
|
-
QueenCheck(Kernel, :p, :sample).should_not be_nil
|
39
|
-
end
|
11
|
+
Klass.arbitrary.should be_instance_of(QueenCheck::Arbitrary)
|
12
|
+
Klass.arbitrary?.should == true
|
13
|
+
Class.arbitrary.should be_nil
|
14
|
+
Class.arbitrary?.should == false
|
40
15
|
end
|
41
16
|
end
|
42
|
-
|
@@ -1,42 +1,14 @@
|
|
1
1
|
require 'queencheck'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ret.failures.should eq(0)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'exception' do
|
19
|
-
div = QueenCheck(5, :/, Integer)
|
20
|
-
|
21
|
-
ret = div.run do | result, arguments, error |
|
22
|
-
if error
|
23
|
-
error.should be_kind_of(ZeroDivisionError)
|
24
|
-
else
|
25
|
-
result.should eq(5 / arguments[0])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
ret.examples.should eq(100)
|
30
|
-
ret.passes.should eq(100)
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'Task' do
|
34
|
-
it 'verbose' do
|
35
|
-
task = QueenCheck::Core::Task.new(1, :+, [1])
|
36
|
-
|
37
|
-
task.run! do | result, arguments, error |
|
38
|
-
result != arguments[0]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
3
|
+
prop_int = QueenCheck::Testable.new(
|
4
|
+
QueenCheck::Gen.choose(0, 100),
|
5
|
+
QueenCheck::Gen.choose(0, 100)
|
6
|
+
) { | x, y |
|
7
|
+
x + y == y + x
|
8
|
+
}
|
9
|
+
|
10
|
+
puts prop_int.check_with_label(
|
11
|
+
"x > y" => proc {|x, y| x > y },
|
12
|
+
"x < y" => proc {|x, y| x < y },
|
13
|
+
"x == y" => proc {|x, y| x == y }
|
14
|
+
).pretty_report
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'queencheck/gen'
|
2
|
+
|
3
|
+
describe QueenCheck::Gen do
|
4
|
+
it "initialize" do
|
5
|
+
QueenCheck::Gen.new { | progress, rnd |
|
6
|
+
[progress, rnd]
|
7
|
+
}.should be_instance_of(QueenCheck::Gen)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#choose" do
|
11
|
+
choose = QueenCheck::Gen.choose(0, 100)
|
12
|
+
choose.should be_instance_of(QueenCheck::Gen)
|
13
|
+
10000.times do | n |
|
14
|
+
v = choose.value(n)[0]
|
15
|
+
v.should >= 0
|
16
|
+
v.should <= 100
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#one_of" do
|
21
|
+
one_of = QueenCheck::Gen.one_of([
|
22
|
+
QueenCheck::Gen.elements_of([1, 2, 3]),
|
23
|
+
QueenCheck::Gen.choose(5, 10)
|
24
|
+
])
|
25
|
+
|
26
|
+
10000.times do | n |
|
27
|
+
v = one_of.value(n)[0]
|
28
|
+
v.should >= 1
|
29
|
+
v.should <= 10
|
30
|
+
v.should_not == 4
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "#where" do
|
35
|
+
gen = QueenCheck::Gen.choose(0, 10)
|
36
|
+
|
37
|
+
include_gen = gen.where(
|
38
|
+
:include => [0,2,3]
|
39
|
+
).where(
|
40
|
+
:not_equal => 0
|
41
|
+
)
|
42
|
+
10000.times do | n |
|
43
|
+
v = include_gen.value(n)
|
44
|
+
[2, 3].include?(v[0]).should == v[1]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#frequency" do
|
49
|
+
gen = QueenCheck::Gen.frequency([
|
50
|
+
[1, QueenCheck::Gen.elements_of([0])],
|
51
|
+
[3, QueenCheck::Gen.elements_of([1])]
|
52
|
+
])
|
53
|
+
|
54
|
+
stat = {
|
55
|
+
:a => 0,
|
56
|
+
:b => 0
|
57
|
+
}
|
58
|
+
10000.times do | n |
|
59
|
+
v = gen.value(n)
|
60
|
+
if v[0] == 0
|
61
|
+
stat[:a] += 1
|
62
|
+
else
|
63
|
+
stat[:b] += 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
stat[:a].should <= stat[:b]
|
67
|
+
end
|
68
|
+
end
|