Esempio n. 1
0
    def expectNeighborhoodCoords(self, centerCoords, radius, dimensions,
                                 expected):
        centerIndex = indexFromCoordinates(centerCoords, dimensions)

        numIndices = 0

        for index, expectedIndex in zip(
                neighborhood(centerIndex, radius, dimensions), expected):
            numIndices += 1
            self.assertEqual(index,
                             indexFromCoordinates(expectedIndex, dimensions))

        self.assertEqual(numIndices, len(expected))
Esempio n. 2
0
    def testIndexFromCoordinates(self):
        self.assertEqual(0, indexFromCoordinates((0, ), (100, )))
        self.assertEqual(50, indexFromCoordinates((50, ), (100, )))
        self.assertEqual(99, indexFromCoordinates((99, ), (100, )))

        self.assertEqual(0, indexFromCoordinates((0, 0), (100, 80)))
        self.assertEqual(10, indexFromCoordinates((0, 10), (100, 80)))
        self.assertEqual(80, indexFromCoordinates((1, 0), (100, 80)))
        self.assertEqual(90, indexFromCoordinates((1, 10), (100, 80)))

        self.assertEqual(0, indexFromCoordinates((0, 0, 0), (100, 10, 8)))
        self.assertEqual(7, indexFromCoordinates((0, 0, 7), (100, 10, 8)))
        self.assertEqual(8, indexFromCoordinates((0, 1, 0), (100, 10, 8)))
        self.assertEqual(80, indexFromCoordinates((1, 0, 0), (100, 10, 8)))
        self.assertEqual(88, indexFromCoordinates((1, 1, 0), (100, 10, 8)))
        self.assertEqual(89, indexFromCoordinates((1, 1, 1), (100, 10, 8)))