Class: RandArrayTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- RandArrayTest
- Includes:
- RandTestHelpers
- Defined in:
- lib/rand.rb
Overview
:nodoc:
Instance Method Summary collapse
- #ar ⇒ Object
- #test_pick ⇒ Object
- #test_pick! ⇒ Object
- #test_pick_index ⇒ Object
- #test_pick_index! ⇒ Object
- #test_shuffle ⇒ Object
- #test_shuffle! ⇒ Object
Methods included from RandTestHelpers
Instance Method Details
#ar ⇒ Object
257 258 259 |
# File 'lib/rand.rb', line 257 def ar (0..99).to_a end |
#test_pick ⇒ Object
261 262 263 264 265 |
# File 'lib/rand.rb', line 261 def test_pick a = ar results = (0...a.size).map{ a.pick } assert true, results.all? {|r| a.include? r } end |
#test_pick! ⇒ Object
267 268 269 270 271 |
# File 'lib/rand.rb', line 267 def test_pick! a = ar results = (0...a.size).map{ a.pick! } assert true, results.sort == (0..99).to_a and a.empty? end |
#test_pick_index ⇒ Object
273 274 275 276 277 |
# File 'lib/rand.rb', line 273 def test_pick_index a = ar results = (0...a.size).map{ a.pick_index } assert true, results.all? {|r| r.between?(0, a.size-1) } end |
#test_pick_index! ⇒ Object
279 280 281 282 283 284 |
# File 'lib/rand.rb', line 279 def test_pick_index! a = ar # side-effect-relying block; a.size = a.size-1 after pick_index!, # so the picked index max value is the new a.size assert true, (0...a.size).all?{ a.pick_index!.between?(0, a.size) } and a.empty? end |
#test_shuffle ⇒ Object
286 287 288 289 290 |
# File 'lib/rand.rb', line 286 def test_shuffle a = ar shuffled = try_shuffling(a, a, :shuffle) assert true, shuffled.sort == a and shuffled != a end |
#test_shuffle! ⇒ Object
292 293 294 295 296 |
# File 'lib/rand.rb', line 292 def test_shuffle! a = ar try_shuffling(a, ar, :shuffle!) assert true, a != ar and a.sort == ar end |