def test_length_one_meshpatts_emptyness(self):
        for equivalent_shading in ([], [(0, 0)], [(1, 0)], [(0, 1), (1, 1)]):
            mp = MeshPatt(Perm((0,)), equivalent_shading)
            assert Cell(frozenset({mp}), frozenset()).is_empty()

        for nonequivalent_shading in ([(0, 0), (1, 1)], [(0, 1), (1, 0)]):
            mp = MeshPatt(Perm((0,)), nonequivalent_shading)
            assert not Cell(frozenset({mp}), frozenset()).is_empty()
 def setUp(self):
     self.mp_31c2 = MeshPatt(Perm((2, 0, 1)),
                             ((2, 0), (2, 1), (2, 2), (2, 3)))
     self.mp_cell = Cell(frozenset({self.mp_31c2}), frozenset())
     self.mixed_av_co_cell = Cell(
         frozenset({
             Perm((0, 2, 1)),
             MeshPatt(Perm((1, 0)), [(0, 0), (1, 1), (2, 2)])
         }),
         frozenset({Perm((0, 1))})
     )
 def test_make_tiling(self):
     tiling = self.sub_mt.tiling
     correct_tiling = [
         Cell(frozenset({self.mp_31c2}), frozenset()),
         MeshTiling.empty_cell,
         Cell(frozenset({self.mp_1c2}), frozenset()),
         MeshTiling.empty_cell,
         MeshTiling.point_cell,
         MeshTiling.empty_cell
     ]
     assert tiling == correct_tiling
    def setUp(self):
        self.p_312 = Perm((2, 0, 1))
        self.mp_31c2 = MeshPatt(self.p_312, ((2, 0), (2, 1), (2, 2), (2, 3)))
        self.mp_1c2 = self.mp_31c2.sub_mesh_pattern([1, 2])

        self.root_mp_cell = Cell(frozenset({self.mp_31c2}), frozenset())
        self.sub_mp_cell = Cell(frozenset({self.mp_1c2}), frozenset())

        self.empty_mt = MeshTiling()
        self.any_mt = MeshTiling({(0, 0): MeshTiling.anything_cell})
        self.root_mt = MeshTiling({
            (0, 0): self.root_mp_cell,
        })
        self.sub_mt = MeshTiling({
            (0, 0): self.root_mp_cell,
            (1, 1): MeshTiling.point_cell,
            (2, 0): self.sub_mp_cell,
        })
    def test_get_elmnts_of_size_Av21_cell(self):
        mt = MeshTiling({
            (0, 0): Cell(frozenset({Perm((1, 0))}), frozenset()),
            (1, 1): MeshTiling.point_cell
        })

        for size in range(1, 5):
            expected_perms = set(Av([Perm((1, 0))]).of_length(size))
            mt_perms = mt.get_elmnts(of_size=size)
            assert (len(set(mt_perms)) == len(list(mt_perms)))
            assert (set(mt_perms) == expected_perms)
