Skip to content

Commit 7376dc8

Browse files
committed
Add tests for issue #2966
1 parent a95b385 commit 7376dc8

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
Mail: project@pgrouting.org
5+
6+
------
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
********************************************************************PGR-GNU*/
19+
20+
/*
21+
* Issue #2966: pgr_withPoints does not pick optimal route when fraction = 1
22+
* This test verifies that pgr_trspVia_withPoints also handles fraction=1 correctly.
23+
*/
24+
25+
BEGIN;
26+
27+
SET extra_float_digits=-3;
28+
29+
SELECT CASE WHEN min_version('4.1.0') THEN plan(2) ELSE plan(1) END;
30+
31+
CREATE OR REPLACE FUNCTION issue_2966_tests()
32+
RETURNS SETOF TEXT AS
33+
$BODY$
34+
BEGIN
35+
36+
IF NOT min_version('4.1.0') THEN
37+
RETURN QUERY SELECT skip(1, 'pgr_trspVia_withPoints: Issue 2966 test requires 4.1.0+');
38+
RETURN;
39+
END IF;
40+
41+
CREATE TEMP TABLE test_edges AS
42+
SELECT * FROM (VALUES
43+
(100::BIGINT, 1001::BIGINT, 1002::BIGINT, 10::FLOAT, 10::FLOAT),
44+
(101::BIGINT, 1002::BIGINT, 1003::BIGINT, 12::FLOAT, 12::FLOAT),
45+
(102::BIGINT, 1002::BIGINT, 1003::BIGINT, 100::FLOAT, 100::FLOAT)
46+
) AS t(id, source, target, cost, reverse_cost);
47+
48+
-- Test 1: fraction = 1 should work correctly
49+
RETURN QUERY SELECT set_eq(
50+
$$SELECT agg_cost::TEXT FROM pgr_trspVia_withPoints(
51+
'SELECT * FROM test_edges',
52+
'SELECT path, cost FROM (SELECT ARRAY[1]::INTEGER[] as path, 0::FLOAT as cost WHERE false) AS t',
53+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
54+
ARRAY[1, 2],
55+
'b'
56+
) WHERE edge < 0$$,
57+
ARRAY['17']::TEXT[],
58+
'Issue 2966 (TRSPVia): fraction=1 should route correctly (cost 17, not 105)'
59+
);
60+
61+
-- Test 2: Verify the path uses the correct edges
62+
RETURN QUERY SELECT set_eq(
63+
$$SELECT edge::TEXT FROM pgr_trspVia_withPoints(
64+
'SELECT * FROM test_edges',
65+
'SELECT path, cost FROM (SELECT ARRAY[1]::INTEGER[] as path, 0::FLOAT as cost WHERE false) AS t',
66+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
67+
ARRAY[1, 2],
68+
'b'
69+
) WHERE edge > 0$$,
70+
ARRAY['100', '101']::TEXT[],
71+
'Issue 2966 (TRSPVia): Path should use edges 100 and 101'
72+
);
73+
74+
DROP TABLE test_edges;
75+
76+
END;
77+
$BODY$
78+
LANGUAGE plpgsql;
79+
80+
SELECT issue_2966_tests();
81+
82+
SELECT * FROM finish();
83+
ROLLBACK;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
Mail: project@pgrouting.org
5+
6+
------
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
********************************************************************PGR-GNU*/
19+
20+
/*
21+
* Issue #2966: pgr_withPoints does not pick optimal route when fraction = 1
22+
* This test verifies that pgr_trsp_withPoints also handles fraction=1 correctly.
23+
*/
24+
25+
BEGIN;
26+
27+
SET extra_float_digits=-3;
28+
29+
SELECT CASE WHEN min_version('4.1.0') THEN plan(2) ELSE plan(1) END;
30+
31+
CREATE OR REPLACE FUNCTION issue_2966_tests()
32+
RETURNS SETOF TEXT AS
33+
$BODY$
34+
BEGIN
35+
36+
IF NOT min_version('4.1.0') THEN
37+
RETURN QUERY SELECT skip(1, 'pgr_trsp_withPoints: Issue 2966 test requires 4.1.0+');
38+
RETURN;
39+
END IF;
40+
41+
CREATE TEMP TABLE test_edges AS
42+
SELECT * FROM (VALUES
43+
(100::BIGINT, 1001::BIGINT, 1002::BIGINT, 10::FLOAT, 10::FLOAT),
44+
(101::BIGINT, 1002::BIGINT, 1003::BIGINT, 12::FLOAT, 12::FLOAT),
45+
(102::BIGINT, 1002::BIGINT, 1003::BIGINT, 100::FLOAT, 100::FLOAT)
46+
) AS t(id, source, target, cost, reverse_cost);
47+
48+
-- Test 1: fraction = 1 should work correctly
49+
RETURN QUERY SELECT set_eq(
50+
$$SELECT agg_cost::TEXT FROM pgr_trsp_withPoints(
51+
'SELECT * FROM test_edges',
52+
'SELECT path, cost FROM (SELECT ARRAY[1]::INTEGER[] as path, 0::FLOAT as cost WHERE false) AS t',
53+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
54+
-1, -2,
55+
'b',
56+
true
57+
) WHERE edge < 0$$,
58+
ARRAY['17']::TEXT[],
59+
'Issue 2966 (TRSP): fraction=1 should route correctly (cost 17, not 105)'
60+
);
61+
62+
-- Test 2: Verify the path uses the correct edges
63+
RETURN QUERY SELECT set_eq(
64+
$$SELECT edge::TEXT FROM pgr_trsp_withPoints(
65+
'SELECT * FROM test_edges',
66+
'SELECT path, cost FROM (SELECT ARRAY[1]::INTEGER[] as path, 0::FLOAT as cost WHERE false) AS t',
67+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
68+
-1, -2,
69+
'b',
70+
true
71+
) WHERE edge > 0$$,
72+
ARRAY['100', '101']::TEXT[],
73+
'Issue 2966 (TRSP): Path should use edges 100 and 101'
74+
);
75+
76+
DROP TABLE test_edges;
77+
78+
END;
79+
$BODY$
80+
LANGUAGE plpgsql;
81+
82+
SELECT issue_2966_tests();
83+
84+
SELECT * FROM finish();
85+
ROLLBACK;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
Mail: project@pgrouting.org
5+
6+
------
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
********************************************************************PGR-GNU*/
19+
20+
/*
21+
* Issue #2966: pgr_withPoints does not pick optimal route when fraction = 1
22+
* This test verifies that pgr_withPointsVia also handles fraction=1 correctly.
23+
*/
24+
25+
BEGIN;
26+
27+
SET extra_float_digits=-3;
28+
29+
SELECT CASE WHEN min_version('4.1.0') THEN plan(2) ELSE plan(1) END;
30+
31+
CREATE OR REPLACE FUNCTION issue_2966_tests()
32+
RETURNS SETOF TEXT AS
33+
$BODY$
34+
BEGIN
35+
36+
IF NOT min_version('4.1.0') THEN
37+
RETURN QUERY SELECT skip(1, 'pgr_withPointsVia: Issue 2966 test requires 4.1.0+');
38+
RETURN;
39+
END IF;
40+
41+
CREATE TEMP TABLE test_edges AS
42+
SELECT * FROM (VALUES
43+
(100::BIGINT, 1001::BIGINT, 1002::BIGINT, 10::FLOAT, 10::FLOAT),
44+
(101::BIGINT, 1002::BIGINT, 1003::BIGINT, 12::FLOAT, 12::FLOAT),
45+
(102::BIGINT, 1002::BIGINT, 1003::BIGINT, 100::FLOAT, 100::FLOAT)
46+
) AS t(id, source, target, cost, reverse_cost);
47+
48+
-- Test 1: fraction = 1 should work correctly
49+
RETURN QUERY SELECT set_eq(
50+
$$SELECT agg_cost::TEXT FROM pgr_withPointsVia(
51+
'SELECT * FROM test_edges',
52+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
53+
ARRAY[1, 2],
54+
driving_side := 'b'
55+
) WHERE edge < 0$$,
56+
ARRAY['17']::TEXT[],
57+
'Issue 2966 (Via): fraction=1 should route correctly (cost 17, not 105)'
58+
);
59+
60+
-- Test 2: Verify the path uses the correct edges
61+
RETURN QUERY SELECT set_eq(
62+
$$SELECT edge::TEXT FROM pgr_withPointsVia(
63+
'SELECT * FROM test_edges',
64+
'SELECT * FROM (VALUES (1, 100, 0.5), (2, 101, 1)) AS t(pid, edge_id, fraction)',
65+
ARRAY[1, 2],
66+
driving_side := 'b'
67+
) WHERE edge > 0$$,
68+
ARRAY['100', '101']::TEXT[],
69+
'Issue 2966 (Via): Path should use edges 100 and 101'
70+
);
71+
72+
DROP TABLE test_edges;
73+
74+
END;
75+
$BODY$
76+
LANGUAGE plpgsql;
77+
78+
SELECT issue_2966_tests();
79+
80+
SELECT * FROM finish();
81+
ROLLBACK;

0 commit comments

Comments
 (0)