Skip to content

Commit

Permalink
[pgtap] Using sampledata on 4 directories
Browse files Browse the repository at this point in the history
* astar
  * empty_combinations_empty_result.pg => empty_inner_queries_empty_result.pg
  * new test: compare_dijkstra/combinations.pg
* dijkstra
  * deleted remaining_tests.pg that has duplicated tests
  * deleted issue_1152.pg that takes too long n time and resources and is not unit test
* ksp
* withPoints
  * new tests: allowed_driving_side.pg
  • Loading branch information
cvvergara committed Sep 21, 2023
1 parent f3d7ec3 commit d77eb8e
Show file tree
Hide file tree
Showing 96 changed files with 1,552 additions and 2,494 deletions.
2 changes: 1 addition & 1 deletion pgtap/astar/aStarCostMatrix/inner_query.pg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
BEGIN;

UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost);
UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost);
SELECT plan(102);

-- ONE MATRIX
Expand Down
17 changes: 8 additions & 9 deletions pgtap/astar/aStarCostMatrix/no_crash_test.pg
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
BEGIN;

UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost);
UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost);
SELECT plan(15);

PREPARE edges AS
SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table;
PREPARE edges_q AS
SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges;

PREPARE null_ret AS
SELECT id FROM edge_table_vertices_pgr WHERE id IN (-1);
SELECT id FROM vertices WHERE id IN (-1);

PREPARE null_ret_arr AS
SELECT array_agg(id) FROM edge_table_vertices_pgr WHERE id IN (-1);
SELECT array_agg(id) FROM vertices WHERE id IN (-1);

SELECT isnt_empty('edges', 'Should be not empty to tests be meaningful');
SELECT isnt_empty('edges_q', 'Should be not empty to tests be meaningful');
SELECT is_empty('null_ret', 'Should be empty to tests be meaningful');
SELECT set_eq('null_ret_arr', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful');


CREATE OR REPLACE FUNCTION test_function()
RETURNS SETOF TEXT AS
$BODY$
Expand All @@ -44,10 +43,10 @@ params TEXT[];
subs TEXT[];
BEGIN

params = ARRAY['$$edges$$','ARRAY[1,2]::BIGINT[]']::TEXT[];
params = ARRAY['$$edges_q$$','ARRAY[5,6]::BIGINT[]']::TEXT[];
subs = ARRAY[
'NULL',
'(SELECT array_agg(id) FROM edge_table_vertices_pgr WHERE id IN (-1))'
'(SELECT array_agg(id) FROM vertices WHERE id IN (-1))'
]::TEXT[];

RETURN query SELECT * FROM no_crash_test('pgr_astarCostMatrix', params, subs);
Expand Down
88 changes: 88 additions & 0 deletions pgtap/astar/astar/compare_dijkstra/combinations.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*PGR-GNU*****************************************************************

Copyright (c) 2023 pgRouting developers
Mail: [email protected]

------

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 CASE WHEN min_version('3.2.0') THEN plan(4) ELSE plan(1) END;

UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION astarCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
$BODY$
DECLARE
inner_sql TEXT;
dijkstra_sql TEXT;
astar_sql TEXT;
vids TEXT;
data TEXT;
BEGIN
IF NOT min_version('3.2.0') THEN
RETURN query
SELECT skip(1, 'Combinations signature added on version 3.2');
RETURN;
END IF;

data := ' path_seq, start_vid, end_vid, round(cost::numeric,8) AS cost, round(agg_cost::numeric,8) AS agg_cost ';
vids := ' SELECT * FROM combinations ';


-----------------------
-- with reverse cost
-----------------------
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
-- DIRECTED
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, $$' || vids || '$$, true)';
astar_sql := 'SELECT ' || data || ' FROM pgr_astar($$' || inner_sql || '$$, $$' || vids || '$$, true, heuristic := 0)';
RETURN query SELECT set_eq(astar_sql, dijkstra_sql, astar_sql);

-- UNDIRECTED
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, $$' || vids || '$$, false)';
astar_sql := 'SELECT ' || data || ' FROM pgr_astar($$' || inner_sql || '$$, $$' || vids || '$$, false, heuristic := 0)';
RETURN query SELECT set_eq(astar_sql, dijkstra_sql, astar_sql);

