#NEWLINE# def test_tract_complex_merge( self ) : #NEWLINE# #INDENT# tract1 = self . geographies . find ( { #NEWLINE# #INDENT# 'geoid' : '15001021300' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( tract1 . count ( ) , 1 ) #NEWLINE# tract2 = self . geographies . find ( { #NEWLINE# #INDENT# 'geoid' : '15001021400' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( tract2 . count ( ) , 0 ) #NEWLINE# tract3 = self . geographies . find ( { #NEWLINE# #INDENT# 'geoid' : '15001021503' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( tract3 . count ( ) , 0 ) #NEWLINE# tract1_house_2000 = 2269 #NEWLINE# tract1_house_2000_pct = 0.0065 #NEWLINE# tract2_house_2000 = 1245 #NEWLINE# tract2_house_2000_pct = 0.9938 #NEWLINE# tract3_house_2000 = 2991 #NEWLINE# tract3_house_2000_pct = 0.0351 #NEWLINE# merged_house_2000 = int ( sum ( [ ( tract1_house_2000 * tract1_house_2000_pct ) , ( tract2_house_2000 * tract2_house_2000_pct ) , ( tract3_house_2000 * tract3_house_2000_pct ) ] ) ) #NEWLINE# merged_house_2010 = 1586 #NEWLINE# merged_house_delta = ( merged_house_2010 - merged_house_2000 ) #NEWLINE# merged_house_pct_change = ( float ( merged_house_delta ) / merged_house_2000 ) #NEWLINE# merged_tract = self . geographies . find ( { #NEWLINE# #INDENT# 'geoid' : '15001021402' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( merged_tract . count ( ) , 1 ) #NEWLINE# merged_tract = merged_tract [ 0 ] #NEWLINE# self . assertEqual ( len ( merged_tract [ 'xwalk' ] ) , 3 ) #NEWLINE# self . assertAlmostEqual ( merged_tract [ 'xwalk' ] [ '15001021300' ] [ 'HUPCT00' ] , tract1_house_2000_pct ) #NEWLINE# self . assertAlmostEqual ( merged_tract [ 'xwalk' ] [ '15001021400' ] [ 'HUPCT00' ] , tract2_house_2000_pct ) #NEWLINE# self . assertAlmostEqual ( merged_tract [ 'xwalk' ] [ '15001021503' ] [ 'HUPCT00' ] , tract3_house_2000_pct ) #NEWLINE# self . assertEqual ( float ( merged_tract [ 'data' ] [ '2000' ] [ 'H1' ] [ 'H001001' ] ) , merged_house_2000 ) #NEWLINE# self . assertEqual ( float ( merged_tract [ 'data' ] [ '2010' ] [ 'H1' ] [ 'H001001' ] ) , merged_house_2010 ) #NEWLINE# self . assertEqual ( float ( merged_tract [ 'data' ] [ 'delta' ] [ 'H1' ] [ 'H001001' ] ) , merged_house_delta ) #NEWLINE# self . assertAlmostEqual ( float ( merged_tract [ 'data' ] [ 'pct_change' ] [ 'H1' ] [ 'H001001' ] ) , merged_house_pct_change )