PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_linkedlist.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 41 lines | 32 code | 7 blank | 2 comment | 0 complexity | 5608b3ab1d3ed093d5525734ff9e11d0 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test facets/linkedlist.rb
  2. require 'facets/linkedlist.rb'
  3. require 'test/unit'
  4. class TC_LinkedList < Test::Unit::TestCase
  5. #@cache #?
  6. def test_all
  7. ll = nil
  8. assert_nothing_raised('Failed while creating an LinkedList object.') { ll = LinkedList.new }
  9. assert_kind_of(LinkedList,ll,'Strangely, the created object does not appear to be an LinkedList.')
  10. assert_nothing_raised('Failed while pushing a value onto the linked list.') { ll.push 'a' }
  11. ll.push 'b'
  12. assert_nothing_raised('Failed while assigning a key/value to the linked list.') { ll['c'] = 3 }
  13. assert_equal(3,ll.first, 'First element in the linked list appears to be the wrong one.')
  14. assert_equal('b',ll.last, 'Last element in the linked list appears to be the wrong one.')
  15. assert_nothing_raised('Failed while unshifting a value onto the linked list.') { ll.unshift 'd' }
  16. assert_equal('d',ll.first, 'The prior unshift apparently failed.')
  17. assert_equal('a',ll['a'], 'Accessing an element by key failed.')
  18. assert_equal(4,ll.length, 'The length of the linked list appears to be incorrect.')
  19. d = nil
  20. assert_nothing_raised('Failed while deleting an element from the middle of the list.') { d = ll.delete('a') }
  21. assert_equal('a',d, 'The prior delete returned the wrong value for the deleted object.')
  22. assert_equal(3,ll.length, 'The length of the linked list appears to be incorrect following the prior deletion.')
  23. assert_nothing_raised('Failed while popping an element from the end of the list.') { d = ll.pop }
  24. assert_equal('b',d, 'The prior pop returned the wrong value.')
  25. assert_equal(2,ll.length, 'The length of the linked list appears to be incorrect following the prior pop.')
  26. assert_equal(['d','c'],ll.queue, 'The queue of keys for the list is incorrect.')
  27. assert_equal(['d',3],ll.to_a, 'Converting the list to an array (of values) seems to have failed.')
  28. expected = [['c',3],['d','d']]
  29. ll.each do |k,v|
  30. e = expected.pop
  31. assert_equal(e,[k,v], 'While iterates over the list via each(), the value from this iteration is not what was expected.')
  32. end
  33. end
  34. end