From b715364a1665d16db6239d3ab9f8c3ed45adf784 Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Mon, 22 Jul 2024 22:51:07 +0530 Subject: [PATCH 1/9] [centrality] changed floydWarshall to betweennessCentrality --- pgtap/metrics/types_check.pg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pgtap/metrics/types_check.pg b/pgtap/metrics/types_check.pg index 3b180fd146..9a8893588c 100644 --- a/pgtap/metrics/types_check.pg +++ b/pgtap/metrics/types_check.pg @@ -21,18 +21,18 @@ BEGIN; SELECT plan(5); -SELECT has_function('pgr_floydwarshall'); -SELECT has_function('pgr_floydwarshall', ARRAY['text','boolean']); -SELECT function_returns('pgr_floydwarshall', ARRAY['text','boolean'],'setof record'); +SELECT has_function('pgr_betweennesscentrality'); +SELECT has_function('pgr_betweennesscentrality', ARRAY['text','boolean']); +SELECT function_returns('pgr_betweennesscentrality', ARRAY['text','boolean'],'setof record'); SELECT set_eq( - $$SELECT proargnames from pg_proc where proname = 'pgr_floydwarshall'$$, + $$SELECT proargnames from pg_proc where proname = 'pgr_betweennesscentrality'$$, $$VALUES ('{"","directed","start_vid","end_vid","agg_cost"}'::TEXT[]) $$); SELECT set_eq( - $$SELECT proallargtypes from pg_proc where proname = 'pgr_floydwarshall'$$, + $$SELECT proallargtypes from pg_proc where proname = 'pgr_betweennesscentrality'$$, $$VALUES ('{25,16,20,20,701}'::OID[]) $$); From 9b931fe06dc1fddee86b8234972ee8b17ec4fede Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Mon, 22 Jul 2024 23:02:32 +0530 Subject: [PATCH 2/9] [centrality] types_check.pg -> betweennessCentrality/types_check.pg --- pgtap/metrics/{ => betweennessCentrality}/types_check.pg | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pgtap/metrics/{ => betweennessCentrality}/types_check.pg (100%) diff --git a/pgtap/metrics/types_check.pg b/pgtap/metrics/betweennessCentrality/types_check.pg similarity index 100% rename from pgtap/metrics/types_check.pg rename to pgtap/metrics/betweennessCentrality/types_check.pg From 28ddaae87645c4b7e0235f8bd6a201af0d4769fe Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 07:25:13 +0530 Subject: [PATCH 3/9] [centrality] fixed minor problem in documentation --- doc/metrics/pgr_betweennessCentrality.rst | 1 + pgtap/metrics/betweennessCentrality/types_check.pg | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/metrics/pgr_betweennessCentrality.rst b/doc/metrics/pgr_betweennessCentrality.rst index bc6c8c7d8b..ffaabe8e5d 100644 --- a/doc/metrics/pgr_betweennessCentrality.rst +++ b/doc/metrics/pgr_betweennessCentrality.rst @@ -45,6 +45,7 @@ Signatures | OR EMPTY SET .. TODO: Fix this when docqueries are made + :Example: For a directed subgraph with edges :math:`\{1, 2, 3, 4\}`. .. literalinclude:: betweennessCentrality.queries diff --git a/pgtap/metrics/betweennessCentrality/types_check.pg b/pgtap/metrics/betweennessCentrality/types_check.pg index 9a8893588c..59781f0caa 100644 --- a/pgtap/metrics/betweennessCentrality/types_check.pg +++ b/pgtap/metrics/betweennessCentrality/types_check.pg @@ -28,13 +28,13 @@ SELECT function_returns('pgr_betweennesscentrality', ARRAY['text','boolean'],'se SELECT set_eq( $$SELECT proargnames from pg_proc where proname = 'pgr_betweennesscentrality'$$, $$VALUES - ('{"","directed","start_vid","end_vid","agg_cost"}'::TEXT[]) + ('{"","directed","vid","centrality"}'::TEXT[]) $$); SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'pgr_betweennesscentrality'$$, $$VALUES - ('{25,16,20,20,701}'::OID[]) + ('{25,16,20,701}'::OID[]) $$); SELECT finish(); From d77799a045805e45565ca6386dc47ad94f282bcf Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 07:30:22 +0530 Subject: [PATCH 4/9] [centrality] added edge_cases.pg and added license --- .../betweennessCentrality/edge_cases.pg | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pgtap/metrics/betweennessCentrality/edge_cases.pg diff --git a/pgtap/metrics/betweennessCentrality/edge_cases.pg b/pgtap/metrics/betweennessCentrality/edge_cases.pg new file mode 100644 index 0000000000..2f7ce12c5c --- /dev/null +++ b/pgtap/metrics/betweennessCentrality/edge_cases.pg @@ -0,0 +1,94 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + ********************************************************************PGR-GNU*/ +BEGIN; + + + +SELECT finish(); +ROLLBACK; + +/* +/* -- q1 */ +SELECT * FROM pgr_betweennessCentrality( +'SELECT id, source, target, cost, reverse_cost +FROM edges where id < 5' +) ORDER BY vid; +/* Implicit Cases (directed) */ +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 2' +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 3' +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 4' +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 5' +) ORDER BY vid; + +/* Explicit Cases (undirected) */ +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 2', directed => false +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 3', directed => false +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 4', directed => false +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 5', directed => false +) ORDER BY vid; + +/* Explicit Cases (directed) */ +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 2', directed => true +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 3', directed => true +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 4', directed => true +) ORDER BY vid; + +SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges where id < 5', directed => true +) ORDER BY vid; +*/ From b96aaf7d354d40acc1b5d9a97027f8fb2d27d945 Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 15:41:25 +0530 Subject: [PATCH 5/9] [centrality] added all test cases to edge_cases.pg --- .../betweennessCentrality/edge_cases.pg | 345 +++++++++++++----- 1 file changed, 257 insertions(+), 88 deletions(-) diff --git a/pgtap/metrics/betweennessCentrality/edge_cases.pg b/pgtap/metrics/betweennessCentrality/edge_cases.pg index 2f7ce12c5c..ca29bbe7c9 100644 --- a/pgtap/metrics/betweennessCentrality/edge_cases.pg +++ b/pgtap/metrics/betweennessCentrality/edge_cases.pg @@ -1,94 +1,263 @@ -/*PGR-GNU***************************************************************** - -Copyright (c) 2018 pgRouting developers -Mail: project@pgrouting.org - ------- -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - ********************************************************************PGR-GNU*/ BEGIN; +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(24) END; +CREATE OR REPLACE FUNCTION edge_cases() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + +IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; +END IF; + +/* Implicit Test Cases */ + +PREPARE idless5_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 5' + ) ORDER BY vid; + +PREPARE idless5_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (7 , 0), + (10 , 0.25), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless5_q'); + +RETURN QUERY +SELECT results_eq('idless5_q', 'idless5_r'); + + +PREPARE idless4_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 4' + ) ORDER BY vid; + +PREPARE idless4_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.3333333333333333), + (10 , 0.3333333333333333), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless4_q'); + +RETURN QUERY +SELECT results_eq('idless4_q', 'idless4_r'); + + +PREPARE idless3_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 3' + ) ORDER BY vid; + +PREPARE idless3_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (10 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless3_q'); + +RETURN QUERY +SELECT results_eq('idless3_q', 'idless3_r'); + +PREPARE idless2_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 2' + ) ORDER BY vid; + +PREPARE idless2_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless2_q'); + +RETURN QUERY +SELECT results_eq('idless2_q', 'idless2_r'); + +/* Explicit Undirected Cases */ + +PREPARE idless5ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 5', directed => false ) ORDER BY vid; + +PREPARE idless5ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.8333333333333333), + (7 , 0), + (10 , 0.5), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless5ud_q'); + +RETURN QUERY +SELECT results_eq('idless5ud_q', 'idless5ud_r'); + +PREPARE idless4ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 4', directed => false ) ORDER BY vid; + +PREPARE idless4ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.6666666666666666), + (10 , 0.6666666666666666), (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless4ud_q'); + +RETURN QUERY +SELECT results_eq('idless4ud_q', 'idless4ud_r'); + + +PREPARE idless3ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 3', directed => false ) ORDER BY vid; + +PREPARE idless3ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 1), + (10 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless3ud_q'); + +RETURN QUERY +SELECT results_eq('idless3ud_q', 'idless3ud_r'); + +PREPARE idless2ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 2', directed => false + ) ORDER BY vid; + +PREPARE idless2ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless2ud_q'); + +RETURN QUERY +SELECT results_eq('idless2ud_q', 'idless2ud_r'); + +/* Explicit Directed Cases */ + + +PREPARE idless5d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 5', directed => true ) ORDER BY vid; + +PREPARE idless5d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (7 , 0), + (10 , 0.25), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless5d_q'); + +RETURN QUERY +SELECT results_eq('idless5d_q', 'idless5d_r'); + + +PREPARE idless4d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 4', directed => true ) ORDER BY vid; + +PREPARE idless4d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.3333333333333333), + (10 , 0.3333333333333333), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless4d_q'); + +RETURN QUERY +SELECT results_eq('idless4d_q', 'idless4d_r'); + + +PREPARE idless3d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 3', directed => true ) ORDER BY vid; + +PREPARE idless3d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (10 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless3d_q'); + +RETURN QUERY +SELECT results_eq('idless3d_q', 'idless3d_r'); + +PREPARE idless2d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 2', directed => true + ) ORDER BY vid; + +PREPARE idless2d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless2d_q'); + +RETURN QUERY +SELECT results_eq('idless2d_q', 'idless2d_r'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT edge_cases(); SELECT finish(); ROLLBACK; - -/* -/* -- q1 */ -SELECT * FROM pgr_betweennessCentrality( -'SELECT id, source, target, cost, reverse_cost -FROM edges where id < 5' -) ORDER BY vid; -/* Implicit Cases (directed) */ -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 2' -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 3' -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 4' -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 5' -) ORDER BY vid; - -/* Explicit Cases (undirected) */ -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 2', directed => false -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 3', directed => false -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 4', directed => false -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 5', directed => false -) ORDER BY vid; - -/* Explicit Cases (directed) */ -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 2', directed => true -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 3', directed => true -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 4', directed => true -) ORDER BY vid; - -SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges where id < 5', directed => true -) ORDER BY vid; -*/ From 7c7a2cd8c6587bb945317ad4f8bd5b3289708929 Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 16:14:17 +0530 Subject: [PATCH 6/9] [centrality] added and updated the license for ```edge_cases.pg``` --- .../betweennessCentrality/edge_cases.pg | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pgtap/metrics/betweennessCentrality/edge_cases.pg b/pgtap/metrics/betweennessCentrality/edge_cases.pg index ca29bbe7c9..672556d0aa 100644 --- a/pgtap/metrics/betweennessCentrality/edge_cases.pg +++ b/pgtap/metrics/betweennessCentrality/edge_cases.pg @@ -1,3 +1,22 @@ +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + ********************************************************************PGR-GNU*/ + BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); From 188b1760b416a4d4ca6940a5b7a5a49a9d1cb79a Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 16:41:36 +0530 Subject: [PATCH 7/9] added ```no_crash_test.pg``` and changed ``` edge_cases.pg``` --- .../betweennessCentrality/edge_cases.pg | 270 ++---------------- .../betweennessCentrality/no_crash_test.pg | 72 +++++ 2 files changed, 88 insertions(+), 254 deletions(-) create mode 100644 pgtap/metrics/betweennessCentrality/no_crash_test.pg diff --git a/pgtap/metrics/betweennessCentrality/edge_cases.pg b/pgtap/metrics/betweennessCentrality/edge_cases.pg index 672556d0aa..813870442f 100644 --- a/pgtap/metrics/betweennessCentrality/edge_cases.pg +++ b/pgtap/metrics/betweennessCentrality/edge_cases.pg @@ -1,6 +1,6 @@ /*PGR-GNU***************************************************************** -Copyright (c) 2024 pgRouting developers +Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org ------ @@ -20,263 +20,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(24) END; +SELECT plan(15); -CREATE OR REPLACE FUNCTION edge_cases() -RETURNS SETOF TEXT AS -$BODY$ -BEGIN +SELECT test_agg_cost('pgr_floydWarshall', true); +SELECT test_agg_cost('pgr_floydWarshall', false); +SELECT allPairs_test_flags('pgr_floydwarshall'); -IF NOT min_version('3.7.0') THEN - RETURN QUERY - SELECT skip(1, 'Function is new on 3.7.0'); - RETURN; -END IF; +PREPARE q2 AS +SELECT * FROM pgr_floydWarshall( + 'SELECT source, target, cost, reverse_cost FROM edges' +); -/* Implicit Test Cases */ +PREPARE q3 AS +SELECT * FROM pgr_floydWarshall( + 'SELECT source, target, cost FROM edges', + true +); -PREPARE idless5_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 5' - ) ORDER BY vid; - -PREPARE idless5_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.5), - (7 , 0), - (10 , 0.25), - (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless5_q'); - -RETURN QUERY -SELECT results_eq('idless5_q', 'idless5_r'); - - -PREPARE idless4_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 4' - ) ORDER BY vid; - -PREPARE idless4_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.3333333333333333), - (10 , 0.3333333333333333), - (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless4_q'); - -RETURN QUERY -SELECT results_eq('idless4_q', 'idless4_r'); - - -PREPARE idless3_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 3' - ) ORDER BY vid; - -PREPARE idless3_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.5), - (10 , 0) - ) AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless3_q'); - -RETURN QUERY -SELECT results_eq('idless3_q', 'idless3_r'); - -PREPARE idless2_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 2' - ) ORDER BY vid; - -PREPARE idless2_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0) - ) AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless2_q'); - -RETURN QUERY -SELECT results_eq('idless2_q', 'idless2_r'); - -/* Explicit Undirected Cases */ - -PREPARE idless5ud_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 5', directed => false ) ORDER BY vid; - -PREPARE idless5ud_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.8333333333333333), - (7 , 0), - (10 , 0.5), - (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless5ud_q'); - -RETURN QUERY -SELECT results_eq('idless5ud_q', 'idless5ud_r'); - -PREPARE idless4ud_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 4', directed => false ) ORDER BY vid; - -PREPARE idless4ud_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.6666666666666666), - (10 , 0.6666666666666666), (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless4ud_q'); - -RETURN QUERY -SELECT results_eq('idless4ud_q', 'idless4ud_r'); - - -PREPARE idless3ud_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 3', directed => false ) ORDER BY vid; - -PREPARE idless3ud_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 1), - (10 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless3ud_q'); - -RETURN QUERY -SELECT results_eq('idless3ud_q', 'idless3ud_r'); - -PREPARE idless2ud_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 2', directed => false - ) ORDER BY vid; - -PREPARE idless2ud_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless2ud_q'); - -RETURN QUERY -SELECT results_eq('idless2ud_q', 'idless2ud_r'); - -/* Explicit Directed Cases */ - - -PREPARE idless5d_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 5', directed => true ) ORDER BY vid; - -PREPARE idless5d_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.5), - (7 , 0), - (10 , 0.25), - (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless5d_q'); - -RETURN QUERY -SELECT results_eq('idless5d_q', 'idless5d_r'); - - -PREPARE idless4d_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 4', directed => true ) ORDER BY vid; - -PREPARE idless4d_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.3333333333333333), - (10 , 0.3333333333333333), - (15 , 0)) - AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless4d_q'); - -RETURN QUERY -SELECT results_eq('idless4d_q', 'idless4d_r'); - - -PREPARE idless3d_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 3', directed => true ) ORDER BY vid; - -PREPARE idless3d_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0.5), - (10 , 0) - ) AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless3d_q'); - -RETURN QUERY -SELECT results_eq('idless3d_q', 'idless3d_r'); - -PREPARE idless2d_q AS - SELECT * FROM pgr_betweennessCentrality( - 'SELECT id, source, target, cost, reverse_cost - FROM edges WHERE id < 2', directed => true - ) ORDER BY vid; - -PREPARE idless2d_r AS - SELECT * FROM (VALUES - (5::BIGINT , 0::FLOAT), - (6 , 0) - ) AS t(vid, centrality); - -RETURN QUERY -SELECT lives_ok('idless2d_q'); - -RETURN QUERY -SELECT results_eq('idless2d_q', 'idless2d_r'); - -END; -$BODY$ -LANGUAGE plpgsql; - -SELECT edge_cases(); +SELECT lives_ok('q2', 'SHOULD WORK: without id with flag'); +SELECT lives_ok('q3', 'SHOULD WORK: without id, with flag'); SELECT finish(); ROLLBACK; diff --git a/pgtap/metrics/betweennessCentrality/no_crash_test.pg b/pgtap/metrics/betweennessCentrality/no_crash_test.pg new file mode 100644 index 0000000000..c7b37ce9e7 --- /dev/null +++ b/pgtap/metrics/betweennessCentrality/no_crash_test.pg @@ -0,0 +1,72 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + ********************************************************************PGR-GNU*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(7) END; + +PREPARE edges_q AS +SELECT id, source, target, cost, reverse_cost FROM edges; + +PREPARE null_ret AS +SELECT id FROM vertices WHERE id IN (-1); + +PREPARE null_ret_arr AS +SELECT array_agg(id) FROM vertices WHERE id IN (-1); + + +CREATE OR REPLACE FUNCTION no_crash() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +params TEXT[]; +subs TEXT[]; +BEGIN + IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; + END IF; + + RETURN QUERY + SELECT isnt_empty('edges_q', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); + RETURN QUERY + SELECT set_eq('null_ret_arr', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful'); + + params = ARRAY[ + '$$SELECT id, source, target, cost, reverse_cost FROM edges$$' + ]::TEXT[]; + subs = ARRAY[ + 'NULL' + ]::TEXT[]; + + RETURN query SELECT * FROM no_crash_test('pgr_betweennessCentrality', params, subs); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT * FROM no_crash(); + +SELECT finish(); +ROLLBACK; From 238edfd55cd8540f81ebad67afa931d5d5d332c2 Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 16:44:51 +0530 Subject: [PATCH 8/9] [centrality] added `inner_query.pg``` and it works --- .../betweennessCentrality/inner_query.pg | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pgtap/metrics/betweennessCentrality/inner_query.pg diff --git a/pgtap/metrics/betweennessCentrality/inner_query.pg b/pgtap/metrics/betweennessCentrality/inner_query.pg new file mode 100644 index 0000000000..97b6ea8d71 --- /dev/null +++ b/pgtap/metrics/betweennessCentrality/inner_query.pg @@ -0,0 +1,46 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + ********************************************************************PGR-GNU*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(54) END; + +CREATE OR REPLACE FUNCTION inner_query() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + +IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; +END IF; + +RETURN QUERY +SELECT style_dijkstra('pgr_betweennessCentrality(', ')'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT inner_query(); + +SELECT finish(); +ROLLBACK; From 0830bc324e8326a3b05342fc5e3415da8bfcffb6 Mon Sep 17 00:00:00 2001 From: Arun Thakur Date: Sun, 28 Jul 2024 17:09:15 +0530 Subject: [PATCH 9/9] [centrality] minor changes --- pgtap/metrics/betweennessCentrality/edge_cases.pg | 2 +- pgtap/metrics/betweennessCentrality/inner_query.pg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pgtap/metrics/betweennessCentrality/edge_cases.pg b/pgtap/metrics/betweennessCentrality/edge_cases.pg index 813870442f..bcfc6c9594 100644 --- a/pgtap/metrics/betweennessCentrality/edge_cases.pg +++ b/pgtap/metrics/betweennessCentrality/edge_cases.pg @@ -1,6 +1,6 @@ /*PGR-GNU***************************************************************** -Copyright (c) 2018 pgRouting developers +Copyright (c) 2024 pgRouting developers Mail: project@pgrouting.org ------ diff --git a/pgtap/metrics/betweennessCentrality/inner_query.pg b/pgtap/metrics/betweennessCentrality/inner_query.pg index 97b6ea8d71..9873cbb703 100644 --- a/pgtap/metrics/betweennessCentrality/inner_query.pg +++ b/pgtap/metrics/betweennessCentrality/inner_query.pg @@ -1,7 +1,7 @@ /*PGR-GNU***************************************************************** -Copyright (c) 2018 pgRouting developers +Copyright (c) 2024 pgRouting developers Mail: project@pgrouting.org ------