Пример #1
0
 def test_insert_remove_and_reverse_list( self ):
     ll = DoubleLinkedList()
     ll.add( 50 )
     ll.addEnd( 100 )
     ll.insert( 150, ll.search(50) ) # insert in middle
     self.assertEqual( ll.size(), 3 )
     ll.remove( ll.search( 50 ) )
     self.assertEqual( ll.size(), 2 )
     ll.reverse()
     # NOTE: This test is testing that you don't forget to
     # update next / prev properly when inserting..
     self.assertEqual( ll.toList(), [100, 150] )
Пример #2
0
 def test_nonempty_list( self ):
     ll = DoubleLinkedList()
     ll.add( 50 )
     ll.add( 55 )
     ll.add( 60 )
     ll.add( 65 )
     old_head = ll.head
     old_tail = ll.tail
     ll.reverse()
     self.assertEqual( ll.head, old_tail )
     self.assertEqual( ll.tail, old_head )
     self.assertEqual( ll.toList(), [50,55,60,65] )
Пример #3
0
 def test_nonempty_list_reverse_updates_prev_ptr( self ):
     ll = DoubleLinkedList()
     ll.add( 50 )
     ll.add( 55 )
     ll.add( 60 )
     ll.add( 65 )
     ll.reverse()
     n60 = ll.remove( ll.search( 60 ) )
     # NOTE: This test is testing that you aren't cheating with
     # your reverse() function by just doing what a singly linked
     # list does..  it might run into an infinite loop :)
     self.assertEqual( ll.toList(), [50,55,65] )
Пример #4
0
 def test_empty_list( self ):
     ll = DoubleLinkedList()
     ll.reverse()
     self.assertEqual( ll.toList(), [] )