Class: RubyPriorityQueueTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
PriorityQueueTest
Defined in:
lib/priority-queue/test/priority_queue_test.rb

Instance Method Summary collapse

Methods included from PriorityQueueTest

#teardown, #test_access, #test_decrease_priority, #test_delete, #test_delete_min, #test_delete_min_return_key, #test_delete_min_return_priority, #test_dup, #test_each, #test_empty?, #test_example_1, #test_has_key?, #test_increase_priority, #test_length, #test_merge, #test_min, #test_min_key, #test_min_priority, #test_push, #test_push_decrease_pop, #test_push_pop

Instance Method Details

#setupObject



305
306
307
# File 'lib/priority-queue/test/priority_queue_test.rb', line 305

def setup
  @q = RubyPriorityQueue.new
end

#test_private_delete_firstObject



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/priority-queue/test/priority_queue_test.rb', line 346

def test_private_delete_first
  q = RubyPriorityQueue.new
  q[0] = 0
  q[1] = 1
  q[2] = 2
  tc = self
  q.instance_eval do
    2.times do
	r = @rootlist
	tc.assert_equal(r, delete_first)
	tc.assert_equal(r.right, r)
	tc.assert_equal(r.left, r)
	tc.assert_not_equal(r, @rootlist.left)
	tc.assert_not_equal(r, @rootlist.right)
    end
    r = @rootlist
    tc.assert_equal(r, delete_first)
    tc.assert_equal(r.right, r)
    tc.assert_equal(r.left, r)
    tc.assert_equal(nil, @rootlist)

    tc.assert_equal(nil, delete_first)
  end
end


309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/priority-queue/test/priority_queue_test.rb', line 309

def test_private_link_nodes
  q = RubyPriorityQueue.new
  q[0] = 0
  q[1] = 1
  tc = self
  q.instance_eval do
    n0 = @nodes[0]
    n1 = @nodes[1]
    n0.right = n0.left = n0
    n1.right = n1.left = n1
    tc.assert_equal(n0, link_nodes(n0, n1))
    tc.assert_equal(n0.child, n1)
    tc.assert_equal(n1.child, nil)
    tc.assert_equal(n0.left, n0)
    tc.assert_equal(n1.left, n1)
    tc.assert_equal(n0.right, n0)
    tc.assert_equal(n1.right, n1)
  end
  q = RubyPriorityQueue.new
  q[0] = 0
  q[1] = 1
  q.instance_eval do
    n0 = @nodes[0]
    n1 = @nodes[1]
    n0.right = n0.left = n0
    n1.right = n1.left = n1
    tc.assert_equal(n0, link_nodes(n1, n0))
    tc.assert_equal(n0.child, n1)
    tc.assert_equal(n1.child, nil)
    tc.assert_equal(n0.left, n0)
    tc.assert_equal(n1.left, n1)
    tc.assert_equal(n0.right, n0)
    tc.assert_equal(n1.right, n1)
  end
end