From 93cca73bbcefe54afdb56ff5f50abfeaa9df9226 Mon Sep 17 00:00:00 2001 From: ca20110820 Date: Sun, 14 Apr 2024 13:10:11 +0800 Subject: [PATCH] fix: fixed simplify_path_v1 using normpath from posixpath fix: updated expect_path from test_full_path method in test_unix --- algorithms/unix/path/simplify_path.py | 6 ++++-- tests/test_unix.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/algorithms/unix/path/simplify_path.py b/algorithms/unix/path/simplify_path.py index 8880fc0c6..7cdf4581e 100644 --- a/algorithms/unix/path/simplify_path.py +++ b/algorithms/unix/path/simplify_path.py @@ -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("/") diff --git a/tests/test_unix.py b/tests/test_unix.py index 3cafba98f..63bf4cffc 100644 --- a/tests/test_unix.py +++ b/tests/test_unix.py @@ -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):