rantly 0.2.0 → 3.0.0

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/test/rantly_test.rb CHANGED
@@ -1,284 +1,162 @@
1
- require 'test/test_helper'
2
- require 'rantly/property'
1
+ require 'test_helper'
2
+ require 'rantly/minitest_extensions'
3
3
 
4
4
  module RantlyTest
5
5
  end
6
6
 
7
- # check we generate the right kind of data.
8
- ## doesn't check for distribution
9
- class RantlyTest::Generator < Test::Unit::TestCase
10
- def setup
7
+ describe Rantly::Property do
8
+ before do
11
9
  Rantly.gen.reset
12
10
  end
13
-
14
- should "fail test generation" do
15
- assert_raises(Rantly::TooManyTries) {
16
- property_of { guard range(0,1) < 0 }.check
17
- }
18
- end
19
-
20
- should "generate literal value by returning itself" do
21
- property_of {
22
- i = integer
23
- [i,literal(i)]
24
- }.check { |(a,b)|
25
- assert_equal a, b
26
- }
27
- end
28
-
29
- should "generate integer in range" do
30
- property_of {
31
- i = integer
32
- [i,range(i,i)]
33
- }.check { |(a,b)|
34
- assert_equal a, b
35
- }
36
- property_of {
37
- lo, hi = [integer(100),integer(100)].sort
38
- [lo,hi,range(lo,hi)]
39
- }.check { |(lo,hi,int)|
40
- assert((lo..hi).include?(int))
41
- }
42
- end
43
-
44
- should "generate Fixnum only" do
45
- property_of { integer }.check { |i| assert i.is_a?(Integer) }
46
- end
47
-
48
- should "generate integer less than abs(n)" do
49
- property_of {
50
- n = range(0,10)
51
- [n,integer(n)]
52
- }.check {|(n,i)|
53
- assert n.abs >= i.abs
54
- }
55
- end
56
-
57
- should "generate Float" do
58
- property_of { float }.check { |f| assert f.is_a?(Float)}
59
- end
60
-
61
- should "generate Boolean" do
62
- property_of { boolean }.check { |t|
63
- assert t == true || t == false
64
- }
65
- end
66
-
67
- should "generate empty strings" do
68
- property_of {
69
- sized(0) { string }
70
- }.check { |s|
71
- assert s.empty?
72
- }
73
- end
74
-
75
- should "generate strings with the right regexp char classes" do
76
- char_classes = Rantly::Chars::CLASSES.keys
77
- property_of {
78
- char_class = choose(*char_classes)
79
- len = range(0,10)
80
- sized(len) { [len,char_class,string(char_class)]}
81
- }.check { |(len,char_class,str)|
82
- t = true
83
- chars = Rantly::Chars::CLASSES[char_class]
84
- str.each_byte { |c|
85
- unless chars.include?(c)
86
- t = false
87
- break
88
- end
89
- }
90
- assert_equal len, str.length
91
- assert t
92
- }
93
- end
94
11
 
95
- should "generate strings matching regexp" do
96
- property_of {
97
- sized(10) { string(/[abcd]/) }
98
- }.check { |s|
99
- assert s =~ /[abcd]+/
100
- }
12
+ it 'fail test generation' do
13
+ print "\n### TESTING A FAILING CASE, do not get scared"
14
+ assert_raises(Rantly::TooManyTries) do
15
+ property_of { guard range(0, 1).negative? }.check
16
+ end
101
17
  end
102
18
 
103
19
  # call
104
20
 
105
- should "call Symbol as method call (no arg)" do
106
- property_of {call(:integer)}.check { |i| i.is_a?(Integer)}
21
+ it 'call Symbol as method call (no arg)' do
22
+ property_of { call(:integer) }.check { |i| i.is_a?(Integer) }
107
23
  end
108
24
 
109
- should "call Symbol as method call (with arg)" do
110
- property_of {
111
- n = range(0,100)
112
- [n,call(:integer,n)]
113
- }.check { |(n,i)|
25
+ it 'call Symbol as method call (with arg)' do
26
+ property_of do
27
+ n = range(0, 100)
28
+ [n, call(:integer, n)]
29
+ end.check do |(n, i)|
114
30
  assert n.abs >= i.abs
115
- }
31
+ end
116
32
  end
117
33
 
118
- should "call Array by calling first element as method, the rest as args" do
119
- assert_raise(RuntimeError) {
120
- Rantly.gen.value {
34
+ it 'call Array by calling first element as method, the rest as args' do
35
+ assert_raises(RuntimeError) do
36
+ Rantly.gen.value do
121
37
  call []
122
- }
123
- }
124
- property_of {
38
+ end
39
+ end
40
+ property_of do
125
41
  i = integer
126
- [i,call(choose([:literal,i],[:range,i,i]))]
127
- }.check { |(a,b)|
42
+ [i, call(choose([:literal, i], [:range, i, i]))]
43
+ end.check do |(a, b)|
128
44
  assert_equal a, b
129
- }
45
+ end
130
46
  end
