rubycheck 0.0.1
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/example.rb +38 -0
- data/lib/rubycheck.rb +51 -0
- metadata +46 -0
data/example.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubycheck"
|
4
|
+
|
5
|
+
module RubyCheck
|
6
|
+
def self.gen_even
|
7
|
+
i = gen_int
|
8
|
+
|
9
|
+
if i % 2 == 0
|
10
|
+
i
|
11
|
+
else
|
12
|
+
i + 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
propEven = Proc.new { |n| n.even? }
|
18
|
+
|
19
|
+
# Should fail.
|
20
|
+
RubyCheck::for_all(propEven, [:gen_int])
|
21
|
+
|
22
|
+
# Should pass.
|
23
|
+
RubyCheck::for_all(propEven, [:gen_even])
|
24
|
+
|
25
|
+
module RubyCheck
|
26
|
+
def self.gen_palindrome
|
27
|
+
s = gen_str
|
28
|
+
s + s.reverse
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
propPalindrome = Proc.new { |s| s == s.reverse }
|
33
|
+
|
34
|
+
# Should fail.
|
35
|
+
RubyCheck::for_all(propPalindrome, [:gen_str])
|
36
|
+
|
37
|
+
# Should pass.
|
38
|
+
RubyCheck::for_all(propPalindrome, [:gen_palindrome])
|
data/lib/rubycheck.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyCheck
|
2
|
+
# Returns a random integer from 0 to 10^10 - 1.
|
3
|
+
def self.gen_int
|
4
|
+
Random::rand(10e10).to_i
|
5
|
+
end
|
6
|
+
|
7
|
+
# Returns a random byte.
|
8
|
+
def self.gen_byte
|
9
|
+
gen_int % 256
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a random ASCII character.
|
13
|
+
def self.gen_char
|
14
|
+
(gen_int % 128).chr
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returning a random array given a value generator.
|
18
|
+
def self.gen_array(gen_sym)
|
19
|
+
len = gen_int % 100
|
20
|
+
|
21
|
+
0.upto(len).collect { |i| self.send(gen_sym) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a random string.
|
25
|
+
def self.gen_str
|
26
|
+
gen_array(:gen_char).join("")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Evaluates property over 100 random unit tests,
|
30
|
+
# with argument values specified in generators.
|
31
|
+
def self.for_all(property, gen_syms)
|
32
|
+
trials = 100
|
33
|
+
|
34
|
+
passed_all = true
|
35
|
+
|
36
|
+
0.upto(trials - 1) { |i|
|
37
|
+
test_case = gen_syms.collect { |gen_sym| self.send(gen_sym) }
|
38
|
+
|
39
|
+
propertyHolds = property.call(*test_case)
|
40
|
+
|
41
|
+
if not propertyHolds
|
42
|
+
puts "*** Failed!"
|
43
|
+
puts test_case
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
}
|
47
|
+
|
48
|
+
puts "+++ OK, passed #{trials} tests."
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubycheck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Pennebaker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: See example.rb for API usage.
|
15
|
+
email: andrew.pennebaker@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rubycheck.rb
|
21
|
+
- example.rb
|
22
|
+
homepage: http://www.yellosoft.us/quickcheck
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: a Ruby port of the QuickCheck unit test framework
|
46
|
+
test_files: []
|