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;