





def    A_(			A				,      A				,      A				,      A   ):
	UpperCAmelCase_						,	UpperCAmelCase_								=     len(A   ), len(grid[0]   )
	if (
	    min(A				,      A   ) < 0
	    or row == row_length
	    or col == col_length
	    or (row, col) in visit
	    or grid[row][col] == 1
	):
		return 0
	if row == row_length - 1 and col == col_length - 1:
		return 1

	visit.add((row, col)   )

	UpperCAmelCase_								=     0
	count += depth_first_search(A				,      row + 1				,      A				,      A   )
	count += depth_first_search(A				,      row - 1				,      A				,      A   )
	count += depth_first_search(A				,      A				,      col + 1				,      A   )
	count += depth_first_search(A				,      A				,      col - 1				,      A   )

	visit.remove((row, col)   )
	return count


if __name__ == "__main__":
				import doctest

				doctest.testmod()









import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.text import TextDatasetReader

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases




def    A_(			A				,      A   ):
	assert isinstance(A				,      A   )
	assert dataset.num_rows == 4
	assert dataset.num_columns == 1
	assert dataset.column_names == ["text"]
	for feature, expected_dtype in expected_features.items():
		assert dataset.features[feature].dtype == expected_dtype




@pytest.mark.parametrize("""keep_in_memory"""				,      [False, True]   )
def    A_(			A				,      A				,      A   ):
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
		UpperCAmelCase_								=     TextDatasetReader(A				,      cache_dir=A				,      keep_in_memory=A   ).read()
	_check_text_dataset(A				,      A   )




@pytest.mark.parametrize(
    """features"""				,      [
        None,
        {"""text""": """string"""},
        {"""text""": """int32"""},
        {"""text""": """float32"""},
    ]				,      )
def    A_(			A				,      A				,      A   ):
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	UpperCAmelCase_								=     features.copy() if features else default_expected_features
	UpperCAmelCase_								=     (
	    Features({feature: Value(A   ) for feature, dtype in features.items()}   ) if features is not None else None
	)
	UpperCAmelCase_								=     TextDatasetReader(A				,      features=A				,      cache_dir=A   ).read()
	_check_text_dataset(A				,      A   )




@pytest.mark.parametrize("""split"""				,      [None, NamedSplit("""train"""   ), """train""", """test"""]   )
def    A_(			A				,      A				,      A   ):
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	UpperCAmelCase_								=     TextDatasetReader(A				,      cache_dir=A				,      split=A   ).read()
	_check_text_dataset(A				,      A   )
	assert dataset.split == split if split else "train"




@pytest.mark.parametrize("""path_type"""				,      [str, list]   )
def    A_(			A				,      A				,      A   ):
	if issubclass(A				,      A   ):
		UpperCAmelCase_								=     text_path
	elif issubclass(A				,      A   ):
		UpperCAmelCase_								=     [text_path]
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	UpperCAmelCase_								=     TextDatasetReader(A				,      cache_dir=A   ).read()
	_check_text_dataset(A				,      A   )




def    A_(			A				,      A				,      A=("train",)   ):
	assert isinstance(A				,      A   )
	for split in splits:
		UpperCAmelCase_								=     dataset_dict[split]
		assert dataset.num_rows == 4
		assert dataset.num_columns == 1
		assert dataset.column_names == ["text"]
		for feature, expected_dtype in expected_features.items():
			assert dataset.features[feature].dtype == expected_dtype




@pytest.mark.parametrize("""keep_in_memory"""				,      [False, True]   )
def    A_(			A				,      A				,      A   ):
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
		UpperCAmelCase_								=     TextDatasetReader({"""train""": text_path}				,      cache_dir=A				,      keep_in_memory=A   ).read()
	_check_text_datasetdict(A				,      A   )




@pytest.mark.parametrize(
    """features"""				,      [
        None,
        {"""text""": """string"""},
        {"""text""": """int32"""},
        {"""text""": """float32"""},
    ]				,      )
def    A_(			A				,      A				,      A   ):
	UpperCAmelCase_								=     tmp_path / """cache"""
	# CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
	UpperCAmelCase_								=     {"""text""": """string"""}
	UpperCAmelCase_								=     features.copy() if features else default_expected_features
	UpperCAmelCase_								=     (
	    Features({feature: Value(A   ) for feature, dtype in features.items()}   ) if features is not None else None
	)
	UpperCAmelCase_								=     TextDatasetReader({"""train""": text_path}				,      features=A				,      cache_dir=A   ).read()
	_check_text_datasetdict(A				,      A   )




@pytest.mark.parametrize("""split"""				,      [None, NamedSplit("""train"""   ), """train""", """test"""]   )
def    A_(			A				,      A				,      A   ):
	if split:
		UpperCAmelCase_								=     {split: text_path}
	else:
		UpperCAmelCase_								=     """train"""
		UpperCAmelCase_								=     {"""train""": text_path, """test""": text_path}
	UpperCAmelCase_								=     tmp_path / """cache"""
	UpperCAmelCase_								=     {"""text""": """string"""}
	UpperCAmelCase_								=     TextDatasetReader(A				,      cache_dir=A   ).read()
	_check_text_datasetdict(A				,      A				,      splits=list(path.keys()   )   )
	assert all(dataset[split].split == split for split in path.keys()   )


