示例#1
0
    def test_getGraphSplits_HourglassShape(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-HourglassShape.redistdata')

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits), 4)
 def test_isPolygonAnHourglass_HourglassThumbShape(self):
     candidateDistrictShapeFilePath = os.path.join(
         os.path.dirname(__file__),
         'testData/HourglassThumbDistrictSplit-ReferenceDistrictCandidateShapes.redistdata'
     )
     candidateDistrictShapes = loadDataFromFile(
         filePath=candidateDistrictShapeFilePath)
     self.assertFalse(isPolygonAnHourglass(candidateDistrictShapes[0]))
     self.assertTrue(isPolygonAnHourglass(candidateDistrictShapes[1]))
示例#3
0
    def test_getGraphSplits_WeirdSplitThatCanProduceOrphans(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-WeirdSplitWithOrphans.redistdata'
        )

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits), 4)
示例#4
0
    def test_getGraphSplits_TooSmallToBreak(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-TooSmallToSplit.redistdata')

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits),
                         len(testRedistrictingGroup.children))
示例#5
0
    def test_getGraphSplits_BlockCanNotFindPreviousNeighborBecauseCutOff(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-BlockCanNotFindPreviousNeighborBecauseCutOff.redistdata'
        )

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits), 4)
 def test_isPolygonAnHourglass_TopOfMichiganLowerPeninsula(self):
     candidatesShapeFilePath = os.path.join(
         os.path.dirname(__file__),
         'testData/UPDistrictSplit-ReferenceDistrictCandidatePolygons.redistdata'
     )
     candidateShapes = loadDataFromFile(filePath=candidatesShapeFilePath)
     candidateWithUP = candidateShapes[0]
     polygonsInCandidateWithUP = list(candidateWithUP)
     lowerPortionOfCandidate = polygonsInCandidateWithUP[3]
     self.assertFalse(isPolygonAnHourglass(lowerPortionOfCandidate))
示例#7
0
    def test_getGraphSplits_CouldNotFindRepresentativeBlock(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-CouldNotFindRepresentativeBlock.redistdata'
        )

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits), 11)
    def test_isPolygonAGoodDistrictShape_TopOfMichiganLowerPeninsula(self):
        candidatesShapeFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/UPDistrictSplit-ReferenceDistrictCandidatePolygons.redistdata'
        )
        candidateShapes = loadDataFromFile(filePath=candidatesShapeFilePath)
        upperCandidate = candidateShapes[0]
        lowerCandidate = candidateShapes[1]

        parentShapeFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/UPDistrictSplit-ReferenceParentShape.redistdata')
        parentShape = loadDataFromFile(filePath=parentShapeFilePath)

        self.assertTrue(
            isPolygonAGoodDistrictShape(districtPolygon=upperCandidate,
                                        parentPolygon=parentShape))
        self.assertTrue(
            isPolygonAGoodDistrictShape(districtPolygon=lowerCandidate,
                                        parentPolygon=parentShape))
    def test_isPolygonAGoodDistrictShape_HourglassThumbShape(self):
        candidatesShapeFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/HourglassThumbDistrictSplit-ReferenceDistrictCandidateShapes.redistdata'
        )
        candidateShapes = loadDataFromFile(filePath=candidatesShapeFilePath)
        upperCandidate = candidateShapes[0]
        lowerCandidate = candidateShapes[1]

        parentShapeFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/HourglassThumbDistrictSplit-ReferenceParentShape.redistdata'
        )
        parentShape = loadDataFromFile(filePath=parentShapeFilePath)

        self.assertTrue(
            isPolygonAGoodDistrictShape(districtPolygon=upperCandidate,
                                        parentPolygon=parentShape))
        self.assertFalse(
            isPolygonAGoodDistrictShape(districtPolygon=lowerCandidate,
                                        parentPolygon=parentShape))
 def test_getPopulationEnergyPolygonSplit_GeometryCollectionAfterSplit(
         self):
     testDataFilePath = os.path.join(
         os.path.dirname(__file__),
         'testData/RedistrictingGroup-ErrorCase-TooSmallToSplit.redistdata')
     testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
     testRedistrictingGroup.fillPopulationEnergyGraph(Alignment.northSouth)
     northSouthSplitResult = testRedistrictingGroup.getPopulationEnergySplit(
         Alignment.northSouth)
     northSouthSplitResultType = northSouthSplitResult[0]
     self.assertEqual(northSouthSplitResultType,
                      SplitType.ForceSplitAllBlocks)
