rushcheck 0.3 → 0.4

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