def test_get_by_index_above_size(self): ''' When trying to access a node below index 0. 1. Index must be below 0. 2. LookupError expected ''' ll = LinkedList() with self.assertRaises(LookupError): ll.get_at(1)
def test_get_by_index_not_int(self): ''' When trying to access a node with a non-int index. 1. Index must be non-int. 2. TypeError expected. ''' ll = LinkedList() with self.assertRaises(TypeError): ll.get_at("1")
def test_get_by_index(self): ''' Returns the data attribute of the node at given index. 1. List size must be > 1. 2. Value must be present at given index. ''' ll = LinkedList() some_value = 15 ll.append("12") ll.append(18) ll.append(some_value) self.assertEqual(ll.get_at(2), some_value)
def test_get_index_of(self): ''' When trying to get the index of a given value. 1. The value must be added to the list beforehand. 2. Pass the value to the method. 3. Must return the index of the element. ''' ll = LinkedList() some_value = "Jolis!" ll.append("A") ll.append("B") ll.append(some_value) ll.append("C") returnal = ll.get_index_of(some_value) self.assertEqual(returnal, 2) self.assertEqual(ll.get_at(returnal), some_value)