Ejemplo n.º 1
0
    def make_suit_edge(self,
                       start_point=None,
                       end_point=None,
                       zoneId=2000,
                       test=False):
        point1 = start_point or DNASuitPoint(1, DNASuitPoint.STREET_POINT,
                                             Point3(0, 0, 0))
        point2 = end_point or DNASuitPoint(2, DNASuitPoint.STREET_POINT,
                                           Point3(0, 0, 0))
        edge = DNASuitEdge(point1, point2, 2000)

        if test:
            point3 = DNASuitPoint(3, DNASuitPoint.STREET_POINT,
                                  Point3(0, 0, 0))

            self.assertEqual(edge.getStartPoint(), point1)
            edge.setStartPoint(point3)
            self.assertEqual(edge.getStartPoint(), point3)

            self.assertEqual(edge.getEndPoint(), point2)
            edge.setEndPoint(point1)
            self.assertEqual(edge.getEndPoint(), point1)

            self.assertEqual(edge.getZoneId(), 2000)
            edge.setZoneId(3000)
            self.assertEqual(edge.getZoneId(), 3000)

        edge.setStartPoint(point1)
        edge.setEndPoint(point2)
        edge.setZoneId(zoneId)
        return edge
    def test_vis_group(self):
        visgroup = DNAVisGroup('vg')

        # Test visibles
        self.assertEqual(visgroup.getNumVisibles(), 0)
        visgroup.addVisible('test1')
        visgroup.addVisible('test2')
        visgroup.addVisible('test3')
        self.assertEqual(visgroup.getNumVisibles(), 3)
        for i in xrange(1, 4):
            self.assertEqual(visgroup.getVisible(i - 1), 'test%d' % i)

        self.assertTrue(visgroup.removeVisible('test1'))
        self.assertTrue(visgroup.removeVisible('test2'))

        # Removing a visible which doesn't exist must return False
        self.assertFalse(visgroup.removeVisible('bad'))
        self.assertEqual(visgroup.getNumVisibles(), 1)
        self.assertEqual(visgroup.getVisible(0), 'test3')

        # Test suit edges
        edge1 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            1000)

        edge2 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            1000)

        edge3 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)),
                            1000)

        self.assertEqual(visgroup.getNumSuitEdges(), 0)
        visgroup.addSuitEdge(edge1)
        visgroup.addSuitEdge(edge2)
        self.assertEqual(visgroup.getNumSuitEdges(), 2)

        self.assertEqual(visgroup.getSuitEdge(0), edge1)
        self.assertEqual(visgroup.getSuitEdge(1), edge2)

        self.assertTrue(visgroup.removeSuitEdge(edge1))
        self.assertEqual(visgroup.getNumSuitEdges(), 1)
        self.assertEqual(visgroup.getSuitEdge(0), edge2)

        # Removing an edge which doesn't exist must return False
        self.assertFalse(visgroup.removeSuitEdge(edge3))

        # Test battle cells
        cell1 = DNABattleCell(20, 20, Point3(0, 0, 0))
        cell2 = DNABattleCell(20, 20, Point3(0, 0, 0))
        cell3 = DNABattleCell(20, 20, Point3(0, 0, 0))

        self.assertEqual(visgroup.getNumBattleCells(), 0)
        visgroup.addBattleCell(cell1)
        visgroup.addBattleCell(cell2)
        self.assertEqual(visgroup.getNumBattleCells(), 2)

        self.assertEqual(visgroup.getBattleCell(0), cell1)
        self.assertEqual(visgroup.getBattleCell(1), cell2)

        self.assertTrue(visgroup.removeBattleCell(cell1))
        self.assertEqual(visgroup.getNumBattleCells(), 1)
        self.assertEqual(visgroup.getBattleCell(0), cell2)

        # Removing a battle cell which doesn't exist must return False
        self.assertFalse(visgroup.removeBattleCell(cell3))