131
-
132
- should "call Proc with generator.instance_eval" do
133
- property_of {
134
- call Proc.new { true }
135
- }.check { |o|
47
+
48
+ it 'call Proc with generator.instance_eval' do
49
+ property_of do
50
+ call proc { true }
51
+ end.check do |o|
136
52
  assert_equal true, o
137
- }
138
- property_of {
139
- i0 = range(0,100)
140
- i1,s = call Proc.new {
141
- range(i0+1,i0+100)
53
+ end
54
+ property_of do
55
+ i0 = range(0, 100)
56
+ i1 = call proc {
57
+ range(i0 + 1, i0 + 100)
142
58
  }
143
- [i0,i1]
144
- }.check { |(i0,i1)|
145
- assert i0.is_a?(Fixnum) && i1.is_a?(Fixnum)
146
- assert i0 != i1
59
+ [i0, i1]
60
+ end.check do |(i0, i1)|
61
+ assert i0.is_a?(Integer) && i1.is_a?(Integer)
147
62
  assert i1 > i0
148
- }
63
+ assert i1 <= (i0 + 100)
64
+ end
149
65
  end
150
-
151
- should "raise if calling on any other value" do
152
- assert_raise(RuntimeError) {
66
+
67
+ it 'raise if calling on any other value' do
68
+ assert_raises(RuntimeError) do
153
69
  Rantly.gen.call 0
154
- }
70
+ end
155
71
  end
156
72
 
157
73
  # branch
158
74
 
159
- should "branch by Rantly#calling one of the args" do
160
- property_of {
75
+ it 'branch by Rantly#calling one of the args' do
76
+ property_of do
161
77
  branch :integer, :integer, :integer
162
- }.check { |o|
163
- assert o.is_a?(Fixnum)
164
- }
165
- property_of {
78
+ end.check do |o|
79
+ assert o.is_a?(Integer)
80
+ end
81
+ property_of do
166
82
  sized(10) { branch :integer, :string }
167
- }.check { |o|
168
- assert o.is_a?(Fixnum) || o.is_a?(String)
169
- }
83
+ end.check do |o|
84
+ assert o.is_a?(Integer) || o.is_a?(String)
85
+ end
170
86
  end
171
87
 
172
-
173
88
  # choose
174
-
175
- should "choose a value from args " do
176
- property_of {
89
+
90
+ it 'choose a value from args ' do
91
+ property_of do
177
92
  choose
178
- }.check {|o|
93
+ end.check do |o|
179
94
  assert_nil o
180
- }
181
- property_of {
95
+ end
96
+ property_of do
182
97
  choose 1
183
- }.check { |o|
98
+ end.check do |o|
184
99
  assert_equal 1, o
185
- }
186
- property_of {
187
- choose 1,2
188
- }.check { |o|
189
- assert o == 1 || o == 2
190
- }
191
- property_of {
192
- arr = sized(10) { array(:integer) }
193
- choose(*arr)
194
- }.check { |o|
195
- assert o.is_a?(Fixnum)
196
- }
197
- property_of {
100
+ end
101
+ property_of do
102
+ choose 1, 2
103
+ end.check do |o|
104
+ assert [1, 2].include? o
105
+ end
106
+ property_of do
107
+ arr = sized(10) { array { integer } }
108
+ choose(*arr)
109
+ end.check do |o|
110
+ assert o.is_a?(Integer)
111
+ end
112
+ property_of do
198
113
  # array of array of ints
199
- arr = sized(10) { array(Proc.new { array(:integer)})}
114
+ arr = sized(10) { array { array { integer } } }
200
115
  # choose an array from an array of arrays of ints
201
116
  choose(*arr)
202
- }.check { |arr|
117
+ end.check do |arr|
203
118
  assert arr.is_a?(Array)
204
- assert arr.all? { |o| o.is_a?(Fixnum)}
205
- }
119
+ assert arr.all? { |o| o.is_a?(Integer) }
120
+ end
206
121
  end
207
122
 
208
123
  # freq
209
124
 
210
- should "not pick an element with 0 frequency" do
211
- property_of {
212
- sized(10) {
213
- array Proc.new { freq([0,:string],[1,:integer]) }
214
- }
215
- }.check { |arr|
216
- assert arr.all? { |o| o.is_a?(Integer)}
217
- }
125
+ it 'not pick an element with 0 frequency' do
126
+ property_of do
127
+ sized(10) do
128
+ array { freq([0, :string], [1, :integer]) }
129
+ end
130
+ end.check do |arr|
131
+ assert arr.all? { |o| o.is_a?(Integer) }
132
+ end
218
133
  end
219
134
 
220
- should "handle degenerate freq pairs" do
221
- assert_raise(RuntimeError) {
222
- Rantly.gen.value {
135
+ it 'handle degenerate freq pairs' do
136
+ assert_raises(RuntimeError) do
137
+ Rantly.gen.value do
223
138
  freq
224
- }
225
- }
226
- property_of {
139
+ end
140
+ end
141
+ property_of do
227
142
  i = integer
228
- [i,freq([:literal,i])]
229
- }.check { |(a,b)|
143
+ [i, freq([:literal, i])]
144
+ end.check do |(a, b)|
230
145
  assert_equal a, b
231
- }
146
+ end
232
147
  end
148
+ end
233
149
 
234
- # array
150
+ # TODO: Determine type of tests required here.
235
151
 
236
- should "generate empty array" do
237
- property_of {
238
- sized(0) { array(:integer)}
239
- }.check { |o|
240
- assert o.empty?
241
- }
242
- end
243
-
244
- should "generate the right sized nested arrays" do
245
- property_of {
246
- size1 = range(5,10)
247
- size2 = range(0,size1-1)
248
- array = sized(size1) { array(Proc.new { sized(size2) { array(:integer)}})}
249
- [size1,array]
250
- }.check { |(size1,outter_array)|
251
- assert_equal size1, outter_array.size
252
- assert outter_array.all? { |inner_array| inner_array.size < size1 }
253
- }
254
- end
255
-
256
- should "generate array with right types" do
257
- property_of {
258
- sized(10) { array :integer,:string,:float }
259
- }.check { |arr|
260
- assert arr.all? { |o|
261
- case o
262
- when Fixnum, Float, String
263
- true
264
- else
265
- false
266
- end
267
- }
268
- }
152
+ # check we generate the right kind of data.
153
+ ## doesn't check for distribution
154
+ class RantlyTest::Generator < Minitest::Test
155
+ def setup
156
+ Rantly.gen.reset
269
157
  end
270
-
271
- # should "raise if generating an array without size" do
272
- # assert_raise(RuntimeError) {
273
- # Rantly.gen.value { array(:integer) }
274
- # }
275
- # end
276
-
277
158
  end
278
-
279
-
280
159
 
281
160
  # TODO: check that distributions of different methods look roughly correct.
282
- class RantlyTest::Distribution
283
-
161
+ class RantlyTest::Distribution < Minitest::Test
284
162
  end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+ require 'rantly/shrinks'
3
+ require 'rantly/minitest_extensions'
4
+
5
+ module RantlyTest
6
+ end
7
+
8
+ module RantlyTest::Shrinkers
9
+ end
10
+
11
+ describe Integer do
12
+ it 'not be able to shrink 0 integer' do
13
+ assert !0.shrinkable?
14
+ end
15
+
16
+ it 'shrink positive integers to something less than itself' do
17
+ assert(3.shrink < 3)
18
+ assert(2.shrink < 2)
19
+ assert_equal(0, 1.shrink)
20
+ end
21
+
22
+ it 'shrink negative integers to something larger than itself' do
23
+ assert(-3.shrink > -3)
24
+ assert(-2.shrink > -2)
25
+ assert_equal(0, -1.shrink)
26
+ end
27
+
28
+ it 'shrink 0 to itself' do
29
+ # hmm. should this be undefined?
30
+ assert_equal 0.shrink, 0
31
+ end
32
+ end
33
+
34
+ describe String do
35
+ it 'not be able to shrink empty string' do
36
+ assert !''.shrinkable?
37
+ end
38
+
39
+ it 'shrink a string one char shorter' do
40
+ property_of do
41
+ sized(10) { string }
42
+ end.check do |str|
43
+ assert_equal 9, str.shrink.length
44
+ end
45
+ end
46
+ end
47
+
48
+ describe Tuple do
49
+ it 'not be able to shrink empty tuple' do
50
+ assert !Tuple.new([]).shrinkable?
51
+ end
52
+
53
+ it 'shrink tuple by trying to shrink the last shrinkable element available' do
54
+ assert_equal [1, 0], Tuple.new([1, 1]).shrink.array
55
+ assert_equal [1, 0, 0], Tuple.new([1, 1, 0]).shrink.array
56
+ end
57
+
58
+ it 'do not remove element from array when no element is shrinkable' do
59
+ property_of do
60
+ n = integer(1..10)
61
+ a = Tuple.new(Array.new(n, 0))
62
+ [n, a]
63
+ end.check do |n, a|
64
+ assert_equal n, a.shrink.length
65
+ end
66
+ end
67
+ end
68
+
69
+ describe Hash do
70
+ it 'not be able to shrink empty hash' do
71
+ assert !{}.shrinkable?
72
+ end
73
+
74
+ it 'shrink a value if one of the values is shrinkable' do
75
+ assert_equal({ foo: 0, bar: 0 }, { foo: 1, bar: 0 }.shrink)
76
+ assert_equal({ foo: 0, bar: 0 }, { foo: 0, bar: 1 }.shrink)
77
+ end
78
+
79
+ it 'shrink by deleting an element in it if none of the values is shrinkable' do
80
+ assert_equal({}, { foo: 0 }.shrink)
81
+ end
82
+ end
83
+
84
+ describe 'Shrinker Test' do
85
+ it 'shrink data to smallest value that fails assertion' do
86
+ print "\n### TESTING A FAILING CASE, do not get scared"
87
+ # We try to generate an array of 10 elements, filled with ones.
88
+ # The property we try to test is that non of the element is
89
+ # larger than 1, and the array's length is less than 4.
90
+ test = property_of do
91
+ a = Deflating.new(Array.new(10, 1))
92
+ i = Random.rand(a.length)
93
+ a[i] = 1
94
+ a
95
+ end
96
+ assert_raises MiniTest::Assertion do
97
+ test.check do |a|
98
+ assert(a.array.none?(&:positive?) && a.length < 4, 'contains 1')
99
+ end
100
+ end
101
+
102
+ assert_equal [1], test.shrunk_failed_data.array
103
+ end
104
+ end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,15 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
1
+ # Require simplecov and coveralls before rantly application code.
2
+ require 'simplecov'
3
+ SimpleCov.start
4
4
 
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ begin
6
+ # Coveralls is marked as an _optional_ dependency, so don't
7
+ # throw a fit if it's not there.
8
+ require 'coveralls'
9
+ Coveralls.wear!
10
+ rescue LoadError
11
+ end
7
12
 
13
+ # Require rantly.
14
+ require 'minitest/autorun'
8
15
  require 'rantly'
9
-
10
- class Test::Unit::TestCase
11
- end
metadata CHANGED
@@ -1,71 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rantly
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
+ - Ana María Martínez Gómez
7
8
  - Howard Yeh
8
- autorequire:
9
+ - Anthony Bargnesi
10
+ - Eric Bischoff
11
+ autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
-
12
- date: 2010-01-04 00:00:00 -08:00
13
- default_executable:
14
+ date: 2024-10-21 00:00:00.000000000 Z
14
15
  dependencies: []
15
-
16
- description:
17
- email: hayeah@gmail.com
16
+ description:
17
+ email:
18
+ - anamma06@gmail.com
19
+ - hayeah@gmail.com
20
+ - abargnesi@gmail.com
21
+ - ebischoff@nerim.net
18
22
  executables: []
19
-
20
23
  extensions: []
21
-
22
- extra_rdoc_files:
24
+ extra_rdoc_files:
23
25
  - LICENSE
24
- - README.textile
25
- files:
26
- - .document
27
- - .gitignore
26
+ - README.md
27
+ - CHANGELOG.md
28
+ files:
29
+ - ".document"
30
+ - ".travis.yml"
31
+ - CHANGELOG.md
32
+ - Gemfile
28
33
  - LICENSE
29
- - README.textile
34
+ - README.md
30
35
  - Rakefile
31
36
  - VERSION.yml
32
37
  - lib/rantly.rb
33
38
  - lib/rantly/data.rb
34
39
  - lib/rantly/generator.rb
40
+ - lib/rantly/minitest.rb
41
+ - lib/rantly/minitest_extensions.rb
35
42
  - lib/rantly/property.rb
43
+ - lib/rantly/rspec.rb
44
+ - lib/rantly/rspec_extensions.rb
45
+ - lib/rantly/shrinks.rb
36
46
  - lib/rantly/silly.rb
37
47
  - lib/rantly/spec.rb
48
+ - lib/rantly/testunit_extensions.rb
38
49
  - rantly.gemspec
39
50
  - test/rantly_test.rb
51
+ - test/shrinks_test.rb
40
52
  - test/test_helper.rb
41
- has_rdoc: true
42
- homepage: http://github.com/hayeah/rantly
43
- licenses: []
44
-
45
- post_install_message:
46
- rdoc_options:
47
- - --charset=UTF-8
48
- require_paths:
53
+ homepage: https://github.com/rantly-rb/rantly
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
49
60
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
51
- requirements:
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
52
63
  - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- version:
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- requirements:
64
+ - !ruby/object:Gem::Version
65
+ version: 3.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
58
68
  - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
61
- version:
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
62
71
  requirements: []
63
-
64
- rubyforge_project:
65
- rubygems_version: 1.3.5
66
- signing_key:
67
- specification_version: 3
72
+ rubygems_version: 3.5.9
73
+ signing_key:
74
+ specification_version: 4
68
75
  summary: Ruby Imperative Random Data Generator and Quickcheck
69
- test_files:
70
- - test/rantly_test.rb
71
- - test/test_helper.rb
76
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg