Ejemplo n.º 1
0
 def test_pop_from_singleton_list_removes_head(self):
     sut = LinkedList([1])
     self.assertEqual(sut.pop(), 1)
     with self.assertRaises(EmptyListException) as err:
         sut.head()
     self.assertEqual(type(err.exception), EmptyListException)
     self.assertEqual(err.exception.args[0], "The list is empty.")
 def test_non_empty_list_traverse(self):
     sut = LinkedList(range(10))
     current = sut.head()
     for i in range(10):
         self.assertEqual(current.value(), 9 - i)
         current = current.next()
     self.assertIsNone(current)
Ejemplo n.º 3
0
 def test_non_empty_list_traverse(self):
     sut = LinkedList(range(10))
     current = sut.head()
     for i in range(10):
         self.assertEqual(current.value(), 9 - i)
         current = current.next()
     self.assertIsNone(current)
 def test_push_and_pop(self):
     sut = LinkedList([1, 2])
     sut.push(3)
     self.assertEqual(len(sut), 3)
     self.assertEqual(sut.pop(), 3)
     self.assertEqual(sut.pop(), 2)
     self.assertEqual(sut.pop(), 1)
     self.assertEqual(len(sut), 0)
     sut.push(4)
     self.assertEqual(len(sut), 1)
     self.assertEqual(sut.head().value(), 4)
Ejemplo n.º 5
0
 def test_push_and_pop(self):
     sut = LinkedList([1, 2])
     sut.push(3)
     self.assertEqual(len(sut), 3)
     self.assertEqual(sut.pop(), 3)
     self.assertEqual(sut.pop(), 2)
     self.assertEqual(sut.pop(), 1)
     self.assertEqual(len(sut), 0)
     sut.push(4)
     self.assertEqual(len(sut), 1)
     self.assertEqual(sut.head().value(), 4)
Ejemplo n.º 6
0
 def test_pop_from_singleton_list_removes_head(self):
     sut = LinkedList([1])
     self.assertEqual(sut.pop(), 1)
     with self.assertRaisesWithMessage(EmptyListException):
         sut.head()
Ejemplo n.º 7
0
 def test_can_pop_from_non_empty_list(self):
     sut = LinkedList([3, 4, 5])
     self.assertEqual(sut.pop(), 5)
     self.assertEqual(len(sut), 2)
     self.assertEqual(sut.head().value(), 4)
Ejemplo n.º 8
0
 def test_pushing_to_empty_list_changes_head(self):
     sut = LinkedList()
     sut.push(5)
     self.assertEqual(len(sut), 1)
     self.assertEqual(sut.head().value(), 5)
Ejemplo n.º 9
0
 def test_non_empty_list_has_correct_head(self):
     sut = LinkedList([1, 2])
     self.assertEqual(sut.head().value(), 2)
Ejemplo n.º 10
0
 def test_singleton_list_has_head(self):
     sut = LinkedList([1])
     self.assertEqual(sut.head().value(), 1)
 def test_non_empty_list_has_correct_head(self):
     sut = LinkedList([1, 2])
     self.assertEqual(sut.head().value(), 2)
 def test_error_on_empty_list_head(self):
     sut = LinkedList()
     with self.assertRaisesWithMessage(EmptyListException):
         sut.head()
 def test_singleton_list_head_has_no_next(self):
     sut = LinkedList([1])
     self.assertIsNone(sut.head().next())
 def test_pop_from_singleton_list_removes_head(self):
     sut = LinkedList([1])
     self.assertEqual(sut.pop(), 1)
     with self.assertRaisesWithMessage(EmptyListException):
         sut.head()
 def test_can_from_non_empty_list(self):
     sut = LinkedList([3, 4, 5])
     self.assertEqual(sut.pop(), 5)
     self.assertEqual(len(sut), 2)
     self.assertEqual(sut.head().value(), 4)
 def test_pushing_to_empty_list_changes_head(self):
     sut = LinkedList()
     sut.push(5)
     self.assertEqual(len(sut), 1)
     self.assertEqual(sut.head().value(), 5)
Ejemplo n.º 17
0
 def test_singleton_list_head_has_no_next(self):
     sut = LinkedList([1])
     self.assertIsNone(sut.head().next())
Ejemplo n.º 18
0
 def test_error_on_empty_list_head(self):
     sut = LinkedList()
     with self.assertRaisesWithMessage(EmptyListException):
         sut.head()
Ejemplo n.º 19
0
 def test_error_on_empty_list_head(self):
     sut = LinkedList()
     with self.assertRaises(EmptyListException) as err:
         sut.head()
     self.assertEqual(type(err.exception), EmptyListException)
     self.assertEqual(err.exception.args[0], "The list is empty.")
 def test_singleton_list_has_head(self):
     sut = LinkedList([1])
     self.assertEqual(sut.head().value(), 1)