Ejemplo n.º 3
0
    def test_suit_points(self):
        store = DNAStorage()

        point1 = DNASuitPoint(5, DNASuitPoint.STREET_POINT,
                              Point3(100, 20, 0.5))
        point2 = DNASuitPoint(10, DNASuitPoint.STREET_POINT,
                              Point3(100, 0, 0.5))
        point3 = DNASuitPoint(15, DNASuitPoint.FRONT_DOOR_POINT,
                              Point3(100, -20, 0.5), 10)

        store.storeSuitPoint(point1)
        store.storeSuitPoint(point2)
        store.storeSuitPoint(point3)

        self.assertEqual(store.getNumSuitPoints(), 3)
        self.assertEqual(store.getSuitPointAtIndex(0), point1)
        self.assertEqual(store.getSuitPointAtIndex(1), point2)
        self.assertEqual(store.getSuitPointAtIndex(2), point3)
        self.assertEqual(store.getSuitPointWithIndex(5), point1)
        self.assertEqual(store.getSuitPointWithIndex(10), point2)
        self.assertEqual(store.getSuitPointWithIndex(15), point3)

        # Test invalid index
        self.assertEqual(store.getSuitPointWithIndex(1000), None)

        # Test suit edges
        edges = ((5, 10, 2301), (10, 15, 2302), (15, 5, 2303))

        for edge in edges:
            store.storeSuitEdge(*edge)

        for edge in edges:
            dna_edge = store.getSuitEdge(edge[0], edge[1])
            self.assertTrue(dna_edge is not None)
            self.assertEqual(dna_edge.getStartPoint(),
                             store.getSuitPointWithIndex(edge[0]))
            self.assertEqual(dna_edge.getEndPoint(),
                             store.getSuitPointWithIndex(edge[1]))
            self.assertEqual(dna_edge.getZoneId(), edge[2])
            self.assertEqual(store.getSuitEdgeZone(edge[0], edge[1]), edge[2])

        adj_points = store.getAdjacentPoints(point1)
        self.assertEqual(adj_points.getNumPoints(), 1)
        self.assertEqual(adj_points.getPoint(0), point2)
        self.assertEqual(store.getSuitEdgeTravelTime(5, 10, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(10, 15, 5), 4)
        self.assertEqual(store.getSuitEdgeTravelTime(15, 5, 5), 8)

        # Test suit path
        path = store.getSuitPath(point1, point3, 1, 10)
        self.assertEqual(path.getNumPoints(), 3)
        self.assertEqual(path.getPoint(0), point1)
        self.assertEqual(path.getPoint(1), point2)
        self.assertEqual(path.getPoint(2), point3)

        # Test invalid values
        store.storeSuitEdge(1, 2, 2800)
        self.assertEqual(store.getSuitEdge(1, 2), None)
        self.assertEqual(store.getSuitEdge(145, 13442), None)
        self.assertEqual(store.getSuitEdgeTravelTime(1, 2, 5), 0)
        self.assertEqual(repr(store.getSuitEdgeTravelTime(10, 15, 0)),
                         'inf')  # Division by 0

        point4 = DNASuitPoint(400, DNASuitPoint.STREET_POINT, Point3(0, 0, 0))
        self.assertEqual(store.getSuitPath(point4, point2, 1, 10), None)

        # Reset
        store.resetSuitPoints()
        self.assertEqual(store.getSuitPointWithIndex(5), None)
        self.assertEqual(store.getSuitPointWithIndex(10), None)
        self.assertEqual(store.getSuitPointWithIndex(15), None)
        self.assertTrue(store.discoverContinuity())
Ejemplo n.º 4
0
    def make_suit_point(self, index, type=DNASuitPoint.STREET_POINT, pos=(0, 0, 0), landmark_building_index=-1, test=False):
        point = DNASuitPoint(123, DNASuitPoint.STREET_POINT, Point3(10, -10, 0), 15)

        if test:
            self.assertEqual(point.getIndex(), 123)
            point.setIndex(1)
            self.assertEqual(point.getIndex(), 1)

            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)
            point.setPointType(DNASuitPoint.FRONT_DOOR_POINT)
            self.assertEqual(point.getPointType(), DNASuitPoint.FRONT_DOOR_POINT)
            point.setPointType('STREET_POINT')
            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)

            self.assertEqual(point.getPos(), Point3(10, -10, 0))
            point.setPos(Point3(150, 20, 0.5))
            self.assertEqual(point.getPos(), Point3(150, 20, 0.5))

            self.assertEqual(point.getLandmarkBuildingIndex(), 15)
            point.setLandmarkBuildingIndex(-1)
            self.assertEqual(point.getLandmarkBuildingIndex(), -1)

            # Test invalid point type (shouldn't change it all)
            point.setPointType('INVALID')
            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)

        point.setIndex(index)
        point.setPointType(type)
        point.setPos(pos)
        point.setLandmarkBuildingIndex(landmark_building_index)
        return point
Ejemplo n.º 5
0
    def make_suit_point(self,
                        index,
                        type=DNASuitPoint.STREET_POINT,
                        pos=(0, 0, 0),
                        landmark_building_index=-1,
                        test=False):
        point = DNASuitPoint(123, DNASuitPoint.STREET_POINT,
                             Point3(10, -10, 0), 15)

        if test:
            self.assertEqual(point.getIndex(), 123)
            point.setIndex(1)
            self.assertEqual(point.getIndex(), 1)

            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)
            point.setPointType(DNASuitPoint.FRONT_DOOR_POINT)
            self.assertEqual(point.getPointType(),
                             DNASuitPoint.FRONT_DOOR_POINT)
            point.setPointType('STREET_POINT')
            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)

            self.assertEqual(point.getPos(), Point3(10, -10, 0))
            point.setPos(Point3(150, 20, 0.5))
            self.assertEqual(point.getPos(), Point3(150, 20, 0.5))

            self.assertEqual(point.getLandmarkBuildingIndex(), 15)
            point.setLandmarkBuildingIndex(-1)
            self.assertEqual(point.getLandmarkBuildingIndex(), -1)

            # Test invalid point type (shouldn't change it all)
            point.setPointType('INVALID')
            self.assertEqual(point.getPointType(), DNASuitPoint.STREET_POINT)

        point.setIndex(index)
        point.setPointType(type)
        point.setPos(pos)
        point.setLandmarkBuildingIndex(landmark_building_index)
        return point