Skip to content

Commit 0110bc3

Browse files
authored
add pgrouting tests (#1162)
1 parent 10582da commit 0110bc3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

nix/tests/expected/pgrouting.out

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
create schema v;
2+
-- create the roads table
3+
create table v.roads (
4+
id serial primary key,
5+
source integer,
6+
target integer,
7+
cost double precision
8+
);
9+
-- insert sample data into roads table
10+
insert into v.roads (source, target, cost) values
11+
(1, 2, 1.0),
12+
(2, 3, 1.0),
13+
(3, 4, 1.0),
14+
(1, 3, 2.5),
15+
(3, 5, 2.0);
16+
-- create a function to use pgRouting to find the shortest path
17+
select * from pgr_dijkstra(
18+
'select id, source, target, cost from v.roads',
19+
1, -- start node
20+
4 -- end node
21+
);
22+
seq | path_seq | node | edge | cost | agg_cost
23+
-----+----------+------+------+------+----------
24+
1 | 1 | 1 | 1 | 1 | 0
25+
2 | 2 | 2 | 2 | 1 | 1
26+
3 | 3 | 3 | 3 | 1 | 2
27+
4 | 4 | 4 | -1 | 0 | 3
28+
(4 rows)
29+
30+
drop schema v cascade;
31+
NOTICE: drop cascades to table v.roads

nix/tests/sql/pgrouting.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
create schema v;
2+
3+
-- create the roads table
4+
create table v.roads (
5+
id serial primary key,
6+
source integer,
7+
target integer,
8+
cost double precision
9+
);
10+
11+
-- insert sample data into roads table
12+
insert into v.roads (source, target, cost) values
13+
(1, 2, 1.0),
14+
(2, 3, 1.0),
15+
(3, 4, 1.0),
16+
(1, 3, 2.5),
17+
(3, 5, 2.0);
18+
19+
-- create a function to use pgRouting to find the shortest path
20+
select * from pgr_dijkstra(
21+
'select id, source, target, cost from v.roads',
22+
1, -- start node
23+
4 -- end node
24+
);
25+
26+
drop schema v cascade;
27+

0 commit comments

Comments
 (0)