|
| 1 | + |
| 2 | +/*PGR-GNU***************************************************************** |
| 3 | + |
| 4 | +Copyright (c) 2018 pgRouting developers |
| 5 | +Mail: project@pgrouting.org |
| 6 | + |
| 7 | +------ |
| 8 | +This program is free software; you can redistribute it and/or modify |
| 9 | +it under the terms of the GNU General Public License as published by |
| 10 | +the Free Software Foundation; either version 2 of the License, or |
| 11 | +(at your option) any later version. |
| 12 | +This program is distributed in the hope that it will be useful, |
| 13 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +GNU General Public License for more details. |
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with this program; if not, write to the Free Software |
| 18 | +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + ********************************************************************PGR-GNU*/ |
| 20 | +BEGIN; |
| 21 | + |
| 22 | +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); |
| 23 | +SELECT CASE WHEN NOT min_version('4.0.0') THEN plan(1) ELSE plan(4) END; |
| 24 | + |
| 25 | + |
| 26 | +CREATE OR REPLACE FUNCTION edge_cases() |
| 27 | +RETURNS SETOF TEXT AS |
| 28 | +$BODY$ |
| 29 | +BEGIN |
| 30 | + |
| 31 | +IF NOT min_version('4.0.0') THEN |
| 32 | + RETURN QUERY |
| 33 | + SELECT skip(1, 'Function is new on 4.0.0'); |
| 34 | + RETURN; |
| 35 | +END IF; |
| 36 | + |
| 37 | +-- 0 edge, 0 vertex test |
| 38 | + |
| 39 | +PREPARE q1 AS |
| 40 | +SELECT * FROM pgr_kingOrdering( |
| 41 | +'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18' |
| 42 | +); |
| 43 | + |
| 44 | +RETURN QUERY |
| 45 | +SELECT is_empty('q1', 'Graph with 0 edge and 0 vertex -> Empty row is returned'); |
| 46 | + |
| 47 | +-- 1 vertex test: 6 -- 6 |
| 48 | + |
| 49 | +PREPARE q2 AS |
| 50 | +SELECT * |
| 51 | +FROM pgr_kingOrdering('SELECT id, source, source AS target, cost, reverse_cost FROM edges WHERE id = 2'); |
| 52 | + |
| 53 | +RETURN QUERY |
| 54 | +SELECT set_eq('q2', $$VALUES (1, 6)$$, '6 -- 6: Same node returned'); |
| 55 | + |
| 56 | +-- 2 vertices test (connected): 3 -- 7; 7 -- 3 |
| 57 | + |
| 58 | +PREPARE q3 AS |
| 59 | +SELECT * |
| 60 | +FROM pgr_kingOrdering('SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 7' |
| 61 | +); |
| 62 | + |
| 63 | +RETURN QUERY |
| 64 | +SELECT set_eq('q3', $$VALUES (1,3), (2,7)$$, '3 --7; 7 -- 3: Natural order of edges'); |
| 65 | + |
| 66 | +PERFORM todo_start('Same graph, but with different order of edges'); |
| 67 | +-- 2 vertices test (connected): 7 -- 3; 3 -- 7 |
| 68 | + |
| 69 | +PREPARE q4 AS |
| 70 | +SELECT * |
| 71 | +FROM pgr_kingOrdering('SELECT id, target AS source, source AS target, cost, reverse_cost FROM edges WHERE id = 7' |
| 72 | +); |
| 73 | + |
| 74 | +RETURN QUERY |
| 75 | +SELECT set_eq('q4', $$VALUES (1,3), (2,7)$$, '7 --3; 3 -- 7: Does not matter if 3 comes first or second'); |
| 76 | +PERFORM todo_end(); |
| 77 | + |
| 78 | +END; |
| 79 | +$BODY$ |
| 80 | +LANGUAGE plpgsql; |
| 81 | + |
| 82 | +SELECT edge_cases(); |
| 83 | + |
| 84 | + |
| 85 | +SELECT * FROM finish(); |
| 86 | +ROLLBACK; |
0 commit comments