Пример #1
0
    def test_points(self):
        """Test points operations"""

        # tested block should act as set, so create a reference set and compare contents
        ref_set = set()

        with self.subTest("empty"):
            self.assertEqual(self.b.points, ref_set)

        with self.subTest("adding one point"):
            self.b.add(UTFGridPoint(3, 4))
            ref_set.add(UTFGridPoint(3, 4))
            self.assertEqual(self.b.points, ref_set)

        with self.subTest("adding one point with automatic wrapping"):
            self.b.add((30, 40))
            ref_set.add(UTFGridPoint(30, 40))
            self.assertEqual(self.b.points, ref_set)

        with self.subTest("setting multiple points at once"):
            points = (0, 0), (1, 2), (3, 4), (1, 2), (5, 6)
            self.b.points = points
            ref_set = {UTFGridPoint(*p) for p in points}
            self.assertEqual(self.b.points, ref_set)

        with self.subTest("adding multiple points by update"):
            points = (0, 0), (10, 20), (30, 40), (10, 20), (50, 60)
            self.b.update(points)
            ref_set.update({UTFGridPoint(*p) for p in points})
            self.assertEqual(self.b.points, ref_set)
Пример #2
0
class TestBlock(unittest.TestCase):

    # {descriptor: [points, midpoint, x_lim, y_lim]}
    good_cases = {
        9: [[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2),
             (3, 3)],
            UTFGridPoint(2.0, 2.0), (1, 3), (1, 3)],
        6: [[(1, 0), (1, 1), (2, 0), (2, 1), (3, 0), (3, 1)],
            UTFGridPoint(2.0, 0.0), (1, 3), (-1, 1)],
        4: [[(62, 62), (62, 63), (63, 62), (63, 63)],
            UTFGridPoint(63.0, 63.0), (62, 64), (62, 64)],
        3: [[(63, 30), (63, 31), (63, 32)],
            UTFGridPoint(64.0, 31.0), (63, 65), (30, 32)],
        2: [[(62, 0), (63, 0)],
            UTFGridPoint(63.0, -1.0), (62, 64), (-2, 0)],
        1: [[
            (0, 63),
        ], UTFGridPoint(-1.0, 64.0), (-2, 0), (63, 65)],
    }
    bad_cases = {
        "too much points": [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3),
                            (3, 1), (3, 2), (3, 3), (3, 4)],
        "still too much points": [(63, 30), (63, 31), (63, 32), (63, 33)],
        "point missing: 9": [(1, 1), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1),
                             (3, 2), (3, 3)],
        "point missing: 6": [(1, 0), (1, 1), (2, 0), (3, 0), (3, 1)],
        "points not aligned": [(1, 1), (1, 2), (1, 3), (2, 1), (2, 3), (2, 4),
                               (3, 1), (3, 2), (3, 3)],
    }

    def setUp(self):
        self.b = Block()
        Block.instances = []

    def _generate_blocks(self, case, num=100):
Пример #3
0
def make_tile(x, y, z, a=0, b=0, size=256):
    t = Tile(None, x, y, z)
    t.size = size
    return t, UTFGridPoint(a, b)