示例#11
0
    def test_getGraphSplits_NormalSplitCausesIsolatedBlockInfo(self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-NormalSplitCausesIsolatedBlockInfo.redistdata'
        )

        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        graphSplits = testRedistrictingGroup.getGraphSplits()

        self.assertEqual(len(graphSplits), 4)
        for graphSplit in graphSplits:
            self.assertEqual(type(graphSplit.geometry), Polygon)
    def test_attachOrphanRedistrictingGroupsToClosestNeighbor_ThreeRegions(
            self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/2010-Michigan-KeweenawAndTheThumbRedistrictingGroupInfoHasOrphans.redistdata'
        )
        testData = loadDataFromFile(filePath=testDataFilePath)
        contiguousRegions = findContiguousGroupsOfGraphObjects(testData)
        self.assertEqual(len(contiguousRegions), 3)

        assignNeighboringRedistrictingGroupsForRedistrictingGroups(testData)
        contiguousRegions = findContiguousGroupsOfGraphObjects(testData)
        self.assertEqual(len(contiguousRegions), 1)
 def test_getPopulationEnergyPolygonSplit_SeamInCornerOfGroup(self):
     testDataFilePath = os.path.join(
         os.path.dirname(__file__),
         'testData/RedistrictingGroup-ErrorCase-SeamInCornerOfGroup.redistdata'
     )
     testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
     testRedistrictingGroup.fillPopulationEnergyGraph(Alignment.westEast)
     westEastSplitResult = testRedistrictingGroup.getPopulationEnergySplit(
         Alignment.westEast)
     westEastSplitResultType = westEastSplitResult[0]
     westEastSplit = westEastSplitResult[1]
     self.assertEqual(westEastSplitResultType, SplitType.NormalSplit)
     self.assertTrue(len(westEastSplit[0]) > 0)
     self.assertTrue(len(westEastSplit[1]) > 0)
 def test_getPopulationEnergyPolygonSplit_CentroidNotWithinPolygon(self):
     testDataFilePath = os.path.join(
         os.path.dirname(__file__),
         'testData/RedistrictingGroup-ErrorCase-CentroidNotWithinPolygon.redistdata'
     )
     testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
     testRedistrictingGroup.fillPopulationEnergyGraph(Alignment.northSouth)
     northSouthSplitResult = testRedistrictingGroup.getPopulationEnergySplit(
         Alignment.northSouth)
     northSouthSplitResultType = northSouthSplitResult[0]
     northSouthSplit = northSouthSplitResult[1]
     self.assertEqual(northSouthSplitResultType, SplitType.NormalSplit)
     self.assertTrue(len(northSouthSplit[0]) > 0)
     self.assertTrue(len(northSouthSplit[1]) > 0)
    def test_getPopulationEnergyPolygonSplit_MissingWesternAndEasternChildBlocks(
            self):
        testDataFilePath = os.path.join(
            os.path.dirname(__file__),
            'testData/RedistrictingGroup-ErrorCase-NoWesternOrEasternChildren.redistdata'
        )
        testRedistrictingGroup = loadDataFromFile(filePath=testDataFilePath)
        testRedistrictingGroup.fillPopulationEnergyGraph(Alignment.northSouth)
        northSouthSplitResult = testRedistrictingGroup.getPopulationEnergySplit(
            Alignment.northSouth)
        northSouthSplitResultType = northSouthSplitResult[0]
        northSouthSplit = northSouthSplitResult[1]
        self.assertEqual(northSouthSplitResultType, SplitType.NoSplit)
        self.assertEqual(northSouthSplit, None)

        testRedistrictingGroup.fillPopulationEnergyGraph(Alignment.westEast)
        westEastSplitResult = testRedistrictingGroup.getPopulationEnergySplit(
            Alignment.westEast)
        westEastSplitResultType = westEastSplitResult[0]
        westEastSplit = westEastSplitResult[1]
        self.assertEqual(westEastSplitResultType, SplitType.NormalSplit)
        self.assertTrue(len(westEastSplit[0]) > 0)
        self.assertTrue(len(westEastSplit[1]) > 0)
示例#16
0
 def setUpClass(cls):
     testDataFilePath = os.path\
         .join(os.path.dirname(__file__),
               'testData/2010-Michigan-CandidateRedistrictingGroupInfoNoAtomicBlocks.redistdata')
     cls._stateData = loadDataFromFile(filePath=testDataFilePath)
示例#17
0
 def test_splitNonContiguousRedistrictingGroups_NeedsASplitWithLargeNumberOfBlocks(self):
     testDataFilePath = os.path.join(os.path.dirname(__file__),
                                     'testData/2010-Michigan-CharlevoixRedistrictingGroupInfoNeedsSplit.redistdata')
     testData = loadDataFromFile(filePath=testDataFilePath)
     splitNonContiguousRedistrictingGroups(testData)
     self.assertEqual(len(testData), 2)