Skip to content

Fixed minor bugs from unix.path #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions algorithms/unix/path/simplify_path.py
Original file line number Diff line number Diff line change
@@ -14,10 +14,12 @@

Reference: https://leetcode.com/problems/simplify-path/description/
"""
import posixpath


import os
def simplify_path_v1(path):
return os.path.abspath(path)
return posixpath.normpath(path)


def simplify_path_v2(path):
stack, tokens = [], path.split("/")
4 changes: 2 additions & 2 deletions tests/test_unix.py
Original file line number Diff line number Diff line change
@@ -22,11 +22,11 @@ def test_join_with_slash(self):
def test_full_path(self):
file_name = "file_name"
# Test full path relative
expect_path = "{}/{}".format(os.getcwd(), file_name)
expect_path = os.path.join('{}', '{}').format(os.getcwd(), file_name)
self.assertEqual(expect_path, full_path(file_name))
# Test full path with expanding user
# ~/file_name
expect_path = "{}/{}".format(os.path.expanduser('~'), file_name)
expect_path = os.path.join('{}', '{}').format(os.path.expanduser('~'), file_name)
self.assertEqual(expect_path, full_path("~/{}".format(file_name)))

def test_split(self):