Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_to_standard():
def gen(perm):
res = list(perm)
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
def test_avoiders_generic():
PermSet.avoiding(Perm.to_standard("your mom")).of_length(5)
res = PermSet.avoiding([Perm((0, 1, 2, 3)), Perm((1, 0))])
assert isinstance(res, PermSet)
ts = [
([[]], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
([[0, 1]], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
([[1, 0]], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
([[0, 1, 2]], [catalan(i) for i in range(8)]),
([[0, 2, 1]], [catalan(i) for i in range(8)]),
([[1, 0, 2]], [catalan(i) for i in range(8)]),
([[1, 2, 0]], [catalan(i) for i in range(8)]),
([[2, 0, 1]], [catalan(i) for i in range(8)]),
([[2, 1, 0]], [catalan(i) for i in range(8)]),
([[0, 1, 2], [0, 3, 2, 1]], [1, 1, 2, 5, 13, 34, 89, 233, 610]),
]
def test_to_standard():
def gen(perm):
res = list(perm)
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
res = list(perm)
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
def test_to_standard():
def gen(perm):
res = list(perm)
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
def test_to_standard():
def gen(perm):
res = list(perm)
add = 0
for i in perm.inverse():
add += random.randint(0, 10)
res[i] += add
return Perm(res)
perm = Perm.to_standard(x for x in range(10))
Perm.to_standard(x for x in range(3, 10))
for _ in range(100):
perm = Perm.random(random.randint(0, 20))
assert perm == Perm.to_standard(perm)
assert perm == Perm.to_standard(gen(perm))
assert Perm.to_standard("aaa") == Perm((0, 1, 2))
assert Perm.to_standard("cba") == Perm((2, 1, 0))
def last_sum_component(p):
"""
Return the last sum component of a permutation.
"""
n = len(p)
i = 1
comp = set([p[n - i]])
while comp != set(range(n - i, n)):
i += 1
comp.add(p[n - i])
return Perm.to_standard(p[n - i : n])