def test_at_raises_when_given_index_is_negative( object_under_test: SinglyLinkedList, ): object_under_test.insert_at_end(elem=18) negative_index = -1 with pytest.raises(NegativeIndex) as exc: object_under_test.at(idx=negative_index) assert f"Given index: {negative_index} is negative" in str(exc.value)
def test_at_raises_when_given_index_bigger_than_size( object_under_test: SinglyLinkedList, ): object_under_test.insert_at_end(elem=18) index_equal_to_size = 7 with pytest.raises(OutOfRangeIndex) as exc: object_under_test.at(idx=index_equal_to_size) assert ( f"Given index: {index_equal_to_size} is equal to or bigger than size: 1" in str(exc.value) )
def test_given_one_elem_then_at_zero_has_no_next( object_under_test: SinglyLinkedList, ): object_under_test.insert_at_end(elem=43) node = object_under_test.at(idx=0) assert node.next is None
def test_given_one_elem_then_at_zero_returns_that_elem( object_under_test: SinglyLinkedList, ): first_elem = 32 object_under_test.insert_at_end(elem=first_elem) node = object_under_test.at(idx=0) assert node.data == first_elem
def test_given_two_elements_then_at_one_returns_second_elem( object_under_test: SinglyLinkedList, ): second_elem = 311 object_under_test.insert_at_end(elem=78) object_under_test.insert_at_end(elem=second_elem) node = object_under_test.at(idx=1) assert node.data == second_elem
def test_at_raises_when_list_is_empty( object_under_test: SinglyLinkedList, ): with pytest.raises(AtOnEmptyLinkedList): object_under_test.at(idx=6)