def test_negative_index(self): iterable = 'abcde' r = 4 n = factorial(len(iterable)) // factorial(len(iterable) - r) for index, expected in enumerate(permutations(iterable, r)): actual = mi.nth_permutation(iterable, r, index - n) self.assertEqual(actual, expected)
def test_long(self): iterable = tuple(range(180)) r = 4 index = 1000000 actual = mi.nth_permutation(iterable, r, index) expected = mi.nth(permutations(iterable, r), index) self.assertEqual(actual, expected)
def test_null(self): actual = mi.nth_permutation([], 0, 0) expected = tuple() self.assertEqual(actual, expected)
def test_r_equal_to_n(self): iterable = 'abcde' for index, expected in enumerate(permutations(iterable)): actual = mi.nth_permutation(iterable, None, index) self.assertEqual(actual, expected)
def test_r_less_than_n(self): iterable = 'abcde' r = 4 for index, expected in enumerate(permutations(iterable, r)): actual = mi.nth_permutation(iterable, r, index) self.assertEqual(actual, expected)
def _create_permutation(self, feed, index=0): permutation = nth_permutation(feed, r=self.length, index=index) username = "".join(permutation).lower() return username