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_valid_extension(self):
assert Rd2134CoreStrategy.is_valid_extension(Perm((0, 3, 4, 2, 1)))
assert not Rd2134CoreStrategy.is_valid_extension(Perm((0, 4, 3, 1, 2)))
assert Rd2134CoreStrategy.is_valid_extension(Perm((0, 1, 2, 3)))
assert not Rd2134CoreStrategy.is_valid_extension(Perm((0, 1, 2, 4, 3)))
def test_inverse():
for i in range(10):
assert Perm(range(i)) == Perm(range(i)).inverse()
assert Perm([2, 1, 3, 0]) == Perm([3, 1, 0, 2]).inverse()
assert Perm((1, 2, 5, 0, 3, 4)).inverse() == Perm((3, 0, 1, 4, 5, 2))
assert (
Perm([4, 3, 1, 6, 5, 7, 8, 0, 2]) == Perm([7, 2, 8, 1, 0, 4, 3, 5, 6]).inverse()
)
def test_flip_diagonal():
for i in range(10):
assert Perm(range(i)) == Perm(range(i)).flip_diagonal()
assert Perm([2, 1, 3, 0]) == Perm([3, 1, 0, 2]).flip_diagonal()
assert Perm((1, 2, 5, 0, 3, 4)).flip_diagonal() == Perm((3, 0, 1, 4, 5, 2))
assert (
Perm([4, 3, 1, 6, 5, 7, 8, 0, 2])
== Perm([7, 2, 8, 1, 0, 4, 3, 5, 6]).flip_diagonal()
)
def test_is_skew_decomposable():
p1 = Perm((0, 1, 3, 2))
p2 = Perm((0, 4, 2, 1, 3))
p3 = Perm((2, 0, 1))
p4 = Perm((0,))
p5 = Perm()
assert p1.skew_sum(p2).is_skew_decomposable()
assert p1.skew_sum(p2, p3).is_skew_decomposable()
assert p1.skew_sum(p2, p3, p4).is_skew_decomposable()
assert p2.skew_sum(p3, p4).is_skew_decomposable()
assert not p5.is_skew_decomposable()
assert not Perm((0, 1, 2, 3, 4)).is_skew_decomposable()
assert not Perm((0, 5, 4, 3, 2, 1)).is_skew_decomposable()
def test_insertion_encoding():
strat = InsertionEncodingStrategy([Perm((0, 1, 2)), Perm((2, 0, 1))])
assert strat.applies()
strat = InsertionEncodingStrategy([Perm((0, 2, 1, 3))])
assert not strat.applies()
def test_zero_plus_perm():
assert zero_plus_perm(Perm((0, 1, 2)))
assert not zero_plus_perm(Perm((3, 0, 1, 2)))
def test_ge():
# TODO: No length testing is done here
for _ in range(30):
l1 = list(range(10))
l2 = list(range(10))
random.shuffle(l1)
random.shuffle(l2)
if l1 >= l2:
assert Perm(l1) >= Perm(l2)
else:
assert not (Perm(l1) >= Perm(l2))
assert Perm(l1) >= Perm(l1)
assert Perm(l2) >= Perm(l2)
def test_generators():
assert list(Av(Basis(Perm((0, 1)), Perm((1, 0)))).first(500)) == [
Perm(),
Perm((0,)),
]
assert sorted(Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).of_length(3)) == sorted(
set(Perm.of_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))}
)
assert sorted(
Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).up_to_length(3)
) == sorted(set(Perm.up_to_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))})
from abc import abstractproperty, abstractstaticmethod
from typing import List
from permuta import Av, MeshPatt, Perm
from permuta.enumeration_strategies.abstract_strategy import (
EnumerationStrategyWithSymmetry,
)
R_U = Perm((1, 2, 0, 3))
C_U = Perm((2, 0, 1, 3))
R_D = Perm((1, 3, 0, 2))
C_D = Perm((2, 0, 3, 1))
# Abstract Core Strategy
class CoreStrategy(EnumerationStrategyWithSymmetry):
"""
Abstract class for a core related strategy.
"""
@abstractproperty
def patterns_needed(self):
"""
Return the set of patterns that are needed for the strategy to be
from .Avoiding import *
from permuta import Perm
from .CatalanAvoiding import CatalanAvoidingClass
class Avoiding210(AvoidingGeneric, CatalanAvoidingClass):
descriptor = Basis(Perm((2, 1, 0)))
def _ensure_level(self, level_number):
while len(self.cache) <= level_number:
new_level = set()
current_level_number = len(self.cache)
for perm in self.cache[-1]:
first_descent_location = next(perm.descents(), current_level_number-2)
for index in range(first_descent_location+2):
new_perm = perm.insert(index, 0)
new_level.add(new_perm)
self.cache.append(new_level)