forked from pgRouting/pgrouting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno_crash_test.pg
More file actions
148 lines (116 loc) · 3.94 KB
/
Copy pathno_crash_test.pg
File metadata and controls
148 lines (116 loc) · 3.94 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* :file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2018-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(cost);
SELECT CASE WHEN min_version('4.0.0') THEN plan(82) ELSE plan(1) END;
CREATE OR REPLACE FUNCTION no_crash()
RETURNS SETOF TEXT AS
$BODY$
DECLARE
params TEXT[];
subs TEXT[];
BEGIN
IF NOT min_version('4.0.0') THEN
RETURN QUERY SELECT skip(1, 'pgr_DAGshortestPath return columns are standardized on v4.0.0');
RETURN;
END IF;
PREPARE edges AS
SELECT id, source, target, 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);
RETURN QUERY
SELECT isnt_empty('edges', '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');
-- one to one
params = ARRAY[
'$$SELECT id, source, target, cost FROM edges$$',
'5::BIGINT',
'6::BIGINT'
]::TEXT[];
subs = ARRAY[
'NULL',
'(SELECT id FROM vertices WHERE id IN (-1))',
'(SELECT id FROM vertices WHERE id IN (-1))'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
subs = ARRAY[
'NULL',
'NULL::BIGINT',
'NULL::BIGINT'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
-- one to many
params = ARRAY['$$edges$$','1', 'ARRAY[6,7]::BIGINT[]']::TEXT[];
subs = ARRAY[
'NULL',
'(SELECT id FROM vertices WHERE id IN (-1))',
'(SELECT array_agg(id) FROM vertices WHERE id IN (-1))'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
subs = ARRAY[
'NULL',
'NULL::BIGINT',
'NULL::BIGINT[]'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
-- many to one
params = ARRAY['$$edges$$', 'ARRAY[5]::BIGINT[]', '6']::TEXT[];
subs = ARRAY[
'NULL',
'(SELECT array_agg(id) FROM vertices WHERE id IN (-1))',
'(SELECT id FROM vertices WHERE id IN (-1))'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
subs = ARRAY[
'NULL',
'NULL::BIGINT[]',
'NULL::BIGINT'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
-- many to many
params = ARRAY['$$edges$$','ARRAY[1]::BIGINT[]', 'ARRAY[6,7]::BIGINT[]']::TEXT[];
subs = ARRAY[
'NULL',
'(SELECT array_agg(id) FROM vertices WHERE id IN (-1))',
'(SELECT array_agg(id) FROM vertices WHERE id IN (-1))'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
subs = ARRAY[
'NULL',
'NULL::BIGINT[]',
'NULL::BIGINT[]'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
PREPARE combinations AS
SELECT source, target FROM combinations;
PREPARE null_combinations AS
SELECT source, target FROM combinations WHERE source IN (-1);
RETURN QUERY
SELECT isnt_empty('combinations', 'Should be not empty to tests be meaningful');
RETURN QUERY
SELECT is_empty('null_combinations', 'Should be empty to tests be meaningful');
-- Combinations SQL
params = ARRAY['$$edges$$', '$$combinations$$']::TEXT[];
subs = ARRAY[
'NULL',
'$$(SELECT source, target FROM combinations WHERE source IN (-1))$$'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
subs = ARRAY[
'NULL',
'NULL::TEXT'
]::TEXT[];
RETURN query SELECT * FROM no_crash_test('pgr_dagShortestPath', params, subs);
RETURN query SELECT throw_on_empty_edges_sql('pgr_dagShortestPath', ',1,5');
END
$BODY$
LANGUAGE plpgsql VOLATILE;
SELECT no_crash();
SELECT finish();
ROLLBACK;