]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/CensusTest.py
0789e2fe6b897357f359399aeb5cff2f32402f71
[dead/census-tools.git] / src / Tests / Unit / CensusTest.py
1 import unittest
2
3 import Census
4 import SummaryFile1
5 import Tests.Fixtures
6
7
8 class DatabaseTest(unittest.TestCase):
9
10 def setUp(self):
11 self.cdb = Census.Database()
12
13
14 def testEachBlockContainsItsOwnPopulation(self):
15 # These calculations are slightly off due to a discrepancy
16 # between the WKB/WKT format calculations. It would appear
17 # that converting from WKB to WKT and then back loses some
18 # information.
19 #
20 # The error is 1/100th of a person. Should be pretty safe.
21 error_threshold = 0.01
22
23 grp = SummaryFile1.GeoRecordParser()
24 fixtures_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt'
25 fixtures = grp.parse_blocks(fixtures_path)
26
27 for b in fixtures:
28 block_boundary = self.cdb.get_block_geometry_as_wkt(b.blkidfp00())
29 contained_population = self.cdb.find_contained_population(block_boundary)
30 error = abs(b.pop100 - contained_population)
31 self.assertTrue(error <= error_threshold)
32
33
34 def suite():
35 suite = unittest.TestSuite()
36 suite.addTest(unittest.makeSuite(DatabaseTest))
37 return suite
38