X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTests%2FUnit%2FSummaryFile1Test.py;h=a72539b44b874c51e61bd359ce095f60bd29e19f;hb=cc8bf3b13b57668f8b83d814b496ceca496ced08;hp=edaf59859d91e1e89a5026ee959d1b4b38a87c6a;hpb=f6b26952ca47d6a3740ef244ce030e08be56679f;p=dead%2Fcensus-tools.git diff --git a/src/Tests/Unit/SummaryFile1Test.py b/src/Tests/Unit/SummaryFile1Test.py index edaf598..a72539b 100644 --- a/src/Tests/Unit/SummaryFile1Test.py +++ b/src/Tests/Unit/SummaryFile1Test.py @@ -1,9 +1,18 @@ -import Tests.Fixtures, SummaryFile1, GPS, unittest +import unittest + +import Tests.Fixtures +import SummaryFile1 +import GPS +import StringUtils class BlockTest(unittest.TestCase): - def testAverageDensityIsFloat(self): + def setUp(self): + self.grp = SummaryFile1.GeoRecordParser() + + + def testOneAverageDensityIsFloat(self): """ We want to make sure no float->integer truncation is taking place. @@ -28,7 +37,22 @@ class BlockTest(unittest.TestCase): # intepreted as a float. self.assertEqual(b.population_density(), 1.25) - + + + def testAllAverageDensitiesAreFloat(self): + """ + Test every GeoRecord in the Maryland file, and make sure + all of the average densities can be parsed as floats. + """ + + fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1' + blocks = self.grp.parse_blocks(fixture_path) + + for b in blocks: + self.assertTrue(StringUtils.is_float(b.population_density())) + + + class GeoRecordParserTest(unittest.TestCase): def setUp(self): @@ -54,57 +78,18 @@ class GeoRecordParserTest(unittest.TestCase): def testMdGeoRecordCount(self): fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1' records = self.grp.parse_file(fixture_path) - self.assertEqual(len(records), 98763) + self.assertEqual(len(records), 1000) def testMdGeoBlockCount(self): fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1' blocks = self.grp.parse_blocks(fixture_path) - self.assertEqual(len(blocks), 79128) - - -class SummaryFile1Test(unittest.TestCase): - - def testEachBlockIsClosestToItself(self): - blocks_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1' - grp = SummaryFile1.GeoRecordParser() - blocks = grp.parse_blocks(blocks_path) - - # Only test 100 of these guys (or however many blocks there - # are in those 100 records. - fixtures_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt' - fixtures = grp.parse_blocks(fixtures_path) - - for b in fixtures: - # It's probably unnecessary to copy the coordinates - # into a new instance here, but whatever. - b_coords = GPS.Coordinates() - b_coords.latitude = b.coordinates.latitude - b_coords.longitude = b.coordinates.longitude - - closest_block = SummaryFile1.FindClosestBlock(blocks, b_coords) - self.assertEqual(b.block, closest_block.block) - - - def testEachBlockHasItsOwnAverageDensity(self): - geo_file_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1' - - # Only test 5 of these guys; they take longer. - grp = SummaryFile1.GeoRecordParser() - fixtures_path = Tests.Fixtures.Path() + '/SummaryFile1/five_blocks.txt' - fixtures = grp.parse_blocks(fixtures_path) - - for b in fixtures: - # It's probably unnecessary to copy the coordinates - # into a new instance here, but whatever. - avg_density = SummaryFile1.FindAveragePopulationDensity(b.coordinates, geo_file_path) - self.assertEqual(b.population_density(), avg_density) - + self.assertEqual(len(blocks), 910) + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(GeoRecordParserTest)) - suite.addTest(unittest.makeSuite(SummaryFile1Test)) suite.addTest(unittest.makeSuite(BlockTest)) return suite