rushcheck 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/data/rushcheck/doc/policy.txt +107 -0
- data/data/rushcheck/doc/rushcheck.thtml +832 -0
- data/data/rushcheck/examples/candy.rb +6 -8
- data/data/rushcheck/examples/printf.rb +3 -3
- data/data/rushcheck/examples/proc.rb +4 -4
- data/data/rushcheck/examples/roguetile.rb +16 -16
- data/data/rushcheck/examples/sample.rb +10 -10
- data/data/rushcheck/rdoc/classes/Arbitrary.html +5 -5
- data/data/rushcheck/rdoc/classes/Arbitrary.src/M000082.html +18 -0
- data/data/rushcheck/rdoc/classes/Assertion.html +11 -11
- data/data/rushcheck/rdoc/classes/Assertion.src/M000019.html +20 -0
- data/data/rushcheck/rdoc/classes/Assertion.src/M000020.html +50 -0
- data/data/rushcheck/rdoc/classes/Coarbitrary.html +5 -5
- data/data/rushcheck/rdoc/classes/Coarbitrary.src/M000105.html +18 -0
- data/data/rushcheck/rdoc/classes/FalseClass.html +15 -15
- data/data/rushcheck/rdoc/classes/FalseClass.src/M000022.html +18 -0
- data/data/rushcheck/rdoc/classes/FalseClass.src/M000023.html +18 -0
- data/data/rushcheck/rdoc/classes/FalseClass.src/M000024.html +18 -0
- data/data/rushcheck/rdoc/classes/Float.html +20 -20
- data/data/rushcheck/rdoc/classes/Float.src/M000052.html +21 -0
- data/data/rushcheck/rdoc/classes/Float.src/M000053.html +18 -0
- data/data/rushcheck/rdoc/classes/Float.src/M000054.html +22 -0
- data/data/rushcheck/rdoc/classes/Float.src/M000055.html +20 -0
- data/data/rushcheck/rdoc/classes/Gen.html +102 -102
- data/data/rushcheck/rdoc/classes/Gen.src/M000030.html +4 -10
- data/data/rushcheck/rdoc/classes/Gen.src/M000031.html +29 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000032.html +6 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000033.html +14 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000034.html +10 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000035.html +4 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000036.html +4 -10
- data/data/rushcheck/rdoc/classes/Gen.src/M000037.html +4 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000038.html +4 -7
- data/data/rushcheck/rdoc/classes/Gen.src/M000039.html +4 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000040.html +10 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000041.html +4 -9
- data/data/rushcheck/rdoc/classes/Gen.src/M000042.html +7 -5
- data/data/rushcheck/rdoc/classes/Gen.src/M000043.html +4 -4
- data/data/rushcheck/rdoc/classes/Gen.src/M000044.html +4 -10
- data/data/rushcheck/rdoc/classes/Gen.src/M000045.html +23 -0
- data/data/rushcheck/rdoc/classes/Gen.src/M000046.html +19 -0
- data/data/rushcheck/rdoc/classes/Gen.src/M000047.html +18 -0
- data/data/rushcheck/rdoc/classes/Gen.src/M000048.html +24 -0
- data/data/rushcheck/rdoc/classes/Guard.html +10 -10
- data/data/rushcheck/rdoc/classes/Guard.src/M000028.html +27 -0
- data/data/rushcheck/rdoc/classes/Guard.src/M000029.html +18 -0
- data/data/rushcheck/rdoc/classes/HsRandom.html +20 -20
- data/data/rushcheck/rdoc/classes/HsRandom.src/M000088.html +22 -0
- data/data/rushcheck/rdoc/classes/HsRandom.src/M000089.html +32 -0
- data/data/rushcheck/rdoc/classes/HsRandom.src/M000090.html +18 -0
- data/data/rushcheck/rdoc/classes/Integer.html +20 -20
- data/data/rushcheck/rdoc/classes/Integer.src/M000010.html +18 -0
- data/data/rushcheck/rdoc/classes/Integer.src/M000011.html +18 -0
- data/data/rushcheck/rdoc/classes/Integer.src/M000012.html +21 -0
- data/data/rushcheck/rdoc/classes/Integer.src/M000013.html +19 -0
- data/data/rushcheck/rdoc/classes/NilClass.html +15 -15
- data/data/rushcheck/rdoc/classes/NilClass.src/M000064.html +18 -0
- data/data/rushcheck/rdoc/classes/NilClass.src/M000065.html +18 -0
- data/data/rushcheck/rdoc/classes/NilClass.src/M000066.html +18 -0
- data/data/rushcheck/rdoc/classes/Property.html +10 -10
- data/data/rushcheck/rdoc/classes/Property.src/M000077.html +26 -0
- data/data/rushcheck/rdoc/classes/Property.src/M000078.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomArray.html +15 -15
- data/data/rushcheck/rdoc/classes/RandomArray.src/M000025.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomArray.src/M000026.html +35 -0
- data/data/rushcheck/rdoc/classes/RandomArray.src/M000027.html +22 -0
- data/data/rushcheck/rdoc/classes/RandomBool.html +10 -10
- data/data/rushcheck/rdoc/classes/RandomBool.src/M000086.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomBool.src/M000087.html +19 -0
- data/data/rushcheck/rdoc/classes/RandomGen.html +20 -20
- data/data/rushcheck/rdoc/classes/RandomGen.src/M000083.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomGen.src/M000084.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomGen.src/M000085.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomHash.html +16 -16
- data/data/rushcheck/rdoc/classes/RandomHash.src/M000049.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomHash.src/M000050.html +26 -0
- data/data/rushcheck/rdoc/classes/RandomHash.src/M000051.html +22 -0
- data/data/rushcheck/rdoc/classes/RandomProc.html +20 -20
- data/data/rushcheck/rdoc/classes/RandomProc.src/M000060.html +18 -0
- data/data/rushcheck/rdoc/classes/RandomProc.src/M000061.html +30 -0
- data/data/rushcheck/rdoc/classes/RandomProc.src/M000062.html +26 -0
- data/data/rushcheck/rdoc/classes/RandomProc.src/M000063.html +20 -0
- data/data/rushcheck/rdoc/classes/Result.html +19 -19
- data/data/rushcheck/rdoc/classes/Result.src/M000056.html +18 -0
- data/data/rushcheck/rdoc/classes/Result.src/M000057.html +18 -0
- data/data/rushcheck/rdoc/classes/Result.src/M000058.html +18 -0
- data/data/rushcheck/rdoc/classes/RushCheckConfig.html +41 -11
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000001.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000002.html +1 -1
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000003.html +8 -4
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000004.html +4 -24
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000005.html +22 -39
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000006.html +55 -0
- data/data/rushcheck/rdoc/classes/RushCheckConfig.src/M000007.html +50 -0
- data/data/rushcheck/rdoc/classes/SpecialString.html +5 -5
- data/data/rushcheck/rdoc/classes/SpecialString.src/M000021.html +37 -0
- data/data/rushcheck/rdoc/classes/StdGen.html +27 -27
- data/data/rushcheck/rdoc/classes/StdGen.src/M000014.html +9 -4
- data/data/rushcheck/rdoc/classes/StdGen.src/M000015.html +21 -0
- data/data/rushcheck/rdoc/classes/StdGen.src/M000016.html +21 -0
- data/data/rushcheck/rdoc/classes/StdGen.src/M000017.html +18 -0
- data/data/rushcheck/rdoc/classes/StdGen.src/M000018.html +18 -0
- data/data/rushcheck/rdoc/classes/String.html +20 -20
- data/data/rushcheck/rdoc/classes/String.src/M000073.html +24 -0
- data/data/rushcheck/rdoc/classes/String.src/M000074.html +18 -0
- data/data/rushcheck/rdoc/classes/String.src/M000075.html +25 -0
- data/data/rushcheck/rdoc/classes/String.src/M000076.html +22 -0
- data/data/rushcheck/rdoc/classes/TestExausted.html +113 -0
- data/data/rushcheck/rdoc/classes/TestFailed.html +155 -0
- data/data/rushcheck/rdoc/classes/TestFailed.src/M000067.html +18 -0
- data/data/rushcheck/rdoc/classes/TestOk.html +113 -0
- data/data/rushcheck/rdoc/classes/TestOptions.html +180 -0
- data/data/rushcheck/rdoc/classes/TestOptions.src/M000008.html +18 -0
- data/data/rushcheck/rdoc/classes/TestOptions.src/M000009.html +18 -0
- data/data/rushcheck/rdoc/classes/TestResult.html +164 -0
- data/data/rushcheck/rdoc/classes/TestResult.src/M000068.html +18 -0
- data/data/rushcheck/rdoc/classes/Testable.html +96 -51
- data/data/rushcheck/rdoc/classes/Testable.src/M000091.html +4 -4
- data/data/rushcheck/rdoc/classes/Testable.src/M000092.html +4 -4
- data/data/rushcheck/rdoc/classes/Testable.src/M000095.html +4 -4
- data/data/rushcheck/rdoc/classes/Testable.src/M000096.html +18 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000097.html +18 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000099.html +19 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000100.html +21 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000101.html +18 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000103.html +18 -0
- data/data/rushcheck/rdoc/classes/Testable.src/M000104.html +18 -0
- data/data/rushcheck/rdoc/classes/TheStdGen.html +20 -20
- data/data/rushcheck/rdoc/classes/TheStdGen.src/M000069.html +18 -0
- data/data/rushcheck/rdoc/classes/TheStdGen.src/M000070.html +20 -0
- data/data/rushcheck/rdoc/classes/TheStdGen.src/M000071.html +21 -0
- data/data/rushcheck/rdoc/classes/TheStdGen.src/M000072.html +18 -0
- data/data/rushcheck/rdoc/classes/TrueClass.html +15 -15
- data/data/rushcheck/rdoc/classes/TrueClass.src/M000079.html +18 -0
- data/data/rushcheck/rdoc/classes/TrueClass.src/M000080.html +18 -0
- data/data/rushcheck/rdoc/classes/TrueClass.src/M000081.html +18 -0
- data/data/rushcheck/rdoc/created.rid +1 -1
- data/data/rushcheck/rdoc/files/rushcheck/config_rb.html +8 -1
- data/data/rushcheck/rdoc/files/rushcheck/testable_rb.html +3 -1
- data/data/rushcheck/rdoc/files/rushcheck/testoptions_rb.html +109 -0
- data/data/rushcheck/rdoc/files/rushcheck/testresult_rb.html +105 -0
- data/data/rushcheck/rdoc/files/rushcheck_rb.html +127 -0
- data/data/rushcheck/rdoc/fr_class_index.html +5 -0
- data/data/rushcheck/rdoc/fr_file_index.html +3 -1
- data/data/rushcheck/rdoc/fr_method_index.html +103 -94
- data/lib/rushcheck/arbitrary.rb +16 -12
- data/lib/rushcheck/array.rb +7 -6
- data/lib/rushcheck/assertion.rb +53 -50
- data/lib/rushcheck/bool.rb +26 -24
- data/lib/rushcheck/config.rb +131 -81
- data/lib/rushcheck/float.rb +4 -4
- data/lib/rushcheck/gen.rb +194 -182
- data/lib/rushcheck/guard.rb +9 -10
- data/lib/rushcheck/hash.rb +4 -3
- data/lib/rushcheck/integer.rb +11 -6
- data/lib/rushcheck/proc.rb +7 -7
- data/lib/rushcheck/property.rb +19 -15
- data/lib/rushcheck/random.rb +162 -159
- data/lib/rushcheck/result.rb +16 -12
- data/lib/rushcheck/string.rb +12 -12
- data/lib/rushcheck/testable.rb +99 -25
- data/lib/rushcheck/testoptions.rb +20 -0
- data/lib/rushcheck/testresult.rb +25 -0
- data/lib/{rushcheck/rushcheck.rb → rushcheck.rb} +2 -1
- metadata +93 -4
- data/data/rushcheck/doc/rushcheck.txt +0 -670
data/lib/rushcheck/random.rb
CHANGED
@@ -10,206 +10,209 @@
|
|
10
10
|
# This file provides two module RandomGen, HsRandom, two classes
|
11
11
|
# StdGen and TheStdGen.
|
12
12
|
|
13
|
+
module RushCheck
|
13
14
|
|
14
|
-
# The module RandomGen is an abstract module. This is included
|
15
|
-
# to add instance methods. The author considers that few developers
|
16
|
-
# need to read this implementation. See StdGen as an example.
|
17
|
-
# Check also Haskell's System.Random library.
|
18
|
-
module RandomGen
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
# The module RandomGen is an abstract module. This is included
|
16
|
+
# to add instance methods. The author considers that few developers
|
17
|
+
# need to read this implementation. See StdGen as an example.
|
18
|
+
# Check also Haskell's System.Random library.
|
19
|
+
module RandomGen
|
20
|
+
|
21
|
+
# gen_next should be overrided as an instance method.
|
22
|
+
# It is assumed that gen_next returns an array with length 2.
|
23
|
+
# Here, call 'Foo' the class which includes RandomGen.
|
24
|
+
# The first components of the result should be an integer, and the
|
25
|
+
# last components should be an object which belongs to the class
|
26
|
+
# Foo.
|
27
|
+
def gen_next
|
28
|
+
raise_not_implemented_error
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
# split should be overrided as an instance method.
|
32
|
+
# It is assumed that split returns an array with length 2.
|
33
|
+
# Here, call 'Foo' the class which includes RandomGen.
|
34
|
+
# Then the components of the result are objects which belongs to the
|
35
|
+
# class Foo.
|
36
|
+
def split
|
37
|
+
raise_not_implemented_error
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
# gen_range should be overrided as an instance method.
|
41
|
+
# It is assumed that split returns an array with length 2.
|
42
|
+
# Here, call 'Foo' the class which includes RandomGen.
|
43
|
+
# Then the components of the result are integers where
|
44
|
+
# the first components should be the lowest bound of
|
45
|
+
# the first components of gen_next. Another should be
|
46
|
+
# the highest bound of the first components of gen_next.
|
47
|
+
def gen_range
|
48
|
+
raise_not_implemented_error
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
private
|
52
|
+
def raise_not_implemented_error
|
53
|
+
raise(NotImplementedError, "This method should be overrided.")
|
54
|
+
end
|
54
55
|
|
55
|
-
end
|
56
|
+
end
|
56
57
|
|
57
|
-
# StdGen is a class (and the unique class) which includes RandomGen.
|
58
|
-
# This class provides a functional random number generator.
|
59
|
-
class StdGen
|
58
|
+
# StdGen is a class (and the unique class) which includes RandomGen.
|
59
|
+
# This class provides a functional random number generator.
|
60
|
+
class StdGen
|
60
61
|
|
61
|
-
|
62
|
+
include RushCheck::RandomGen
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
@@min_bound = -(2**30)
|
65
|
+
@@max_bound = 2**30 - 1
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
# left and right are two seeds of random number generator.
|
68
|
+
attr_reader :left, :right
|
69
|
+
def initialize(left=nil, right=nil)
|
70
|
+
@left, @right = [left, right].map do |x|
|
71
|
+
if x.nil?
|
72
|
+
then random
|
73
|
+
else in_range(x)
|
74
|
+
end
|
73
75
|
end
|
74
76
|
end
|
75
|
-
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
# gen_next returns an array with length 2. The first component of
|
79
|
+
# result is a random integer. The last component is a new StdGen
|
80
|
+
# object as a new random number generator. See also RandomGen.
|
81
|
+
def gen_next
|
82
|
+
s, t = [@left, @right].map {|x| random(x) }
|
83
|
+
z = ((s - t) % (@@max_bound - @@min_bound)) + @@min_bound
|
83
84
|
|
84
|
-
|
85
|
-
|
85
|
+
[z, RushCheck::StdGen.new(s, t)]
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
# split returns an array with length 2. The components are
|
89
|
+
# two new StdGen objects as two new random number generators.
|
90
|
+
def split
|
91
|
+
g = gen_next[1]
|
92
|
+
s, t = g.left, g.right
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
[RushCheck::StdGen.new(s + 1, t), RushCheck::StdGen.new(s, t + 1)]
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
# gen_range returns an array with length 2 which represents
|
98
|
+
# a bound of generated random numbers.
|
99
|
+
def gen_range
|
100
|
+
[@@min_bound, @@max_bound]
|
101
|
+
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
def to_s
|
104
|
+
@left.to_s + ' ' + @right.to_s
|
105
|
+
end
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
private
|
108
|
+
def random(s=nil)
|
109
|
+
if s.nil? then srand else srand s end
|
110
|
+
rand(@@max_bound - @@min_bound) + @@min_bound
|
111
|
+
end
|
112
|
+
|
113
|
+
def in_range(n)
|
114
|
+
(n % (@@max_bound - @@min_bound)) + @@min_bound
|
115
|
+
end
|
111
116
|
|
112
|
-
def in_range(n)
|
113
|
-
(n % (@@max_bound - @@min_bound)) + @@min_bound
|
114
117
|
end
|
115
118
|
|
116
|
-
end
|
117
119
|
|
120
|
+
require 'singleton'
|
118
121
|
|
119
|
-
|
122
|
+
# TheStdGen is a singleton class to get the unique random number
|
123
|
+
# generator using StdGen. TheStdGen includes ruby's Singleton module.
|
124
|
+
class TheStdGen
|
120
125
|
|
121
|
-
|
122
|
-
|
123
|
-
class TheStdGen
|
126
|
+
include Singleton
|
127
|
+
include RushCheck::RandomGen
|
124
128
|
|
125
|
-
|
126
|
-
|
129
|
+
def initialize
|
130
|
+
@gen = RushCheck::StdGen.new
|
131
|
+
end
|
127
132
|
|
128
|
-
|
129
|
-
|
130
|
-
|
133
|
+
def gen_next
|
134
|
+
@gen, result = @gen.split
|
135
|
+
|
136
|
+
result.gen_next
|
137
|
+
end
|
131
138
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
result.gen_next
|
136
|
-
end
|
139
|
+
def split
|
140
|
+
result = @gen.split
|
141
|
+
@gen = @gen.gen_next[1]
|
137
142
|
|
138
|
-
|
139
|
-
|
140
|
-
@gen = @gen.gen_next[1]
|
143
|
+
result
|
144
|
+
end
|
141
145
|
|
142
|
-
|
143
|
-
|
146
|
+
def gen_range
|
147
|
+
@gen.gen_range
|
148
|
+
end
|
144
149
|
|
145
|
-
def gen_range
|
146
|
-
@gen.gen_range
|
147
150
|
end
|
148
151
|
|
149
|
-
end
|
150
152
|
|
153
|
+
# HsRandom module provides several random number function with the
|
154
|
+
# functional random generator. This module is implemented Haskell\'s
|
155
|
+
# System.Random library. This module assumes that the class which
|
156
|
+
# includes HsRandom should have an instance method random_range to
|
157
|
+
# generate a random number and a new random number generator.
|
158
|
+
# It assumes also that the class which includes HsRandom should have
|
159
|
+
# a class method bound to give a bound of random numbers.
|
160
|
+
module HsRandom
|
151
161
|
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
# should be a new random number, and the last should be a new random
|
165
|
-
# number generator.
|
166
|
-
def random(gen, lo=nil, hi=nil)
|
167
|
-
lo = bound[0] if lo.nil?
|
168
|
-
hi = bound[1] if hi.nil?
|
169
|
-
random_range(gen, hi, lo) if lo > hi
|
170
|
-
|
171
|
-
random_range(gen, lo, hi)
|
172
|
-
end
|
162
|
+
# random requires the functional random number generater (StdGen
|
163
|
+
# object) and optionally requires the bound of random numbers.
|
164
|
+
# It returns an array with length 2, where the first component
|
165
|
+
# should be a new random number, and the last should be a new random
|
166
|
+
# number generator.
|
167
|
+
def random(gen, lo=nil, hi=nil)
|
168
|
+
lo = bound[0] if lo.nil?
|
169
|
+
hi = bound[1] if hi.nil?
|
170
|
+
random_range(gen, hi, lo) if lo > hi
|
171
|
+
|
172
|
+
random_range(gen, lo, hi)
|
173
|
+
end
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
175
|
+
# random_array requires the functional random number generater
|
176
|
+
# (StdGen object). Optionally, it requires the length of results and
|
177
|
+
# the bound of random numbers. This method returns different result
|
178
|
+
# whether the second argument length is nil or not. When the second
|
179
|
+
# argument is nil, then random_array returns a Proc which takes one
|
180
|
+
# variable as an integer and return a new random value, such as an
|
181
|
+
# infinite sequence of random numbers. Otherwise, the second
|
182
|
+
# argument of random_array is not nil but some integer, then
|
183
|
+
# random_array returns an array of random numbers with the length.
|
184
|
+
def random_array(gen, len=nil, lo=nil, hi=nil)
|
185
|
+
g = gen
|
186
|
+
if len.nil?
|
187
|
+
then
|
188
|
+
Proc.new do |i|
|
189
|
+
(i+1).times do
|
190
|
+
v, g = random(g, lo, hi)
|
191
|
+
end
|
192
|
+
v
|
193
|
+
end
|
194
|
+
else
|
195
|
+
(1..len).map do
|
189
196
|
v, g = random(g, lo, hi)
|
197
|
+
v
|
190
198
|
end
|
191
|
-
v
|
192
|
-
end
|
193
|
-
else
|
194
|
-
(1..len).map do
|
195
|
-
v, g = random(g, lo, hi)
|
196
|
-
v
|
197
199
|
end
|
198
200
|
end
|
199
|
-
end
|
200
201
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
202
|
+
# random_std requires optionally the bound of random numbers.
|
203
|
+
# It returns an array with length 2, where the first component
|
204
|
+
# should be a new random number, and the last should be a new random
|
205
|
+
# number generator. This method uses the unique standard random
|
206
|
+
# generator TheStdGen.
|
207
|
+
def random_std(lo=nil, hi=nil)
|
208
|
+
random(RushCheck::TheStdGen.instance, lo, hi)
|
209
|
+
end
|
210
|
+
|
211
|
+
def random_range(gen, lo=nil, hi=nil)
|
212
|
+
raise(NotImplementedError, "This method should be overrided.")
|
213
|
+
end
|
214
|
+
private :random_range
|
209
215
|
|
210
|
-
def random_range(gen, lo=nil, hi=nil)
|
211
|
-
raise(NotImplementedError, "This method should be overrided.")
|
212
216
|
end
|
213
|
-
private :random_range
|
214
217
|
|
215
218
|
end
|
data/lib/rushcheck/result.rb
CHANGED
@@ -5,22 +5,26 @@
|
|
5
5
|
require 'rushcheck/property'
|
6
6
|
require 'rushcheck/testable'
|
7
7
|
|
8
|
-
|
8
|
+
module RushCheck
|
9
9
|
|
10
|
-
|
10
|
+
class Result
|
11
11
|
|
12
|
-
|
13
|
-
Result.new(false)
|
14
|
-
end
|
12
|
+
include RushCheck::Testable
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def self.nothing
|
15
|
+
RushCheck::Result.new(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :ok, :stamp, :arguments
|
19
|
+
def initialize(ok=nil, stamp=[], arguments=[])
|
20
|
+
@ok, @stamp, @arguments = ok, stamp, arguments
|
21
|
+
end
|
22
|
+
|
23
|
+
def result
|
24
|
+
RushCheck::Property.new(@ok, @stamp, @arguments)
|
25
|
+
end
|
26
|
+
alias property :result
|
20
27
|
|
21
|
-
def result
|
22
|
-
Property.new(@ok, @stamp, @arguments)
|
23
28
|
end
|
24
|
-
alias property :result
|
25
29
|
|
26
30
|
end
|
data/lib/rushcheck/string.rb
CHANGED
@@ -9,19 +9,19 @@ require 'rushcheck/random'
|
|
9
9
|
|
10
10
|
class String
|
11
11
|
|
12
|
-
extend Arbitrary
|
13
|
-
extend HsRandom
|
12
|
+
extend RushCheck::Arbitrary
|
13
|
+
extend RushCheck::HsRandom
|
14
14
|
|
15
|
-
include Coarbitrary
|
15
|
+
include RushCheck::Coarbitrary
|
16
16
|
|
17
17
|
@@min_range = 0
|
18
18
|
@@max_range = 1024
|
19
19
|
|
20
20
|
def self.arbitrary
|
21
|
-
Gen.sized do |n|
|
22
|
-
Gen.choose(0, n).bind do |len|
|
23
|
-
Gen.vector(Integer, len).
|
24
|
-
|
21
|
+
RushCheck::Gen.sized do |n|
|
22
|
+
RushCheck::Gen.choose(0, n).bind do |len|
|
23
|
+
RushCheck::Gen.vector(Integer, len).fmap do |xs|
|
24
|
+
xs.map{|x| (x % 128).chr}.join
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -80,17 +80,17 @@ class SpecialString < String
|
|
80
80
|
[f['alphabet'],f['control'],f['number'],f['special']].zip(
|
81
81
|
[ @@alphabet, @@control, @@number, @@special]) do
|
82
82
|
|weight, table|
|
83
|
-
gen = Gen.oneof(table.map {|n| Gen.unit(n.chr)})
|
83
|
+
gen = RushCheck::Gen.oneof(table.map {|n| RushCheck::Gen.unit(n.chr)})
|
84
84
|
frq << [weight, gen]
|
85
85
|
end
|
86
86
|
|
87
|
-
Gen.sized do |m|
|
88
|
-
Gen.choose(0, m).bind do |len|
|
89
|
-
Gen.new do |n, r|
|
87
|
+
RushCheck::Gen.sized do |m|
|
88
|
+
RushCheck::Gen.choose(0, m).bind do |len|
|
89
|
+
RushCheck::Gen.new do |n, r|
|
90
90
|
r2 = r
|
91
91
|
(1..len).map do
|
92
92
|
r1, r2 = r2.split
|
93
|
-
Gen.frequency(frq).value(n, r1)
|
93
|
+
RushCheck::Gen.frequency(frq).value(n, r1)
|
94
94
|
end.join
|
95
95
|
end
|
96
96
|
end
|
data/lib/rushcheck/testable.rb
CHANGED
@@ -3,39 +3,113 @@
|
|
3
3
|
# See also QuickCheck in Haskell
|
4
4
|
|
5
5
|
require 'rushcheck/config'
|
6
|
+
require 'rushcheck/random'
|
7
|
+
require 'rushcheck/testresult'
|
6
8
|
|
7
|
-
module
|
9
|
+
module RushCheck
|
8
10
|
|
9
|
-
|
10
|
-
raise(NotImplementedError, "This method should be overrided.")
|
11
|
-
end
|
11
|
+
module Testable
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
alias quick_check :check
|
17
|
-
alias quickcheck :check
|
13
|
+
def property
|
14
|
+
raise(NotImplementedError, "This method should be overrided.")
|
15
|
+
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def check(config=RushCheck::Config.quick)
|
18
|
+
config.tests(property.gen, RushCheck::TheStdGen.instance)
|
19
|
+
end
|
20
|
+
alias quick_check :check
|
21
|
+
alias quickcheck :check
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def classify(name)
|
24
|
+
yield ? label(name) : property
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
alias collect :label
|
27
|
+
def imply
|
28
|
+
yield ? property : RushCheck::Result.nothing.result
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def label(s)
|
32
|
+
RushCheck::Property.new(property.gen.fmap {|res| res.stamp << s.to_s; res })
|
33
|
+
end
|
34
|
+
alias collect :label
|
35
|
+
|
36
|
+
def run(opts)
|
37
|
+
RushCheck::Config.batch(opts.ntests, opts.debug?).
|
38
|
+
tests_batch(property, RushCheck::StdGen.new(0))
|
39
|
+
end
|
36
40
|
|
37
|
-
|
38
|
-
|
41
|
+
def rjustify(n, s)
|
42
|
+
' ' * [0, n - s.length].max + s
|
43
|
+
end
|
44
|
+
private :rjustify
|
45
|
+
|
46
|
+
def try_test(ts)
|
47
|
+
ntests = 1
|
48
|
+
count = 0
|
49
|
+
others = []
|
50
|
+
if ! ts.empty?
|
51
|
+
ts.each do |t|
|
52
|
+
begin
|
53
|
+
r = t.call(opts)
|
54
|
+
case r
|
55
|
+
when RushCheck::TestOk
|
56
|
+
puts "."
|
57
|
+
ntests += 1
|
58
|
+
count += r.ntests
|
59
|
+
when RushCheck::TestExausted
|
60
|
+
puts "?"
|
61
|
+
ntests += 1
|
62
|
+
count += r.ntests
|
63
|
+
when RushCheck::TestFailed
|
64
|
+
puts "#"
|
65
|
+
ntests += 1
|
66
|
+
others << [r.results, ntests, r.ntests]
|
67
|
+
count += r.ntests
|
68
|
+
else
|
69
|
+
raise(RuntimeError, "RushCheck: illegal result")
|
70
|
+
end
|
71
|
+
rescue
|
72
|
+
puts "*"
|
73
|
+
ntests += 1
|
74
|
+
next
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
print(rjustify([0, 35-ntests].max, " (") + count.to_s + ")\n")
|
79
|
+
others
|
80
|
+
end
|
81
|
+
private :try_test
|
82
|
+
|
83
|
+
def final_run(f, n, no, name)
|
84
|
+
puts
|
85
|
+
puts " ** test " + n.to_s + " of " + name + " failed with the binding(s)"
|
86
|
+
f.each do |v|
|
87
|
+
puts " ** " + v.to_s
|
88
|
+
end
|
89
|
+
puts
|
90
|
+
end
|
91
|
+
private :final_run
|
92
|
+
|
93
|
+
def run_tests(name, opts, tests)
|
94
|
+
print(rjustify(25, name) + " : ")
|
95
|
+
f = try_test(tests)
|
96
|
+
f.each { |f, n, no| final_run(f, n, no, name) }
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
def test
|
101
|
+
check(RushCheck::Config.verbose)
|
102
|
+
end
|
103
|
+
alias verbose_check :test
|
104
|
+
|
105
|
+
def testcase
|
106
|
+
Proc.new {|opts| run(opts)}
|
107
|
+
end
|
108
|
+
|
109
|
+
def trivial
|
110
|
+
classify('trivial') { yield }
|
111
|
+
end
|
39
112
|
end
|
40
113
|
|
41
114
|
end
|
115
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# = testoptions.rb
|
2
|
+
# define class TestOptions for a batch process for RushCheck
|
3
|
+
|
4
|
+
module RushCheck
|
5
|
+
|
6
|
+
class TestOptions
|
7
|
+
|
8
|
+
attr_reader :ntests, :length
|
9
|
+
def initialize(ntests=100, length=1, debug=false)
|
10
|
+
@ntests, @length, @debug = ntests, length, debug
|
11
|
+
end
|
12
|
+
|
13
|
+
def debug?
|
14
|
+
@debug
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# = testresult.rb
|
2
|
+
#
|
3
|
+
|
4
|
+
module RushCheck
|
5
|
+
|
6
|
+
class TestResult
|
7
|
+
attr_reader :message, :ntests, :stamps
|
8
|
+
def initialize(message, ntests, stamps)
|
9
|
+
@message, @ntest, @stamps = message, ntests, stamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestOk < TestResult; end
|
14
|
+
|
15
|
+
class TestExausted < TestResult; end
|
16
|
+
|
17
|
+
class TestFailed
|
18
|
+
attr_reader :results, :ntests
|
19
|
+
def initialize(results, ntests)
|
20
|
+
@results, @ntests = results, ntests
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
@@ -5,13 +5,14 @@
|
|
5
5
|
require 'rushcheck/arbitrary'
|
6
6
|
require 'rushcheck/assertion'
|
7
7
|
require 'rushcheck/gen'
|
8
|
+
require 'rushcheck/guard'
|
8
9
|
require 'rushcheck/random'
|
9
10
|
require 'rushcheck/testable'
|
10
11
|
|
11
12
|
require 'rushcheck/array'
|
12
13
|
require 'rushcheck/bool'
|
14
|
+
require 'rushcheck/float'
|
13
15
|
require 'rushcheck/hash'
|
14
16
|
require 'rushcheck/integer'
|
15
|
-
require 'rushcheck/float'
|
16
17
|
require 'rushcheck/proc'
|
17
18
|
require 'rushcheck/string'
|