Beispiel #1
0
def test_contains():
    gp = GriddedPerm(
        Perm((0, 5, 1, 4, 2, 3, 6)),
        ((0, 0), (0, 1), (0, 0), (1, 1), (1, 1), (1, 1), (2, 2)),
    )
    assert gp.contains(GriddedPerm())
    assert all(gp.contains(GriddedPerm((0, ), (pos, ))) for pos in gp._cells)
    assert gp.contains(GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (2, 2))))
    assert gp.contains(GriddedPerm((2, 0, 1), ((1, 1), ) * 3))
    assert gp.contains(
        GriddedPerm((0, 2, 1), ((0, 0), ) * 3),
        GriddedPerm((0, 2, 1), ((1, 1), (1, 1), (2, 2))),
        GriddedPerm((1, 0, 2), ((1, 1), (1, 1), (2, 2))),
    )
    assert GriddedPerm().contains(GriddedPerm())
Beispiel #2
0
 def contains(self, gp: GriddedPerm, *patts: GriddedPerm) -> bool:
     """This is a an alternative containment check.
     It will return True if any element of patts is contained in gp, and add
     it to the known_patts. Only use this if it is worth caching, so in the
     usage case, if the check is related to the target gps requirement."""
     known_patts = self.known_patts[gp]
     if any(patt in known_patts for patt in patts):
         return True
     for patt in patts:
         if gp.contains(patt):
             known_patts.add(patt)
             return True
     return False
Beispiel #3
0
 def yielded_subgridded_perm(gp: GriddedPerm) -> bool:
     """Return True if a subgridded perm was yielded."""
     return gp.contains(*yielded)