Skip to content

Commit

Permalink
permutations
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 15, 2019
1 parent cf19426 commit f155431
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kyu_4/permutations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Permutations

In this kata you have to create all permutations of an input string and remove duplicates, if present. This means, you have to shuffle all letters from the input in all possible orders.

### Examples:

```bash
permutations('a'); # ['a']
permutations('ab'); # ['ab', 'ba']
permutations('aabb'); # ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']
```

The order of the permutations doesn't matter.

[Source](https://www.codewars.com/kata/5254ca2719453dcc0b00027d/train/python)
Empty file added kyu_4/permutations/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions kyu_4/permutations/permutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Created by Egor Kostan.
# GitHub: https://github.com/ikostan
# LinkedIn: https://www.linkedin.com/in/egor-kostan/


def permutations(string) -> list:
"""
creates all permutations of an input string and
remove duplicates, if present. This means, you
have to shuffle all letters from the input in all
possible orders.
"""
pass
59 changes: 59 additions & 0 deletions kyu_4/permutations/test_permutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Created by Egor Kostan.
# GitHub: https://github.com/ikostan
# LinkedIn: https://www.linkedin.com/in/egor-kostan/

# ALGORITHMS PERMUTATIONS STRINGS

import allure
import unittest
import pytest
from utils.log_func import print_log
from kyu_4.permutations.permutations import permutations


@allure.epic("4 kyu")
@allure.parent_suite('Competent')
@allure.suite("Algorithms")
@allure.sub_suite("Unit Tests")
@allure.feature("String")
@allure.story("Permutations")
@pytest.mark.skip(reason="The solution is not ready")
class PermutationsTestCase(unittest.TestCase):

def test_permutations(self):
"""
Testing permutations function
Test that permutations function creates all
permutations of an input string and
remove duplicates, if present. This means, you
have to shuffle all letters from the input in all
possible orders.
"""

allure.dynamic.title("Testing permutations function")
allure.dynamic.severity(allure.severity_level.NORMAL)

with allure.step("Enter a test string and verify the output"):
test_data = [
('a', ['a']),
('ab', ['ab', 'ba']),
('aabb', ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']),
('abc', ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']),
('abcd', ['abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb',
'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca',
'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba',
'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba']),
('dcba', ['abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb',
'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca',
'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba',
'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba'])
]

for string, expected in test_data:

print_log(string=string,
expected=expected)

self.assertListEqual(sorted(expected),
sorted(permutations(string)))

1 comment on commit f155431

@ikostan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy detected an issue:

Message: Unnecessary pass statement

Occurred on:

Currently on:

Please sign in to comment.