Guest User

Untitled

a guest
Aug 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. require 'linked_list'
  2.  
  3. describe '.LinkedList' do
  4. describe '.add' do
  5. it 'adds an element to a linked list' do
  6. linked_list = LinkedList.new
  7.  
  8. linked_list.add(1)
  9.  
  10. result = linked_list.traverse
  11. expect(result).to eq '1'
  12. end
  13. end
  14.  
  15. describe '.delete' do
  16. it 'it deletes an element' do
  17. linked_list = LinkedList.new
  18.  
  19. linked_list.add(3)
  20. linked_list.add(2)
  21. linked_list.add(1)
  22.  
  23. linked_list.delete(2)
  24.  
  25. result = linked_list.traverse
  26. expect(result).to eq('1 3')
  27. end
  28.  
  29. it 'it does nothing if the element does not exist' do
  30. linked_list = LinkedList.new
  31.  
  32. linked_list.add(3)
  33. linked_list.add(2)
  34. linked_list.add(1)
  35.  
  36. linked_list.delete(4)
  37.  
  38. result = linked_list.traverse
  39. expect(result).to eq('1 2 3')
  40. end
  41.  
  42. it 'it deletes the first element' do
  43. linked_list = LinkedList.new
  44.  
  45. linked_list.add(3)
  46. linked_list.add(2)
  47. linked_list.add(1)
  48.  
  49. linked_list.delete(1)
  50.  
  51. result = linked_list.traverse
  52. expect(result).to eq('2 3')
  53. end
  54. end
  55.  
  56. describe '.replace' do
  57. it 'replaces the element at position' do
  58. linked_list = LinkedList.new
  59.  
  60. linked_list.add(3)
  61. linked_list.add(2)
  62. linked_list.add(1)
  63.  
  64. linked_list.replace(4, 1)
  65.  
  66. result = linked_list.traverse
  67. expect(result).to eq('1 4 3')
  68. end
  69.  
  70. it 'does nothing if the position does not exist' do
  71. linked_list = LinkedList.new
  72.  
  73. linked_list.add(3)
  74. linked_list.add(2)
  75. linked_list.add(1)
  76.  
  77. linked_list.replace(4, 6)
  78.  
  79. result = linked_list.traverse
  80. expect(result).to eq('1 2 3')
  81. end
  82. end
  83. end
Add Comment
Please, Sign In to add comment