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_alternative_construction_methods():
assert (
Basis.from_string("123_321")
== Basis.from_iterable([Perm((0, 1, 2)), Perm((2, 1, 0))])
== Basis(Perm((0, 1, 2)), Perm((2, 1, 0)))
== Basis.from_string("012:210")
)
assert MeshBasis.from_iterable(
[MeshPatt(Perm((1, 2, 0)), [(0, 0), (0, 2), (1, 1), (1, 3), (2, 0), (2, 1)])]
) == MeshBasis(
MeshPatt(Perm((1, 2, 0)), [(0, 0), (0, 2), (1, 1), (1, 3), (2, 0), (2, 1)])
)
def test_meshbasis_of_perms():
p1 = Perm((0, 2, 1))
p2 = Perm((2, 0, 1))
assert MeshBasis(p1, p2) == MeshBasis(MeshPatt(p1, []), MeshPatt(p2, []))
shading = ((2, 0), (2, 1), (2, 2), (2, 3))
mp1 = MeshPatt(p1, shading)
mp2 = MeshPatt(p2, shading)
assert MeshBasis(p1, p2) == MeshBasis(p1, p2, mp1, mp2)
for elmnt in MeshBasis(p1, p2):
assert isinstance(elmnt, MeshPatt)
def test_avoiding_generic_mesh_patterns():
p = Perm((2, 0, 1))
shading = ((2, 0), (2, 1), (2, 2), (2, 3))
mps = [MeshPatt(p, shading)]
meshbasis = MeshBasis(*mps)
avoiding_generic_basis = Av(meshbasis)
enum = [1, 1, 2, 5, 15, 52, 203, 877] # Bell numbers
for (n, cnt) in enumerate(enum):
inst = avoiding_generic_basis.of_length(n)
gen = list(inst)
assert len(gen) == cnt
assert len(gen) == len(set(gen))
for perm in gen:
assert perm.avoids(*mps)
assert perm in avoiding_generic_basis
mx = len(enum) - 1
cnt = [0 for _ in range(mx + 1)]
for perm in Av(meshbasis).up_to_length(mx):
def test_av_meshpatt():
p = Perm((2, 0, 1))
shading = ((2, 0), (2, 1), (2, 2), (2, 3))
mp = MeshPatt(p, shading)
av = Av([mp])
enum = [1, 1, 2, 5, 15, 52, 203, 877] # Bell numbers
for (n, cnt) in enumerate(enum):
inst = av.of_length(n)
gen = list(inst)
assert len(gen) == cnt
def test_meshbasis():
assert MeshBasis(*[MeshPatt(), MeshPatt(Perm((0,)), ())]) == MeshBasis(MeshPatt())
assert MeshBasis(*[MeshPatt(), Perm()]) == MeshBasis(MeshPatt())
assert MeshBasis(*(Perm((1, 2, 0)), MeshPatt(Perm((1, 2, 0)), []))) == MeshBasis(
*(MeshPatt(Perm((1, 2, 0)), []),)
)
assert MeshBasis(
*(
Perm((1, 2, 0)),
MeshPatt(Perm((0, 2, 1)), [(0, 0), (0, 1), (1, 1), (2, 3), (3, 0), (3, 3)]),
)
) == MeshBasis(
*(
MeshPatt(Perm((0, 2, 1)), [(0, 0), (0, 1), (1, 1), (2, 3), (3, 0), (3, 3)]),
MeshPatt(Perm((1, 2, 0)), []),
)
)
assert MeshBasis(
def test_is_mesh_basis():
assert not MeshBasis.is_mesh_basis(())
assert not MeshBasis.is_mesh_basis([])
p1 = Perm((0, 2, 1))
p2 = Perm((2, 0, 1))
perm_list = [p1, p2]
assert not MeshBasis.is_mesh_basis(p1)
assert not MeshBasis.is_mesh_basis(p2)
assert not MeshBasis.is_mesh_basis(perm_list)
p1 = Perm((0, 2, 1))
p2 = Perm((2, 0, 1))
shading = ((2, 0), (2, 1), (2, 2), (2, 3))
mp1 = MeshPatt(p1, shading)
mp2 = MeshPatt(p2, shading)
meshpatt_list = [mp1, mp2]
mixed_patt_list = [p1, mp2]
assert MeshBasis.is_mesh_basis(mp1)
assert MeshBasis.is_mesh_basis(mp2)
assert MeshBasis.is_mesh_basis(meshpatt_list)
assert MeshBasis.is_mesh_basis(mixed_patt_list)
def test_enumeration():
assert (
Av.from_string("132").enumeration(8)
== Av(Basis(Perm((0, 2, 1)))).enumeration(8)
== [1, 1, 2, 5, 14, 42, 132, 429, 1430]
)
assert (
Av.from_string("Av(123,231)").enumeration(8)
== Av(Basis(Perm((0, 1, 2)), Perm((1, 2, 0)))).enumeration(8)
== [1, 1, 2, 4, 7, 11, 16, 22, 29]
)
assert Av(
(Perm((0, 1, 2)), MeshPatt(Perm((2, 0, 1)), [(0, 1), (1, 1), (2, 1), (3, 1)]))
).enumeration(7) == [1, 1, 2, 4, 8, 16, 32, 64]
assert (
Av.from_string("0123_2013_1023").enumeration(8)
== Av(
Basis(Perm((0, 1, 2, 3)), Perm((2, 0, 1, 3)), Perm((1, 0, 2, 3)))
).enumeration(8)
== [1, 1, 2, 6, 21, 79, 309, 1237, 5026]
)
assert (
Av.from_string("1243 1342 3241 3241").enumeration(8)
== Av(
Basis(
Perm((0, 1, 3, 2)),
Perm((0, 2, 3, 1)),
Perm((2, 1, 3, 0)),
Perm((2, 1, 3, 0)),
def is_valid_extension(patt):
mp = MeshPatt(
Perm((1, 0)), [(0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 1), (2, 2)]
)
last_comp = last_sum_component(fstrip(patt))
return (
patt[0] == 0
and fstrip(patt).avoids(mp)
and (last_comp not in Av([Perm((0, 1))]) or len(last_comp) == 1)
)