add dfs method and its test-case.