diff options
| author | seaker <3043281+seaker@users.noreply.github.com> | 2021-05-10 23:36:02 +0800 |
|---|---|---|
| committer | seaker <3043281+seaker@users.noreply.github.com> | 2021-05-10 23:36:02 +0800 |
| commit | b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed (patch) | |
| tree | a00fb83ed6d531b3592a2501e03a6b02157236f8 /challenge-112/roger-bell-west/python/ch-1.py | |
| parent | 144a4fa80fbfa1d1356d05d1da1a1e7ff4cd6ba9 (diff) | |
| parent | 5e535c759ec1826d95b3f49c4033db88803975ca (diff) | |
| download | perlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.tar.gz perlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.tar.bz2 perlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-112/roger-bell-west/python/ch-1.py')
| -rwxr-xr-x | challenge-112/roger-bell-west/python/ch-1.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-112/roger-bell-west/python/ch-1.py b/challenge-112/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..cf1ecbd798 --- /dev/null +++ b/challenge-112/roger-bell-west/python/ch-1.py @@ -0,0 +1,31 @@ +#! /usr/bin/python3 + +import unittest + +def cp(i): + p=[x for x in i.split('/') if x != '' and x != '.'] + d=True + while d: + d=False + for pi in range(1,len(p)): + if p[pi] == '..': + p=p[0:pi-2]+p[pi+1:-1] + d=True + break + return '/'+'/'.join(p) + +class TestCp(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(cp('/a/'),'/a','example 1') + + def test_ex2(self): + self.assertEqual(cp('/a/b//c/'),'/a/b/c','example 2') + + def test_ex3(self): + self.assertEqual(cp('/a/b/c/../..'),'/a','example 3') + + def test_ex4(self): + self.assertEqual(cp('/a/./b'),'/a/b','example 4') + +unittest.main() |
