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_is_subclass():
av1 = AvoidingGeneric((Perm((0,)),))
av12_21 = AvoidingGeneric((Perm((0, 1)), Perm((1, 0))))
av123 = AvoidingGeneric((Perm((0, 1, 2)),))
av1234 = AvoidingGeneric((Perm((0, 1, 2, 3)),))
assert av1.is_subclass(av123)
assert not av123.is_subclass(av1)
assert av123.is_subclass(av1234)
assert not av1234.is_subclass(av12_21)
assert av12_21.is_subclass(av1234)
assert av123.is_subclass(av123)
av1324_1423_12345 = AvoidingGeneric(
(Perm((0, 2, 1, 3)), Perm((0, 3, 1, 2)), Perm((0, 1, 2, 3, 4, 5)))
)
av1324_1234 = AvoidingGeneric((Perm((0, 2, 1, 3)), Perm((0, 1, 2, 3))))
av1234_132 = AvoidingGeneric((Perm((0, 1, 2, 3)), Perm((0, 2, 1))))
assert av123.is_subclass(av1324_1423_12345)
assert not av1324_1234.is_subclass(av1324_1423_12345)
def test_iter_getitem_same_principal_classes():
maximum = 100
for length in range(3, 5):
for patt in PermSet(length):
basis = Basis(patt)
avoiders = AvoidingGeneric(basis)
for index, perm in enumerate(avoiders):
assert perm == avoiders[index]
if index > maximum:
break
def test_avoiding_enumeration(patts, enum):
patts = [Perm(patt) for patt in patts]
basis = Basis(patts)
for (n, cnt) in enumerate(enum):
# print(n, cnt)
inst = AvoidingGeneric(basis).of_length(n)
gen = list(inst)
# assert len(gen) == cnt
assert len(gen) == len(set(gen))
for perm in gen:
assert perm.avoids(*patts)
mx = len(enum) - 1
cnt = [0 for _ in range(mx + 1)]
for perm in AvoidingGeneric(basis):
if len(perm) > mx:
break
assert perm.avoids(*patts)
cnt[len(perm)] += 1
assert enum == cnt
]
for (patts, enum) in ts:
patts = [Perm(patt) for patt in patts]
basis = Basis(patts)
for (n, cnt) in enumerate(enum):
inst = AvoidingGeneric(basis).of_length(n)
gen = list(inst)
assert len(gen) == cnt
assert len(gen) == len(set(gen))
for perm in gen:
assert perm.avoids(*patts)
mx = len(enum) - 1
cnt = [0 for _ in range(mx + 1)]
for perm in AvoidingGeneric(basis):
if len(perm) > mx:
break
assert perm.avoids(*patts)
cnt[len(perm)] += 1
assert enum == cnt
def test_avoiding_enumeration(patts, enum):
patts = [Perm(patt) for patt in patts]
basis = Basis(patts)
for (n, cnt) in enumerate(enum):
# print(n, cnt)
inst = AvoidingGeneric(basis).of_length(n)
gen = list(inst)
# assert len(gen) == cnt
assert len(gen) == len(set(gen))
for perm in gen:
assert perm.avoids(*patts)
mx = len(enum) - 1
cnt = [0 for _ in range(mx + 1)]
for perm in AvoidingGeneric(basis):
if len(perm) > mx:
break
assert perm.avoids(*patts)
cnt[len(perm)] += 1
assert enum == cnt
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 = AvoidingGeneric(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
for mp in mps:
with pytest.raises(TypeError):
mp in avoiding_generic_basis
mx = len(enum) - 1
def test_is_subclass():
av1 = AvoidingGeneric((Perm((0,)),))
av12_21 = AvoidingGeneric((Perm((0, 1)), Perm((1, 0))))
av123 = AvoidingGeneric((Perm((0, 1, 2)),))
av1234 = AvoidingGeneric((Perm((0, 1, 2, 3)),))
assert av1.is_subclass(av123)
assert not av123.is_subclass(av1)
assert av123.is_subclass(av1234)
assert not av1234.is_subclass(av12_21)
assert av12_21.is_subclass(av1234)
assert av123.is_subclass(av123)
av1324_1423_12345 = AvoidingGeneric(
(Perm((0, 2, 1, 3)), Perm((0, 3, 1, 2)), Perm((0, 1, 2, 3, 4, 5)))
)
av1324_1234 = AvoidingGeneric((Perm((0, 2, 1, 3)), Perm((0, 1, 2, 3))))
av1234_132 = AvoidingGeneric((Perm((0, 1, 2, 3)), Perm((0, 2, 1))))
assert av123.is_subclass(av1324_1423_12345)
assert not av1324_1234.is_subclass(av1324_1423_12345)
assert av1234_132.is_subclass(av1324_1423_12345)
def test_is_subclass():
av1 = AvoidingGeneric((Perm((0,)),))
av12_21 = AvoidingGeneric((Perm((0, 1)), Perm((1, 0))))
av123 = AvoidingGeneric((Perm((0, 1, 2)),))
av1234 = AvoidingGeneric((Perm((0, 1, 2, 3)),))
assert av1.is_subclass(av123)
assert not av123.is_subclass(av1)
assert av123.is_subclass(av1234)
assert not av1234.is_subclass(av12_21)
assert av12_21.is_subclass(av1234)
assert av123.is_subclass(av123)
av1324_1423_12345 = AvoidingGeneric(
(Perm((0, 2, 1, 3)), Perm((0, 3, 1, 2)), Perm((0, 1, 2, 3, 4, 5)))
)
av1324_1234 = AvoidingGeneric((Perm((0, 2, 1, 3)), Perm((0, 1, 2, 3))))
av1234_132 = AvoidingGeneric((Perm((0, 1, 2, 3)), Perm((0, 2, 1))))
assert av123.is_subclass(av1324_1423_12345)
assert not av1324_1234.is_subclass(av1324_1423_12345)
assert av1234_132.is_subclass(av1324_1423_12345)
def test_avoiding_generic_finite_class():
ts = [
([[0]], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
([[0, 1], [3, 2, 1, 0]], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]),
([[0, 1, 2], [3, 2, 1, 0]], [1, 1, 2, 5, 13, 25, 25, 0, 0, 0, 0, 0]),
]
for (patts, enum) in ts:
patts = [Perm(patt) for patt in patts]
basis = Basis(patts)
for (n, cnt) in enumerate(enum):
inst = AvoidingGeneric(basis).of_length(n)
gen = list(inst)
assert len(gen) == cnt
assert len(gen) == len(set(gen))
for perm in gen:
assert perm.avoids(*patts)
mx = len(enum) - 1
cnt = [0 for _ in range(mx + 1)]
for perm in AvoidingGeneric(basis):
if len(perm) > mx:
break
assert perm.avoids(*patts)
cnt[len(perm)] += 1
assert enum == cnt
def test_is_subclass():
av1 = AvoidingGeneric((Perm((0,)),))
av12_21 = AvoidingGeneric((Perm((0, 1)), Perm((1, 0))))
av123 = AvoidingGeneric((Perm((0, 1, 2)),))
av1234 = AvoidingGeneric((Perm((0, 1, 2, 3)),))
assert av1.is_subclass(av123)
assert not av123.is_subclass(av1)
assert av123.is_subclass(av1234)
assert not av1234.is_subclass(av12_21)
assert av12_21.is_subclass(av1234)
assert av123.is_subclass(av123)
av1324_1423_12345 = AvoidingGeneric(
(Perm((0, 2, 1, 3)), Perm((0, 3, 1, 2)), Perm((0, 1, 2, 3, 4, 5)))
)
av1324_1234 = AvoidingGeneric((Perm((0, 2, 1, 3)), Perm((0, 1, 2, 3))))
av1234_132 = AvoidingGeneric((Perm((0, 1, 2, 3)), Perm((0, 2, 1))))
assert av123.is_subclass(av1324_1423_12345)
assert not av1324_1234.is_subclass(av1324_1423_12345)
assert av1234_132.is_subclass(av1324_1423_12345)