示例#1
0
 def test_isvalid(self):
     fg = FatgraphB([
         (1, 2, 3, 4),
     ], [(1, 2), (3, 4)], [(1, 4), (2, 3)])
     assert fg.isvalid()
     fg._is = Permutation.from_cycles((1, 2), (3, 4))
     assert not fg.isvalid()
     fgb = FatgraphB([
         tuple(range(1, 9)),
     ], [(1, 8), (2, 3), (4, 7), (5, 6)], [(2, 7), (3, 6), (4, 5), (1, 8)])
     assert not fgb.isvalid()
     fgb = FatgraphB([(1, 2, 3, 4), (5, 6, 7, 8)], [(1, 8), (2, 7), (3, 5),
                                                    (4, 6)],
                     [(1, 2), (3, 4), (5, 6), (7, 8)])
     assert not fgb.isvalid()
     fgb._is = Permutation.from_cycles((1, 4), (2, 3), (5, 6), (7, 8))
     assert fgb.isvalid()
     fg = FatgraphB([
         (1, 2, 3, 4, 5, 6),
     ], [(3, 6), (4, 5)], [(1, 4), (2, 3), (5, 6)])
     assert fg.isvalid()
     fg = FatgraphB([
         (1, 2, 3, 4, 5, 6),
     ], [(3, 6), (4, 5)], [(1, 2), (6, 3), (5, 4)])
     assert not fg.isvalid()
     fg = FatgraphB([
         (1, 2, 3, 4, 5, 6),
     ], [(1, 4), (3, 5)], [(1, 6), (2, 5), (3, 4)])
     assert fg.isvalid()
示例#2
0
 def __init__(self, vertices, edges):
     # Check the arguments define a valid fatgraph
     self.checkvalidity(vertices, edges)
     self.vertices = vertices
     self.edges = edges
     self._vs = Permutation.from_cycles(*vertices)
     self._es = Permutation.from_cycles(*edges)
     vs = [i for j in vertices for i in j]
     es = [i for j in edges for i in j]
     self.unpaired = set(vs) - set(es)
示例#3
0
    def test_permutation_sign(self):
        tests = [(([(0, )], 1), 1), (([(0, 1), (2, 3)], 4), 1),
                 (([(0, 1)], 4), -1), (([(0, 1), (1, 2)], 4), 1),
                 (([(0, 1), (2, 3), (4, 5)], 6), -1)]

        for test in tests:
            cycles = test[0][0]
            dim = test[0][1]
            expected = test[1]
            self.assertEqual(
                Permutation.from_cycles(cycles, dim).sign(), expected)
示例#4
0
    def test_construction_from_cycles(self):
        tests = [(([(0, )], 1), [0]), (([(0, 1), (2, 3)], 4), [1, 0, 3, 2]),
                 (([(0, 1)], 4), [1, 0, 2, 3]),
                 (([(0, 1), (1, 2)], 4), [1, 2, 0, 3]),
                 (([(0, 1), (2, 3), (4, 5)], 6), [1, 0, 3, 2, 5, 4]),
                 (([(0, 1, 2), (2, 3)], 4), [1, 2, 3, 0])]

        for test in tests:
            cycles = test[0][0]
            dim = test[0][1]
            expected = test[1]
            self.assertEqual(Permutation.from_cycles(cycles, dim),
                             Permutation.from_list(expected))
示例#5
0
 def __init__(self, vertices, edges, interiors):
     self._is = Permutation.from_cycles(*interiors)
     super().__init__(vertices, edges)
示例#6
0
import pytest
from six.moves import zip_longest
from permutation import Permutation

S4 = [
    Permutation(),
    Permutation.from_cycles((1, 2)),
    Permutation.from_cycles((2, 3)),
    Permutation.from_cycles((1, 3, 2)),
    Permutation.from_cycles((1, 2, 3)),
    Permutation.from_cycles((1, 3)),
    Permutation.from_cycles((3, 4)),
    Permutation.from_cycles((1, 2), (3, 4)),
    Permutation.from_cycles((2, 4, 3)),
    Permutation.from_cycles((1, 4, 3, 2)),
    Permutation.from_cycles((1, 2, 4, 3)),
    Permutation.from_cycles((1, 4, 3)),
    Permutation.from_cycles((2, 3, 4)),
    Permutation.from_cycles((1, 3, 4, 2)),
    Permutation.from_cycles((2, 4)),
    Permutation.from_cycles((1, 4, 2)),
    Permutation.from_cycles((1, 3), (2, 4)),
    Permutation.from_cycles((1, 4, 2, 3)),
    Permutation.from_cycles((1, 2, 3, 4)),
    Permutation.from_cycles((1, 3, 4)),
    Permutation.from_cycles((1, 2, 4)),
    Permutation.from_cycles((1, 4)),
    Permutation.from_cycles((1, 3, 2, 4)),
    Permutation.from_cycles((1, 4), (2, 3)),
]
示例#7
0
def test_from_cycles(p, cycles):
    assert Permutation.from_cycles(*cycles) == p
示例#8
0
 def test_cycle_decomposition(self):
     for p in permutations(5):
         cycle_list = p.as_cycles()
         self.assertEqual(Permutation.from_cycles(cycle_list, 5), p)
示例#9
0
import pytest
from permutation import Permutation

EQUIV_CLASSES = [
    [
        Permutation(),
        Permutation(1),
        Permutation(1, 2),
        Permutation(1, 2, 3, 4, 5),
        Permutation.cycle(),
        Permutation.from_cycles(),
        Permutation.from_cycles(()),
    ],
    [
        Permutation(2, 1),
        Permutation(2, 1, 3, 4, 5),
        Permutation.cycle(1, 2),
        Permutation.cycle(2, 1),
        Permutation.from_cycles((1, 2)),
        Permutation.from_cycles((2, 1)),
    ],
    [
        Permutation(2, 3, 1),
        Permutation(2, 3, 1, 4, 5),
        Permutation.cycle(1, 2, 3),
        Permutation.cycle(2, 3, 1),
        Permutation.cycle(3, 1, 2),
        Permutation.from_cycles((1, 2, 3)),
        Permutation.from_cycles((2, 3, 1)),
        Permutation.from_cycles((3, 1, 2)),
    ],
示例#10
0
def test_bad_from_cycles(cycles):
    with pytest.raises(ValueError):
        Permutation.from_cycles(*cycles)