From 7782bdeec23285e875b0d153dfd31bdcd22d5f59 Mon Sep 17 00:00:00 2001 From: Stuart Lynn Date: Fri, 22 Apr 2016 16:10:41 -0400 Subject: [PATCH] adding tests fro new json returning get methods --- .../41_observatory_augmentation_test.out | 36 ++++++------- .../sql/41_observatory_augmentation_test.sql | 50 +++++++++++-------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out index 948b4b3..41bff69 100644 --- a/src/pg/test/expected/41_observatory_augmentation_test.out +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -41,34 +41,34 @@ Done. {female_pop,male_pop} | {} (1 row) - names | vals ---------------+---------- - {gini_index} | {0.3494} +obs_get_gini_index_at_test_point +---------------------------------- +t (1 row) - names | vals ---------------+------ - {gini_index} | {} +obs_get_gini_index_at_null_island +----------------------------------- +t (1 row) - _obs_getpoints --------------------- - {4809.33511352425} +obs_getpoints_for_test_point +------------------------------ +t (1 row) - _obs_getpoints ----------------- - +obs_getpoints_for_null_island +------------------------------- +t (1 row) - _obs_getpolygons --------------------- - {1570.72353789469} +obs_getpolygons_for_test_point +-------------------------------- +t (1 row) - _obs_getpolygons ------------------- - {NULL} +obs_getpolygons_for_null_island +--------------------------------- +t (1 row) segment_name | total_pop_quantile | male_pop_quantile | female_pop_quantile | median_age_quantile | white_pop_quantile | black_pop_quantile | asian_pop_quantile | hispanic_pop_quantile | not_us_citizen_pop_quantile | workers_16_and_over_quantile | commuters_by_car_truck_van_quantile | commuters_by_public_transportation_quantile | commuters_by_bus_quantile | commuters_by_subway_or_elevated_quantile | walked_to_work_quantile | worked_at_home_quantile | children_quantile | households_quantile | population_3_years_over_quantile | in_school_quantile | in_grades_1_to_4_quantile | in_grades_5_to_8_quantile | in_grades_9_to_12_quantile | in_undergrad_college_quantile | pop_25_years_over_quantile | high_school_diploma_quantile | bachelors_degree_quantile | masters_degree_quantile | pop_5_years_over_quantile | speak_only_english_at_home_quantile | speak_spanish_at_home_quantile | pop_determined_poverty_status_quantile | poverty_quantile | median_income_quantile | gini_index_quantile | income_per_capita_quantile | housing_units_quantile | vacant_housing_units_quantile | vacant_housing_units_for_rent_quantile | vacant_housing_units_for_sale_quantile | median_rent_quantile | percent_income_spent_on_rent_quantile | owner_occupied_housing_units_quantile | million_dollar_housing_units_quantile diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql index 1436597..5999383 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -41,42 +41,50 @@ FROM -- -----------|------- -- gini_index | 0.3494 -SELECT * FROM - cdb_observatory._OBS_Get( +WITH result as ( + SELECT _OBS_GetJSON::text as expected FROM + cdb_observatory._OBS_GetJSON( cdb_observatory._TestPoint(), Array['"us.census.acs".B19083001']::text[], '2009 - 2013', '"us.census.tiger".block_group' - ); + ) +) select expected = '{"value":0.3494,"name":"Gini Index","tablename":"obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb","aggregate":"","type":"Numeric","description":""}' + from result; -- gini index at null island -SELECT * FROM - cdb_observatory._OBS_Get( +WITH result as ( + SELECT count(_OBS_GetJSON) as expected FROM + cdb_observatory._OBS_GetJSON( CDB_LatLng(0, 0), Array['"us.census.acs".B19083001']::text[], '2009 - 2013', '"us.census.tiger".block_group' - ); - + ) +) select expected = 0 as OBS_Get_gini_index_at_null_island + from result; + -- OBS_GetPoints -- obs_getpoints -- -------------------- -- {4809.33511352425} SELECT - cdb_observatory._OBS_GetPoints( + (cdb_observatory._OBS_GetPoints( cdb_observatory._TestPoint(), 'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable - Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData] - ); - + (Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) + ))[1]::text = '{"value":4809.33511352425,"name":"Total Population","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' + as OBS_GetPoints_for_test_point; -- what happens at null island + SELECT - cdb_observatory._OBS_GetPoints( + (cdb_observatory._OBS_GetPoints( CDB_LatLng(0, 0), 'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable - Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData] - ); + (Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) + ))[1]::text is null + as OBS_GetPoints_for_null_island; -- OBS_GetPolygons -- obs_getpolygons @@ -84,19 +92,21 @@ SELECT -- {12996.8172420752} SELECT - cdb_observatory._OBS_GetPolygons( + (cdb_observatory._OBS_GetPolygons( cdb_observatory._TestArea(), 'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable - Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData] -); + Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json] +))[1]::text = '{"value":12996.8172420752,"name":"Total Population","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' + as OBS_GetPolygons_for_test_point; -- see what happens around null island SELECT - cdb_observatory._OBS_GetPolygons( + (cdb_observatory._OBS_GetPolygons( ST_Buffer(CDB_LatLng(0, 0)::geography, 500)::geometry, 'obs_a92e1111ad3177676471d66bb8036e6d057f271b'::text, -- see example in obs_geomtable - Array[('total_pop','obs_ab038198aaab3f3cb055758638ee4de28ad70146','sum')::cdb_observatory.OBS_ColumnData] -); + Array['{"colname":"total_pop","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) + )[1]->>'value' is null + as OBS_GetPolygons_for_null_island; SELECT * FROM cdb_observatory._OBS_GetSegmentSnapshot(