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_invalid_ops_with_mesh_patt():
with pytest.raises(NotImplementedError):
Av(MeshBasis(Perm((0, 1)))).is_finite()
with pytest.raises(NotImplementedError):
Av(MeshBasis(Perm((0, 1)))).is_insertion_encodable()
with pytest.raises(NotImplementedError):
Av(MeshBasis(Perm((0, 1)))).is_polynomial()
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_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):
assert perm.avoids(*mps)
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_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)
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(
*(
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)]),)
)
assert MeshBasis(
*(
MeshPatt(Perm((1, 2, 0)), [(0, 0), (0, 2), (1, 1), (1, 3), (2, 0), (2, 1)]),
def is_polynomial(self) -> bool:
"""Check if the perm class has polynomial growth."""
if isinstance(self.basis, MeshBasis):
raise NotImplementedError(Av._BASIS_ONLY_MSG)
return is_polynomial(self.basis)
def from_iterable(
cls, basis: Union[Iterable[Perm], Iterable[Union[Perm, MeshPatt]]]
) -> "Av":
"""Create a permutation class from a basis defined by an iterable of patterns.
"""
if MeshBasis.is_mesh_basis(basis):
return cls(MeshBasis(*basis))
return cls(Basis(*basis))
def from_iterable(
cls, basis: Union[Iterable[Perm], Iterable[Union[Perm, MeshPatt]]]
) -> "Av":
"""Create a permutation class from a basis defined by an iterable of patterns.
"""
if MeshBasis.is_mesh_basis(basis):
return cls(MeshBasis(*basis))
return cls(Basis(*basis))