def test_permutations_simple(): """Test permutations """ assert recursion.permutations("xyz") == [ 'zyx', 'yzx', 'yxz', 'zxy', 'xzy', 'xyz' ] assert recursion.permutations("cat") == [ 'tac', 'atc', 'act', 'tca', 'cta', 'cat' ]
def test_permutations_long_strings(): """Test permutations with longer inputs.""" perms1 = recursion.permutations("Python") assert "Python" in perms1 assert "hontyP" in perms1 assert len(perms1) == 720 perms2 = recursion.permutations("theeyes") assert len(perms2) == 840 assert "theysee" in perms2
def test_permutations_no_duplicates(): """Permutation list should not contain any duplicates.""" aabc_perms = [ 'cbaa', 'bcaa', 'baca', 'baac', 'caba', 'acba', 'abca', 'abac', 'caab', 'acab', 'aacb', 'aabc' ] assert recursion.permutations("aabc") == aabc_perms
def testPermutations(self): self.assertItemsEqual( rn.permutations([1, 2, 3]), [[1, 2, 3], [2, 1, 3], [3, 2, 1], [1, 3, 2], [2, 3, 1], [3, 1, 2]]) self.assertItemsEqual( rn.permutations_nr([1, 2, 3]), [[1, 2, 3], [2, 1, 3], [3, 2, 1], [1, 3, 2], [2, 3, 1], [3, 1, 2]])
def test_permutation(self): assert permutations("0") == ["0"] assert permutations("1") == ["1"] assert permutations("2") == ["2"] assert permutations("3") == ["3"] assert permutations("12") == ["12", "21"] assert permutations("23") == ["23", "32"] three = permutations("123") three.sort() assert three == ["123", "132", "213", "231", "312", "321"] four = permutations("1234") four.sort() assert four == ['1234', '1234', '1324', '1324', '2134', '2134', '2314', '2314', '2341', '2341', '2431', '2431', '3124', '3124', '3214', '3214', '3241', '3241', '3421', '3421', '4231', '4231', '4321', '4321']
def test_permutations_empty(): """Test permutations with empty input.""" assert recursion.permutations("") == ['']