def test_when_there_is_only_one_node(self): e1 = r.Element(1) li = r.LinkedList(e1) element = li.get_kth_to_last_element(3) self.assertEqual(element.value, 1)
def test_empty_list(self): linked_list = return_kth_to_last.LinkedList() answers = [ None, None, None, None, None, None, ] self.return_kth_to_last_test(linked_list, answers)
def test_two_elem_list(self): linked_list = return_kth_to_last.LinkedList( return_kth_to_last.Node(2, return_kth_to_last.Node(1))) answers = [ return_kth_to_last.Node(1), return_kth_to_last.Node(2), None, None, None, None, ] self.return_kth_to_last_test(linked_list, answers)
def test_when_there_is_more_than_one_node(self): e1 = r.Element(1) e2 = r.Element(2) e3 = r.Element(3) e4 = r.Element(4) li = r.LinkedList(e1) li.append(e2) li.append(e3) li.append(e4) element = li.get_kth_to_last_element(2) self.assertEqual(element.value, 2)
def test_when_head_is_null(self): li = r.LinkedList() self.assertEqual(li.get_kth_to_last_element(3), None)