-----------------------
-- NO reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, $$' || vids || '$$, true)';
astar_sql := 'SELECT ' || data || ' FROM pgr_astar($$' || inner_sql || '$$, $$' || vids || '$$, true, heuristic := 0)';
RETURN query SELECT set_eq(astar_sql, dijkstra_sql, astar_sql);

-- UNDIRECTED
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, $$' || vids || '$$, false)';
astar_sql := 'SELECT ' || data || ' FROM pgr_astar($$' || inner_sql || '$$, $$' || vids || '$$, false, heuristic := 0)';
RETURN query SELECT set_eq(astar_sql, dijkstra_sql, astar_sql);

RETURN;
END
$BODY$
language plpgsql;

SELECT * from astarCompareDijkstra();


SELECT * FROM finish();
ROLLBACK;

6 changes: 3 additions & 3 deletions pgtap/astar/astar/compare_dijkstra/many_to_many.pg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BEGIN;

SELECT plan(4);

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;
UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION astarCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
Expand All @@ -45,7 +45,7 @@ BEGIN
-- with reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || vids
|| ',' || vids || ', true)';

Expand All @@ -65,7 +65,7 @@ BEGIN
-- NO reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || vids
|| ',' || vids || ', true)';

Expand Down
9 changes: 5 additions & 4 deletions pgtap/astar/astar/compare_dijkstra/many_to_one.pg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT plan(68);

SET client_min_messages TO ERROR;

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;
UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION astarCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
Expand All @@ -39,7 +39,8 @@ astar_sql TEXT;
vids TEXT;
data TEXT;
BEGIN
data := ' seq, start_vid, cost::text, agg_cost::text ';
data := ' seq, path_seq, start_vid, round(cost::numeric,8) AS cost, round(agg_cost::numeric,8) AS agg_cost ';

vids := ' ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] ';

FOR i IN 1.. cant LOOP
Expand All @@ -48,7 +49,7 @@ BEGIN
-- with reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || vids
|| ',' || i || ', true)';

Expand All @@ -68,7 +69,7 @@ BEGIN
-- NO reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || vids
|| ',' || i || ', true)';

Expand Down
9 changes: 5 additions & 4 deletions pgtap/astar/astar/compare_dijkstra/one_to_many.pg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT plan(68);

SET client_min_messages TO ERROR;

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;
UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION astarCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
Expand All @@ -39,7 +39,8 @@ astar_sql TEXT;
vids TEXT;
data TEXT;
BEGIN
data = ' seq, end_vid, round(cost::numeric,8) AS cost, round(agg_cost::numeric,8) AS agg_cost ';
data := ' seq, path_seq, end_vid, round(cost::numeric,8) AS cost, round(agg_cost::numeric,8) AS agg_cost ';

vids = ' ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] ';

FOR i IN 1.. cant LOOP
Expand All @@ -48,7 +49,7 @@ BEGIN
-- with reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || vids
|| ', true)';

Expand All @@ -68,7 +69,7 @@ BEGIN
-- NO reverse cost
-----------------------
-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || data || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || vids
|| ', true)';

Expand Down
10 changes: 5 additions & 5 deletions pgtap/astar/astar/compare_dijkstra/one_to_one.pg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BEGIN;

SELECT plan(612);

UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;
UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id;

CREATE or REPLACE FUNCTION astarCompareDijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
Expand All @@ -42,7 +42,7 @@ BEGIN
FOR j IN 1.. cant LOOP

-- DIRECTED WITH REVERSE COST
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';

Expand All @@ -52,7 +52,7 @@ BEGIN


-- DIRECTED WITHOUT REVERSE COST
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';

Expand All @@ -62,7 +62,7 @@ BEGIN


-- UNDIRECTED WITH REVERSE COST
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';

Expand All @@ -72,7 +72,7 @@ BEGIN


-- UNDIRECTED WITHOUT REVERSE COST
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edge_table';
inner_sql := 'SELECT id, source, target, cost, x1, y1, x2, y2 FROM edges';
dijkstra_sql := 'SELECT ' || result_columns || ' FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';

Expand Down
49 changes: 0 additions & 49 deletions pgtap/astar/astar/edge_cases/empty_combinations_empty_result.pg

This file was deleted.

Loading

0 comments on commit d77eb8e

Please sign in to comment.