From f1554318015c5f99a6b414fef055fa6cb75895da Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 14 Dec 2019 21:32:10 -0800 Subject: [PATCH] permutations --- kyu_4/permutations/README.md | 15 +++++++ kyu_4/permutations/__init__.py | 0 kyu_4/permutations/permutations.py | 13 ++++++ kyu_4/permutations/test_permutations.py | 59 +++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 kyu_4/permutations/README.md create mode 100644 kyu_4/permutations/__init__.py create mode 100644 kyu_4/permutations/permutations.py create mode 100644 kyu_4/permutations/test_permutations.py diff --git a/kyu_4/permutations/README.md b/kyu_4/permutations/README.md new file mode 100644 index 00000000000..ead73abe929 --- /dev/null +++ b/kyu_4/permutations/README.md @@ -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) \ No newline at end of file diff --git a/kyu_4/permutations/__init__.py b/kyu_4/permutations/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kyu_4/permutations/permutations.py b/kyu_4/permutations/permutations.py new file mode 100644 index 00000000000..a83a766ca8c --- /dev/null +++ b/kyu_4/permutations/permutations.py @@ -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 diff --git a/kyu_4/permutations/test_permutations.py b/kyu_4/permutations/test_permutations.py new file mode 100644 index 00000000000..c3a17375ed5 --- /dev/null +++ b/kyu_4/permutations/test_permutations.py @@ -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)))