rushcheck 0.7 → 0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rubygems'
6
6
  require 'rake'
7
7
  require 'rake/gempackagetask'
8
8
 
9
- RUSHCHECK_VERSION="0.7"
9
+ RUSHCHECK_VERSION="0.8"
10
10
  task :default => ["dist", "gem"]
11
11
 
12
12
  task :dist do
@@ -32,7 +32,7 @@ spec = Gem::Specification.new do |s|
32
32
  s.bindir = 'bin'
33
33
  # s.executable =
34
34
  # s.extra_rdoc_files =
35
- s.files = FileList['lib/**/*', 'data/**/**/*',
35
+ s.files = FileList['lib/**/*', 'data/**/**/**/*',
36
36
  '[A-Z]*', 'copying.txt'].to_a
37
37
  s.description = <<-EOF
38
38
  RushCheck is a random testing tool which is one of implementations
@@ -662,7 +662,7 @@ h3. <a name="using Gen.create">(1) using Gen.create</a>
662
662
 
663
663
  <pre>
664
664
  class Candy
665
- extend Arbitrary
665
+ extend RushCheck::Arbitrary
666
666
 
667
667
  def self.arbitrary
668
668
  RushCheck::Gen.create(String, Integer) do |name, price|
@@ -0,0 +1,45 @@
1
+ 2006-11-29 start
2
+
3
+ files
4
+ -----
5
+ rushcheck.rb
6
+ rushcheck/arbitrary.rb rushcheck/claim.rb rushcheck/guard.rb rushcheck/property.rb rushcheck/testable.rb
7
+ rushcheck/array.rb rushcheck/config.rb rushcheck/hash.rb rushcheck/random.rb rushcheck/testoptions.rb
8
+ rushcheck/assertion.rb rushcheck/float.rb rushcheck/integer.rb rushcheck/result.rb rushcheck/testresult.rb
9
+ rushcheck/bool.rb rushcheck/gen.rb rushcheck/proc.rb rushcheck/string.rb rushcheck/version.rb
10
+
11
+ 21 files
12
+
13
+ categories
14
+ ----------
15
+ - prelude
16
+ | rushcheck.rb
17
+ - version
18
+ | version.rb
19
+ - arbitrary for base classes
20
+ | array.rb
21
+ | bool.rb
22
+ | float.rb
23
+ | hash.rb
24
+ | integer.rb
25
+ | proc.rb
26
+ | string.rb
27
+ - random number generators
28
+ | random.rb
29
+ - interfaces
30
+ | assertion.rb
31
+ | claim.rb
32
+ | guard.rb
33
+ - internal preliminaries
34
+ | arbitrary.rb
35
+ | config.rb
36
+ | gen.rb
37
+ | property.rb
38
+ | result.rb
39
+ | testable.rb
40
+ | testoptions.rb
41
+ | testresult.rb
42
+
43
+ specification
44
+ -------------
45
+
@@ -30,9 +30,9 @@ class ExpensiveCandy < Candy
30
30
 
31
31
  def self.arbitrary
32
32
  lo = 100000
33
- g = Gen.sized { |n| Gen.choose(lo, n + lo)}
33
+ g = RushCheck::Gen.sized { |n| Gen.choose(lo, n + lo)}
34
34
  xs = [String.arbitrary, g]
35
- Gen.create_by_gen(xs) do |name, price|
35
+ RushCheck::Gen.create_by_gen(xs) do |name, price|
36
36
  RushCheck::guard { price >= 100000 }
37
37
  new(name, price)
38
38
  end
@@ -10,7 +10,7 @@ def malformed_format_string
10
10
  RushCheck::Assertion.new(String) { |s|
11
11
  sprintf(s)
12
12
  true
13
- }.check
13
+ }
14
14
  end
15
15
 
16
16
  def malformed_format_string2
@@ -18,5 +18,5 @@ def malformed_format_string2
18
18
  RushCheck::Assertion.new(SpecialString) { |s|
19
19
  sprintf(s)
20
20
  true
21
- }.check
21
+ }
22
22
  end
@@ -32,6 +32,8 @@ module RushCheck
32
32
 
33
33
  include RushCheck::Testable
34
34
 
35
+ attr_reader :proc
36
+
35
37
  def initialize(*xs, &f)
36
38
  @inputs = xs[0..(f.arity - 1)]
37
39
  @proc = f
@@ -11,21 +11,18 @@ module RushCheck
11
11
 
12
12
  attr_reader :max_test, :max_fail, :size, :every
13
13
 
14
- def self.quick
14
+ def self.verbose
15
15
  new(100, 1000,
16
16
  Proc.new{|x| x / 2 + 3},
17
17
  Proc.new do |n, args|
18
- s = n.to_s
19
- s + ("\b" * s.length)
18
+ n.to_s + ":\n" + args.join("\n") + "\n"
20
19
  end)
21
20
  end
22
21
 
