Skip to content

Commit a502f12

Browse files
committed
[Bugfix] Fix permuation formatting with zero length separators
1 parent 89223bd commit a502f12

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

challenges/challenge.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,11 @@ def format_path(self, integers, backwards=False):
380380

381381
def format_permutations(self, permutations, separator = '\n',
382382
element_separator = ' '):
383-
output = ''
383+
entries = []
384384
for perm in permutations:
385-
output += '('
386-
output += element_separator.join(
385+
entry = '('
386+
entry += element_separator.join(
387387
('+' if i > 0 else '') + str(i) for i in perm)
388-
output += ')' + separator
389-
return output[:-len(separator)]
388+
entry += ')'
389+
entries.append(entry)
390+
return separator.join(entries)

tests/test_challenge.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def test_format_permuations(self):
286286
expect = '(+1 -2)\n(-3 +4)'
287287
self.assertEqual(expect, actual)
288288

289-
def test_format_permuations_with_user_defined_joint(self):
289+
def test_format_permuations_with_user_defined_separator(self):
290290
"""Show user defined separators can be used."""
291291
list = [[1, -2], [-3, 4]]
292292
actual = self.challenge.format_permutations(
@@ -296,3 +296,15 @@ def test_format_permuations_with_user_defined_joint(self):
296296
)
297297
expect = '(+1 | -2), (-3 | +4)'
298298
self.assertEqual(expect, actual)
299+
300+
def test_format_permuations_with_user_defined_separator_of_length_zero(
301+
self):
302+
"""Show user defined separators can be used."""
303+
list = [[1, -2], [-3, 4]]
304+
actual = self.challenge.format_permutations(
305+
list,
306+
separator = '',
307+
element_separator = ''
308+
)
309+
expect = '(+1-2)(-3+4)'
310+
self.assertEqual(expect, actual)

0 commit comments

Comments
 (0)