class CellTest(unittest.TestCase):

    def setUp(self):
        self.mp_31c2 = MeshPatt(Perm((2, 0, 1)),
                                ((2, 0), (2, 1), (2, 2), (2, 3)))
        self.mp_cell = Cell(frozenset({self.mp_31c2}), frozenset())
        self.mixed_av_co_cell = Cell(
            frozenset({
                Perm((0, 2, 1)),
                MeshPatt(Perm((1, 0)), [(0, 0), (1, 1), (2, 2)])
            }),
            frozenset({Perm((0, 1))})
        )

    def test_empty_cell(self):
        assert (MeshTiling.empty_cell.is_empty())
        assert (not MeshTiling.point_cell.is_empty())
        assert (not MeshTiling.anything_cell.is_empty())

    def test_point_cell(self):
        assert (not MeshTiling.empty_cell.is_point())
        assert (MeshTiling.point_cell.is_point())
        assert (not MeshTiling.anything_cell.is_point())

    def test_anything_cell(self):
        assert (not MeshTiling.empty_cell.is_anything())
        assert (not MeshTiling.point_cell.is_anything())
        assert (MeshTiling.anything_cell.is_anything())

    def test_length_one_meshpatts_emptyness(self):
        for equivalent_shading in ([], [(0, 0)], [(1, 0)], [(0, 1), (1, 1)]):
            mp = MeshPatt(Perm((0,)), equivalent_shading)
            assert Cell(frozenset({mp}), frozenset()).is_empty()

        for nonequivalent_shading in ([(0, 0), (1, 1)], [(0, 1), (1, 0)]):
            mp = MeshPatt(Perm((0,)), nonequivalent_shading)
            assert not Cell(frozenset({mp}), frozenset()).is_empty()

    def test_repr(self):
        assert repr(MeshTiling.empty_cell) == " "
        assert repr(MeshTiling.point_cell) == "o"
        assert repr(MeshTiling.anything_cell) == "S"
        assert repr(self.mp_cell) == "Av({})".format(repr(self.mp_31c2))
        assert repr(self.mp_cell.flip()) == "Co({})".format(repr(self.mp_31c2))
        assert repr(self.mixed_av_co_cell) == "Av({}) and Co({})".format(
            ", ".join(repr(p) for p in Utils.sorted(
                self.mixed_av_co_cell.obstructions)),
            ", ".join(repr(p) for p in Utils.sorted(
                self.mixed_av_co_cell.requirements))
        )

    def test_str(self):
        assert str(MeshTiling.empty_cell) == " "
        assert str(MeshTiling.point_cell) == "o"
        assert str(MeshTiling.anything_cell) == "S"
        assert str(self.mp_cell) == (
            "     | |#|   \n"
            "    -2-+-+-  \n"
            "     | |#|   \n"
            "Av( -+-+-1- )\n"
            "     | |#|   \n"
            "    -+-0-+-  \n"
            "     | |#|   ")
        assert str(self.mp_cell.flip()) == (
            "     | |#|   \n"
            "    -2-+-+-  \n"
            "     | |#|   \n"
            "Co( -+-+-1- )\n"
            "     | |#|   \n"
            "    -+-0-+-  \n"
            "     | |#|   ")
        assert str(self.mixed_av_co_cell) == (
            "     | | |                           \n"
            "    -+-2-+-    | |#            | |   \n"
            "     | | |    -1-+-           -+-1-  \n"
            "Av( -+-+-1- ,  |#|  ) and Co(  | |  )\n"
            "     | | |    -+-0-           -0-+-  \n"
            "    -0-+-+-   #| |             | |   \n"
            "     | | |                           ")

    def test_flip(self):
        flipped_cell = Cell(frozenset(), frozenset({self.mp_31c2}))
        assert flipped_cell == self.mp_cell.flip()
        assert self.mp_cell == self.mp_cell.flip().flip()

    def test_get_permclass(self):
        for size in range(1, 5):
            expected_from_empty_cell = set()
            permclass_empty_cell = MeshTiling.empty_cell.get_permclass()
            assert isinstance(permclass_empty_cell, Av)
            assert set(permclass_empty_cell.of_length(
                size)) == expected_from_empty_cell

            expected_from_point_cell = {Perm((0,))} if size == 1 else set()
            permclass_point_cell = MeshTiling.point_cell.get_permclass()
            assert isinstance(permclass_point_cell, PermSet)
            assert set(permclass_point_cell.of_length(
                size)) == expected_from_point_cell

            expected_from_anything_cell = set(PermSet(size))
            permclass_anything_cell = MeshTiling.anything_cell.get_permclass()
            assert isinstance(permclass_anything_cell, PermSet)
            assert set(permclass_anything_cell.of_length(
                size)) == expected_from_anything_cell

        assert isinstance(self.mp_cell.get_permclass(), Av)
        assert isinstance(self.mixed_av_co_cell.get_permclass(), MockAvCoPatts)
 def test_invalid_obstruction(self):
     invalid_cell = Cell(frozenset({"not a mesh patt"}), frozenset())
     invalid_mt = MeshTiling({(0, 0): invalid_cell})
     with pytest.raises(ValueError):
         list(invalid_mt.get_subrules())
 def setUp(self) -> None:
     self.p = Perm((1, 0))
     self.mt = MeshTiling({(0, 0): Cell(frozenset({self.p}), frozenset())})
 def test_flip(self):
     flipped_cell = Cell(frozenset(), frozenset({self.mp_31c2}))
     assert flipped_cell == self.mp_cell.flip()
     assert self.mp_cell == self.mp_cell.flip().flip()