File: edge_cases.pg

package info (click to toggle)
pgrouting 4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,332 kB
  • sloc: cpp: 21,315; sql: 10,419; ansic: 9,795; perl: 1,142; sh: 919; javascript: 314; xml: 182; makefile: 29
file content (110 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* :file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2019-2026 pgRouting developers
:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */


BEGIN;

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

UPDATE edges SET cost = 0 WHERE id IN(1, 4, 7, 12, 15, 16, 17, 18);
UPDATE edges SET reverse_cost = 0 WHERE id IN(1, 3, 4, 7, 15, 16, 17, 18);

-- 0 edges tests

-- directed graph
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '', 5, 2)', '2');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',array[5], 3)','3');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',5, array[3, 7])','3');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',array[2,5], array[3,7])', '4');

-- undirected graph
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '', 5, 2, directed := false)', '5');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',array[5], 3, directed := false)','6');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',5, array[3, 7], directed := false)','7');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges where id>18 '',array[2,5], array[3,7], directed := false)', '8');

-- -- vertex not present in graph tests
-- directed graph
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges'', -5, 2)', '2');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges'',array[5], -3)','3');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges'',5, array[-3, -7])','3');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT * from edges'',array[-2,-5], array[3,7])', '4');

-- undirected graph
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT *  from edges'', 5, -2, directed := false)', '5');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT *  from edges'',array[-5], 3, directed := false)','6');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT *  from edges'',-5, array[-3, 7], directed := false)','7');
SELECT is_empty('
SELECT * from pgr_binaryBreadthFirstSearch(''SELECT *  from edges'',array[-2,-5], array[-3,-7], directed := false)', '8');

SELECT * INTO edges_invalid_1 FROM edges;
UPDATE edges_invalid_1 SET cost = 5 WHERE id = 1;

PREPARE errorTestManyWeights AS
SELECT *
FROM pgr_binaryBreadthFirstSearch(
    'SELECT *
    FROM edges_invalid_1',
    4, 6
);


SELECT
  CASE WHEN min_lib_version('4.0.0') THEN
    throws_ok('errorTestManyWeights',
    'XX000',
    'Graph Condition Failed: Graph should have at most two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!',
      '17: Graph has more than 2 distinct weights')
  ELSE
  throws_ok('errorTestManyWeights',
    'XX000',
    'Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!',
      '17: Graph has more than 2 distinct weights')
  END;

SELECT * INTO edges_invalid_2 FROM edges;
UPDATE edges_invalid_2 SET cost = 2 WHERE cost = 0;
UPDATE edges_invalid_2 SET reverse_cost = 2 WHERE reverse_cost = 0;

PREPARE errorTestNoZeroWeight AS
SELECT *
FROM pgr_binaryBreadthFirstSearch(
    'SELECT *
    FROM edges_invalid_2',
    4, 6
);


SELECT
  CASE WHEN min_lib_version('4.0.0') THEN
     throws_ok('errorTestNoZeroWeight',
    'XX000',
    'Graph Condition Failed: Graph should have at most two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!',
    '17: If graph has 2 distinct weights, one must be zero')
  ELSE
     throws_ok('errorTestNoZeroWeight',
    'XX000',
    'Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!',
    '17: If graph has 2 distinct weights, one must be zero')
  END;


SELECT * FROM finish();
ROLLBACK;