aboutsummaryrefslogtreecommitdiff
path: root/challenge-321/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-321/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-321/roger-bell-west/python/ch-2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-321/roger-bell-west/python/ch-2.py b/challenge-321/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..baf1c7a1c7
--- /dev/null
+++ b/challenge-321/roger-bell-west/python/ch-2.py
@@ -0,0 +1,28 @@
+#! /usr/bin/python3
+
+def backspacecompare(a, b):
+ sa = []
+ for i in [a, b]:
+ oa = []
+ for c in i:
+ if c == "#":
+ oa.pop()
+ else:
+ oa.append(c)
+ sa.append("".join(oa))
+ return sa[0] == sa[1]
+
+import unittest
+
+class TestBackspacecompare(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(backspacecompare("ab#c", "ad#c"), True, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(backspacecompare("ab##", "a#b#"), True, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(backspacecompare("a#b", "c"), False, 'example 3')
+
+unittest.main()