23
- def self.verbose
22
+ def self.silent
24
23
  new(100, 1000,
25
24
  Proc.new{|x| x / 2 + 3},
26
- Proc.new do |n, args|
27
- n.to_s + ":\n" + args.join("\n") + "\n"
28
- end)
25
+ Proc.new { |n, args| ''})
29
26
  end
30
27
 
31
28
  def self.batch(n, v)
@@ -36,7 +33,10 @@ module RushCheck
36
33
  end)
37
34
  end
38
35
 
39
- def initialize(max_test, max_fail, size, every)
36
+ def initialize(max_test = 100,
37
+ max_fail = 1000,
38
+ size = Proc.new {|x| x / 2 + 3},
39
+ every = Proc.new {|n, args| s = n.to_s; s + ("\b" * s.length)})
40
40
  @max_test, @max_fail, @size, @every = max_test, max_fail, size, every
41
41
  end
42
42
 
@@ -17,7 +17,9 @@ module RushCheck
17
17
  # choose returns a Gen object which generates a random value in the
18
18
  # bound. It may useful to implement arbitrary method into your class.
19
19
  def self.choose(lo=nil, hi=nil)
20
- rand.fmap {|x| lo.class.random(x, lo, hi)[0] }
20
+ rand.fmap do |x|
21
+ lo.class.random(x, lo, hi).first
22
+ end
21
23
  end
22
24
 
23
25
  # create_gen is one of primitive generators to create a random Gen object.
@@ -77,7 +79,7 @@ module RushCheck
77
79
  # random generator Gen.rand in 33%, while another random generator
78
80
  # of Integer (Integer.arbitrary) in 67%.
79
81
  def self.frequency(xs)
80
- tot = xs.inject(0) {|r, pair| r + pair[0]}
82
+ tot = xs.inject(0) {|r, pair| r + pair.first}
81
83
  raise(RuntimeError, "Illegal frequency:#{xs.inspect}") if tot == 0
82
84
  choose(0, tot - 1).bind do |n|
83
85
  m = n
@@ -219,7 +221,7 @@ module RushCheck
219
221
 
220
222
  # variant constructs a generator which transforms the random number
221
223
  # seed. variant takes one variable which should be an
222
- # Integer. variant is needed to generate rundom functions.
224
+ # Integer. variant is needed to generate random functions.
223
225
  def variant(v)
224
226
  self.class.new do |n, r|
225
227
  gen = r
@@ -44,7 +44,6 @@ class Integer
44
44
  m = (self >= 0) ? 2 * self : (-2) * self + 1
45
45
  g.variant(m)
46
46
  end
47
-
48
47
  end
49
48
 
50
49
  class PositiveInteger < Integer
@@ -97,7 +96,7 @@ class NegativeInteger < Integer
97
96
  def self.arbitrary
98
97
  RushCheck::Gen.sized do |n|
99
98
  n = (-1) - n if n >= 0
100
- RushCheck::Gen.choose(-n, -1)
99
+ RushCheck::Gen.choose(n, -1)
101
100
  end
102
101
  end
103
102
 
@@ -19,11 +19,11 @@ class String
19
19
 
20
20
  def self.arbitrary
21
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
- end
26
- end
22
+ # Note the Benford's law;
23
+ # http://mathworld.wolfram.com/BenfordsLaw.html
24
+ # This says that (a random integer % 128).chr seems not
25
+ # have /really randomness/.
26
+ RushCheck::Gen.unit((0..n).map{rand(128).chr}.join)
27
27
  end
28
28
  end
29
29
 
@@ -14,7 +14,7 @@ module RushCheck
14
14
  raise(NotImplementedError, "This method should be overrided.")
15
15
  end
16
16
 
17
- def check(config=RushCheck::Config.quick)
17
+ def check(config=RushCheck::Config.new)
18
18
  config.tests(property.gen, RushCheck::TheStdGen.instance)
19
19
  end
20
20
  alias quick_check :check
@@ -97,6 +97,10 @@ module RushCheck
97
97
  nil
98
98
  end
99
99
 
100
+ def silent_check
101
+ check(RushCheck::Config.silent)
102
+ end
103
+
100
104
  def test
101
105
  check(RushCheck::Config.verbose)
102
106
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RushCheck
5
5
 
6
- VERSION = "0.7"
6
+ VERSION = "0.8"
7
7
 
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rushcheck
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.7"
7
- date: 2006-10-28 00:00:00 +09:00
6
+ version: "0.8"
7
+ date: 2007-08-25 00:00:00 +09:00
8
8
  summary: A lightweight random testing tool
9
9
  require_paths:
10
10
  - lib
@@ -59,6 +59,7 @@ files:
59
59
  - data/rushcheck/rdoc
60
60
  - data/rushcheck/doc/policy.txt
61
61
  - data/rushcheck/doc/rushcheck.thtml
62
+ - data/rushcheck/doc/spec.txt
62
63
  - data/rushcheck/examples/candy.rb
63
64
  - data/rushcheck/examples/printf.rb
64
65
  - data/rushcheck/examples/proc.rb