rushcheck 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -1
- data/Rakefile.in +9 -1
- data/data/rushcheck/doc/rushcheck.thtml +55 -0
- data/data/rushcheck/examples/proc.rb +1 -1
- data/data/rushcheck/examples/rspec/stack.rb +42 -0
- data/data/rushcheck/examples/rspec/stack_spec.rb +223 -0
- data/data/rushcheck/rdoc/classes/RushCheck/Arbitrary.src/M000035.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Assertion.html +14 -3
- data/data/rushcheck/rdoc/classes/RushCheck/Assertion.src/M000073.html +1 -2
- data/data/rushcheck/rdoc/classes/RushCheck/Assertion.src/M000074.html +6 -33
- data/data/rushcheck/rdoc/classes/RushCheck/Claim.html +199 -0
- data/data/rushcheck/rdoc/classes/RushCheck/Claim.src/M000107.html +21 -0
- data/data/rushcheck/rdoc/classes/RushCheck/Coarbitrary.src/M000058.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.html +3 -3
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000076.html +0 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000077.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000078.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000079.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000080.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000081.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000082.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000083.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000084.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000085.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000086.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000087.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000088.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000089.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000090.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000091.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000092.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000093.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck/Gen.src/M000094.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheck.html +25 -1
- data/data/rushcheck/rdoc/created.rid +1 -1
- data/data/rushcheck/rdoc/files/rushcheck/arbitrary_rb.html +20 -2
- data/data/rushcheck/rdoc/files/rushcheck/assertion_rb.html +1 -1
- data/data/rushcheck/rdoc/files/rushcheck/claim_rb.html +119 -0
- data/data/rushcheck/rdoc/files/rushcheck/gen_rb.html +1 -1
- data/data/rushcheck/rdoc/files/rushcheck/random_rb.html +1 -1
- data/data/rushcheck/rdoc/files/rushcheck/version_rb.html +107 -0
- data/data/rushcheck/rdoc/files/rushcheck_rb.html +3 -1
- data/data/rushcheck/rdoc/fr_class_index.html +1 -0
- data/data/rushcheck/rdoc/fr_file_index.html +2 -0
- data/data/rushcheck/rdoc/fr_method_index.html +8 -7
- data/lib/rushcheck/arbitrary.rb +15 -1
- data/lib/rushcheck/assertion.rb +21 -6
- data/lib/rushcheck/claim.rb +56 -0
- data/lib/rushcheck/gen.rb +2 -4
- data/lib/rushcheck/version.rb +1 -1
- data/lib/rushcheck.rb +1 -0
- metadata +11 -2
data/Rakefile
CHANGED
@@ -6,10 +6,18 @@ require 'rubygems'
|
|
6
6
|
require 'rake'
|
7
7
|
require 'rake/gempackagetask'
|
8
8
|
|
9
|
+
RUSHCHECK_VERSION="0.6"
|
10
|
+
task :default => ["dist", "gem"]
|
11
|
+
|
12
|
+
task :dist do
|
13
|
+
system "darcs dist -d rushcheck-#{RUSHCHECK_VERSION}"
|
14
|
+
system "mv rushcheck-#{RUSHCHECK_VERSION}.tar.gz pkg/"
|
15
|
+
end
|
16
|
+
|
9
17
|
spec = Gem::Specification.new do |s|
|
10
18
|
s.name = 'rushcheck'
|
11
19
|
s.summary = "A lightweight random testing tool"
|
12
|
-
s.version =
|
20
|
+
s.version = RUSHCHECK_VERSION
|
13
21
|
s.author = 'Daisuke IKEGAMI'
|
14
22
|
s.email = 'ikegami@madscientist.jp'
|
15
23
|
s.homepage = 'http://rushcheck.rubyforge.org'
|
data/Rakefile.in
CHANGED
@@ -6,10 +6,18 @@ require 'rubygems'
|
|
6
6
|
require 'rake'
|
7
7
|
require 'rake/gempackagetask'
|
8
8
|
|
9
|
+
RUSHCHECK_VERSION="@VERSION@"
|
10
|
+
task :default => ["dist", "gem"]
|
11
|
+
|
12
|
+
task :dist do
|
13
|
+
system "darcs dist -d rushcheck-#{RUSHCHECK_VERSION}"
|
14
|
+
system "mv rushcheck-#{RUSHCHECK_VERSION}.tar.gz pkg/"
|
15
|
+
end
|
16
|
+
|
9
17
|
spec = Gem::Specification.new do |s|
|
10
18
|
s.name = 'rushcheck'
|
11
19
|
s.summary = "A lightweight random testing tool"
|
12
|
-
s.version =
|
20
|
+
s.version = RUSHCHECK_VERSION
|
13
21
|
s.author = 'Daisuke IKEGAMI'
|
14
22
|
s.email = 'ikegami@madscientist.jp'
|
15
23
|
s.homepage = 'http://rushcheck.rubyforge.org'
|
@@ -19,6 +19,8 @@ h1. Index
|
|
19
19
|
## <a href="#Watching the statistics">Watching the statistics</a>
|
20
20
|
### <a href="#trivial">'trivial'</a>
|
21
21
|
### <a href="#classify">'classify'</a>
|
22
|
+
# <a href="Combining unit testing and RushCheck">Combining unit testing and RushCheck</a>
|
23
|
+
# <a href="Combining RSpec and RushCheck">Combining RSpec and RushCheck</a>
|
22
24
|
## <a href="#With another basic classes for assertions">With another basic classes for assertions</a>
|
23
25
|
### <a href="#SpecialString">SpecialString</a>
|
24
26
|
### <a href="#Array and RandomArray">Array and RandomArray</a>
|
@@ -307,6 +309,59 @@ true
|
|
307
309
|
irb>
|
308
310
|
</pre>
|
309
311
|
|
312
|
+
h2. <a name="Combining unit testing and RushCheck">Combining unit testing and RushCheck</a>
|
313
|
+
|
314
|
+
The library 'test/unit' of Ruby is useful for unit testing. Here is a trick to use 'test/unit'.
|
315
|
+
|
316
|
+
<pre>
|
317
|
+
def forall(*cs, &f)
|
318
|
+
assert(RushCheck::Claim.new(*cs, &f).check)
|
319
|
+
end
|
320
|
+
</pre>
|
321
|
+
|
322
|
+
The class Claim is a subclass of Assertion. The meaning is almost similar to Assertion, however
|
323
|
+
Claim does not check the result value of the given block 'f'. Because assertions in 'test/unit'
|
324
|
+
such as 'assert_equal' does not return any result, but return nil, we don't need to check the
|
325
|
+
result values of a sequence of assertions. Nevertheless we can check the testcase because
|
326
|
+
the assertions in 'test/unit' raises an exception if the testcase is failed.
|
327
|
+
|
328
|
+
Example:
|
329
|
+
<pre>
|
330
|
+
def test_not_empty_after_push
|
331
|
+
array = Array.new
|
332
|
+
forall(Integer) do |item|
|
333
|
+
array.push item
|
334
|
+
assert(! array.empty?)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
</pre>
|
338
|
+
|
339
|
+
h2. <a name="Combining RSpec and RushCheck">Combining RSpec and RushCheck</a>
|
340
|
+
"RSpec":http://rspec.rubyforge.org is another testing framework which helps Behaviour Driven Development (BDD).
|
341
|
+
To combine RSpec and RushCheck, the following trick maybe useful and easy to read:
|
342
|
+
<pre>
|
343
|
+
def forall(*cs, &f)
|
344
|
+
RushCheck::Claim.new(*cs, &f).check.should_equal true
|
345
|
+
end
|
346
|
+
</pre>
|
347
|
+
|
348
|
+
Then, for example, we can write a specification of Array#push as follows:
|
349
|
+
<pre>
|
350
|
+
context "An empty array" do
|
351
|
+
|
352
|
+
specify "should not be empty after 'push'" do
|
353
|
+
forall(Integer) do |item|
|
354
|
+
array = Array.new
|
355
|
+
array.push item
|
356
|
+
array.should_not_be_empty
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
</pre>
|
362
|
+
|
363
|
+
See also 'examples/rspec' in the distribution of RushCheck for details.
|
364
|
+
|
310
365
|
h2. <a name="With another basic classes for assertions">With another basic classes for assertions</a>
|
311
366
|
|
312
367
|
In previous sections, we have seen how to check assertions for any
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This example is quoted from the RSpec tutorial.
|
2
|
+
# check also http://rspec.rubyforge.org/tutorials/index.html
|
3
|
+
|
4
|
+
class StackUnderflowError < RuntimeError; end
|
5
|
+
class StackOverflowError < RuntimeError; end
|
6
|
+
|
7
|
+
class Stack
|
8
|
+
|
9
|
+
SIZE = 5
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@items = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def empty?
|
16
|
+
@items.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def length
|
20
|
+
@items.length
|
21
|
+
end
|
22
|
+
|
23
|
+
def full?
|
24
|
+
@items.length == SIZE
|
25
|
+
end
|
26
|
+
|
27
|
+
def push(item)
|
28
|
+
raise StackOverflowError if full?
|
29
|
+
@items.push item
|
30
|
+
end
|
31
|
+
|
32
|
+
def pop
|
33
|
+
raise StackUnderflowError if empty?
|
34
|
+
@items.pop
|
35
|
+
end
|
36
|
+
|
37
|
+
def peek
|
38
|
+
raise StackUnderflowError if empty?
|
39
|
+
@items.last
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# This example is quoted from the RSpec tutorial and also
|
2
|
+
# test/spec.
|
3
|
+
# check also
|
4
|
+
# http://rspec.rubyforge.org/tutorials/index.html
|
5
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/217242
|
6
|
+
#
|
7
|
+
# To execute this example, you have to follow
|
8
|
+
# 1. install rspec
|
9
|
+
# % sudo gem install rspec
|
10
|
+
# 2. then, execute the 'spec' command
|
11
|
+
# % spec stack_spec.rb -f s
|
12
|
+
#
|
13
|
+
# On my PowerBook PC, this example takes about 50 seconds.
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'rubygems'
|
17
|
+
require_gem 'rushcheck'
|
18
|
+
rescue LoadError
|
19
|
+
require 'rushcheck'
|
20
|
+
end
|
21
|
+
|
22
|
+
def forall(*cs, &f)
|
23
|
+
RushCheck::Claim.new(*cs, &f).check.should_equal true
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'stack'
|
27
|
+
|
28
|
+
context "An empty stack" do
|
29
|
+
|
30
|
+
specify "should not be empty after 'push'" do
|
31
|
+
forall(Integer) do |item|
|
32
|
+
stack = Stack.new
|
33
|
+
stack.push item
|
34
|
+
stack.should_not_be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# setup for general stack
|
41
|
+
class NotEmptyAndFullStack < Stack
|
42
|
+
extend RushCheck::Arbitrary
|
43
|
+
|
44
|
+
def self.arbitrary
|
45
|
+
stack = self.new
|
46
|
+
RushCheck::Gen.choose(1, SIZE-2).bind do |size|
|
47
|
+
RushCheck::Gen.vector(String, size).fmap do |ary|
|
48
|
+
ary.each { |i| stack.push i }
|
49
|
+
stack
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "A stack (in general)" do
|
56
|
+
|
57
|
+
setup do
|
58
|
+
puts " This test consumes time. Please wait few seconds."
|
59
|
+
end
|
60
|
+
|
61
|
+
specify "should add the top when sent 'push'" do
|
62
|
+
forall(NotEmptyAndFullStack, String) do |stack, item|
|
63
|
+
stack.push item
|
64
|
+
stack.peek.should_equal item
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
specify "should NOT remove the top item when sent 'peek'" do
|
69
|
+
forall(NotEmptyAndFullStack, Integer) do |stack, item|
|
70
|
+
stack.push item
|
71
|
+
stack.peek.should_equal item
|
72
|
+
stack.peek.should_equal item
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
specify "should return the top item when sent 'pop'" do
|
77
|
+
forall(NotEmptyAndFullStack, Integer) do |stack, item|
|
78
|
+
stack.push item
|
79
|
+
stack.pop.should_equal item
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
specify "should remove the top item when sent 'pop'" do
|
84
|
+
forall(NotEmptyAndFullStack, Integer, Integer) do |stack, dummy, item|
|
85
|
+
stack.push item
|
86
|
+
stack.push dummy
|
87
|
+
stack.pop
|
88
|
+
stack.pop.should_equal item
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context "An empty stack" do
|
95
|
+
|
96
|
+
specify "should be empty" do
|
97
|
+
Stack.new.should_be_empty
|
98
|
+
end
|
99
|
+
|
100
|
+
specify "should no longer be empty" do
|
101
|
+
forall(Integer) do |item|
|
102
|
+
stack = Stack.new
|
103
|
+
stack.push item
|
104
|
+
stack.should_not_be_empty
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
specify "should complain when sent 'peek'" do
|
109
|
+
lambda { Stack.new.peek }.should_raise StackUnderflowError
|
110
|
+
end
|
111
|
+
|
112
|
+
specify "should complain when sent 'pop'" do
|
113
|
+
lambda { Stack.new.pop }.should_raise StackUnderflowError
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "An almost empty stack (with one item)" do
|
118
|
+
specify "should not be empty" do
|
119
|
+
forall(Integer) do |item|
|
120
|
+
stack = Stack.new
|
121
|
+
stack.push item
|
122
|
+
stack.should_not_be_empty
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
specify "should remain not empty after 'peek'" do
|
127
|
+
forall(Integer) do |item|
|
128
|
+
stack = Stack.new
|
129
|
+
stack.push item
|
130
|
+
stack.peek
|
131
|
+
stack.should_not_be_empty
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
specify "should become empty after 'pop'" do
|
136
|
+
forall(Integer) do |item|
|
137
|
+
stack = Stack.new
|
138
|
+
stack.push item
|
139
|
+
stack.pop
|
140
|
+
stack.should_be_empty
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
# setup for almost full stack
|
147
|
+
class AlmostFullStack < Stack
|
148
|
+
extend RushCheck::Arbitrary
|
149
|
+
|
150
|
+
def self.arbitrary
|
151
|
+
stack = self.new
|
152
|
+
RushCheck::Gen.vector(String, SIZE-1).fmap do |ary|
|
153
|
+
ary.each { |i| stack.push i }
|
154
|
+
stack
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "An almost full stack (with one item less than capacity)" do
|
160
|
+
|
161
|
+
setup do
|
162
|
+
puts " This test consumes time. Please wait few seconds."
|
163
|
+
end
|
164
|
+
|
165
|
+
specify "should not be full" do
|
166
|
+
forall(AlmostFullStack) do |stack|
|
167
|
+
stack.should.not.be.full
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
specify "should become full when sent 'push'" do
|
172
|
+
forall(AlmostFullStack, Integer) do |stack, item|
|
173
|
+
stack.push item
|
174
|
+
stack.should.be.full
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# setup for full stack
|
180
|
+
class FullStack < Stack
|
181
|
+
extend RushCheck::Arbitrary
|
182
|
+
|
183
|
+
def self.arbitrary
|
184
|
+
stack = self.new
|
185
|
+
RushCheck::Gen.vector(String, SIZE).fmap do |ary|
|
186
|
+
ary.each { |i| stack.push i }
|
187
|
+
stack
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "A full stack" do
|
193
|
+
|
194
|
+
setup do
|
195
|
+
puts " This test consumes time. Please wait few seconds."
|
196
|
+
end
|
197
|
+
|
198
|
+
specify "should be full" do
|
199
|
+
forall(FullStack) do |stack|
|
200
|
+
stack.should.be.full
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
specify "should remain full after 'peek'" do
|
205
|
+
forall(FullStack) do |stack|
|
206
|
+
stack.peek
|
207
|
+
stack.should.be.full
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
specify "should no longer be full after 'pop'" do
|
212
|
+
forall(FullStack) do |stack|
|
213
|
+
stack.pop
|
214
|
+
stack.should.not.be.full
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
specify "should complain on 'push'" do
|
219
|
+
forall(FullStack, Integer) do |stack, item|
|
220
|
+
lambda { stack.push item }.should.raise StackOverflowError
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre><span class="ruby-comment cmt"># File rushcheck/arbitrary.rb, line
|
13
|
+
<pre><span class="ruby-comment cmt"># File rushcheck/arbitrary.rb, line 30</span>
|
14
14
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">arbitrary</span>
|
15
15
|
<span class="ruby-identifier">raise</span>(<span class="ruby-constant">NotImplementedError</span>, <span class="ruby-value str">"This method should be overrided."</span>)
|
16
16
|
<span class="ruby-keyword kw">end</span></pre>
|
@@ -97,10 +97,21 @@ href="../Integer.html">Integer</a>, <a href="../String.html">String</a>) do
|
|
97
97
|
end
|
98
98
|
</p>
|
99
99
|
<p>
|
100
|
+
The return value of the body of testcase is checked by the method
|
101
|
+
‘check’.
|
102
|
+
</p>
|
103
|
+
<p>
|
100
104
|
Note that the number of arguments in the block must be equal to the number
|
101
|
-
of arguments of <a href="Assertion.html#M000073">Assertion.new</a>.
|
102
|
-
|
103
|
-
|
105
|
+
of arguments of <a href="Assertion.html#M000073">Assertion.new</a>.
|
106
|
+
However, for a curried block, we can write also
|
107
|
+
</p>
|
108
|
+
<pre>
|
109
|
+
Assertion.new(*cs) {|*xs| ...}
|
110
|
+
</pre>
|
111
|
+
<p>
|
112
|
+
See also class <a href="Claim.html">Claim</a>, which is a subclass of <a
|
113
|
+
href="Assertion.html">Assertion</a> See also the <a
|
114
|
+
href="../RushCheck.html">RushCheck</a> tutorial and several examples.
|
104
115
|
</p>
|
105
116
|
|
106
117
|
</div>
|
@@ -10,9 +10,8 @@
|
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre><span class="ruby-comment cmt"># File rushcheck/assertion.rb, line
|
13
|
+
<pre><span class="ruby-comment cmt"># File rushcheck/assertion.rb, line 35</span>
|
14
14
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">xs</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">f</span>)
|
15
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">length</span>
|
16
15
|
<span class="ruby-ivar">@inputs</span> = <span class="ruby-identifier">xs</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">f</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)]
|
17
16
|
<span class="ruby-ivar">@proc</span> = <span class="ruby-identifier">f</span>
|
18
17
|
<span class="ruby-keyword kw">end</span></pre>
|
@@ -10,41 +10,14 @@
|
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre><span class="ruby-comment cmt"># File rushcheck/assertion.rb, line
|
13
|
+
<pre><span class="ruby-comment cmt"># File rushcheck/assertion.rb, line 79</span>
|
14
14
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">property</span>
|
15
|
-
<span class="ruby-identifier">
|
16
|
-
<span class="ruby-
|
17
|
-
<span class="ruby-keyword kw">
|
18
|
-
<span class="ruby-keyword kw">
|
19
|
-
<span class="ruby-ivar">@inputs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
20
|
-
<span class="ruby-identifier">r1</span>, <span class="ruby-identifier">r2</span> = <span class="ruby-identifier">r2</span>.<span class="ruby-identifier">split</span>
|
21
|
-
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">arbitrary</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">n</span>, <span class="ruby-identifier">r1</span>)
|
22
|
-
<span class="ruby-keyword kw">end</span>
|
23
|
-
<span class="ruby-keyword kw">else</span>
|
24
|
-
[]
|
15
|
+
<span class="ruby-identifier">_property</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">args</span><span class="ruby-operator">|</span>
|
16
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@proc</span>.<span class="ruby-identifier">call</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
17
|
+
<span class="ruby-keyword kw">then</span> <span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">true</span>)
|
18
|
+
<span class="ruby-keyword kw">else</span> <span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">false</span>)
|
25
19
|
<span class="ruby-keyword kw">end</span>
|
26
|
-
|
27
|
-
<span class="ruby-identifier">test</span> = <span class="ruby-keyword kw">begin</span>
|
28
|
-
<span class="ruby-ivar">@proc</span>.<span class="ruby-identifier">call</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
29
|
-
<span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
|
30
|
-
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">ex</span>
|
31
|
-
<span class="ruby-keyword kw">when</span> <span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">GuardException</span>
|
32
|
-
<span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>)
|
33
|
-
<span class="ruby-keyword kw">else</span>
|
34
|
-
<span class="ruby-identifier">err</span> = <span class="ruby-node">"Unexpected exception: #{ex.inspect}\n"</span> <span class="ruby-operator">+</span>
|
35
|
-
<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"\n"</span>)
|
36
|
-
<span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">false</span>, [], [<span class="ruby-identifier">err</span>])
|
37
|
-
<span class="ruby-keyword kw">end</span>
|
38
|
-
<span class="ruby-keyword kw">end</span>
|
39
|
-
<span class="ruby-comment cmt"># not use ensure here because ensure clause</span>
|
40
|
-
<span class="ruby-comment cmt"># does not return values</span>
|
41
|
-
<span class="ruby-identifier">test</span>.<span class="ruby-identifier">property</span>.<span class="ruby-identifier">gen</span>.<span class="ruby-identifier">fmap</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
|
42
|
-
<span class="ruby-identifier">res</span>.<span class="ruby-identifier">arguments</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">inspect</span>
|
43
|
-
<span class="ruby-identifier">res</span>
|
44
|
-
<span class="ruby-keyword kw">end</span>
|
45
|
-
<span class="ruby-keyword kw">end</span>
|
46
|
-
|
47
|
-
<span class="ruby-constant">RushCheck</span><span class="ruby-operator">::</span><span class="ruby-constant">Property</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">g</span>)
|
20
|
+
}
|
48
21
|
<span class="ruby-keyword kw">end</span></pre>
|
49
22
|
</body>
|
50
23
|
</html>
|