Skip to content

Commit ea0605f

Browse files
committed
(pgtap/separateTouching) Unit tests for function separateTouching
1 parent 5361ae7 commit ea0605f

File tree

8 files changed

+564
-0
lines changed

8 files changed

+564
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
21+
22+
SELECT CASE WHEN min_version('3.8.0') THEN plan(6) ELSE plan(1) END;
23+
24+
CREATE TABLE grid(
25+
id serial NOT NULL primary key,
26+
dir text,
27+
the_geom geometry
28+
);
29+
30+
-- creating the grid geometry
31+
INSERT INTO grid(dir, the_geom)
32+
SELECT
33+
CASE WHEN s1 % 2 = 0 THEN 'FT' ELSE 'TF' END,
34+
ST_AsTexT(ST_MakeLine(ST_MakePoint(1,s1), ST_MakePoint(6,s1)))
35+
FROM (SELECT generate_series(1,6) AS s1) AS foo
36+
37+
UNION ALL
38+
39+
SELECT
40+
CASE WHEN s1 % 2 = 0 THEN 'FT' ELSE 'TF' END,
41+
ST_AsTexT(ST_MakeLine(ST_MakePoint(s1,1), ST_MakePoint(s1,6)))
42+
FROM (SELECT generate_series(1,6) AS s1) AS foo;
43+
44+
45+
CREATE OR REPLACE FUNCTION issue_test()
46+
RETURNS SETOF TEXT AS
47+
$BODY$
48+
BEGIN
49+
50+
IF NOT min_version('3.8.0') THEN
51+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
52+
RETURN;
53+
END IF;
54+
55+
RETURN QUERY
56+
SELECT is((SELECT count(*)::INTEGER FROM grid), 12, 'There are 12 original edges');
57+
58+
CREATE TABLE grid_r AS
59+
SELECT *, NULL::INTEGER source, NULL::INTEGER target, NULL::TEXT dir
60+
FROM pgr_separateTouching('SELECT id, the_geom AS geom FROM grid', 0.001);
61+
62+
RETURN QUERY
63+
SELECT has_total_edges_vertices('grid_r', 20, 20);
64+
65+
RETURN QUERY
66+
SELECT set_eq(
67+
'SELECT id, count(*) FROM grid_r GROUP BY id ORDER BY id',
68+
'VALUES (1,5),(6,5),(7,5),(12,5)',
69+
'For each original edge there are 5 subedges');
70+
71+
-- set the source information
72+
UPDATE grid_r AS e
73+
SET source = rv.id
74+
FROM tmp_rv rv
75+
WHERE ST_StartPoint(e.geom) = rv.geom;
76+
77+
-- set the target information
78+
UPDATE grid_r AS e
79+
SET target = rv.id
80+
FROM tmp_rv rv
81+
WHERE ST_EndPoint(e.geom) = rv.geom;
82+
83+
-- se the dir
84+
UPDATE grid_r AS e
85+
SET dir = grid.dir
86+
FROM grid
87+
WHERE grid.id = e.id;
88+
89+
RETURN QUERY
90+
SELECT is(
91+
(SELECT DISTINCT count(*)::INTEGER FROM grid GROUP BY dir),
92+
6, '6 is the count of different TF and FT in grid');
93+
RETURN QUERY
94+
SELECT is(
95+
(SELECT DISTINCT count(*)::INTEGER FROM grid_r GROUP BY dir),
96+
10, '10 is the count of different TF and FT in grid_r (4*5)');
97+
98+
END;
99+
$BODY$ LANGUAGE plpgsql;
100+
101+
SELECT issue_test();
102+
103+
SELECT finish();
104+
ROLLBACK;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
20+
21+
SELECT CASE WHEN min_version('3.8.0') THEN plan(2) ELSE plan(1) END;
22+
23+
CREATE TABLE i1009 (
24+
gid serial,
25+
geom geometry(LineString, 25831)
26+
);
27+
28+
INSERT INTO i1009(geom) VALUES
29+
('0102000020E764000008000000F281433F6B731A41C84583B869855141592275DD14731A41C89C7A7D73855141B3E5D70CD3721A4164B5681680855141BFC2A67BBE721A419A3856BE8585514137F861B0A1721A41D72C1EC58F855141D87C445995721A413DC21EB6968551416D2458939D721A41DFF4EFE89D85514137F861B0A1721A411578DD90A3855141'),
30+
('0102000020E76400000900000065D6DA5A51701A410D5914A88B855141DA9E3C70E5701A4106E8394987855141ADE2BBDC85711A415E9B857C85855141C32F009B0D721A416B2643758485514150B2FF8D78721A41A8C313B784855141BFC2A67BBE721A419A3856BE85855141930626E85E731A4135FA4C92888551414E90077728741A418D04908A90855141A5E6108797741A41F399907B97855141');
31+
32+
CREATE OR REPLACE FUNCTION issue_test()
33+
RETURNS SETOF TEXT AS
34+
$BODY$
35+
BEGIN
36+
37+
IF NOT min_version('3.8.0') THEN
38+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
39+
RETURN;
40+
END IF;
41+
42+
CREATE TABLE i1009_r AS
43+
SELECT *
44+
FROM pgr_separateTouching('SELECT gid AS id, geom FROM i1009');
45+
46+
RETURN QUERY
47+
SELECT has_total_edges_vertices('i1009_r', 0, 0);
48+
49+
END;
50+
$BODY$ LANGUAGE plpgsql;
51+
52+
SELECT issue_test();
53+
SELECT finish();
54+
ROLLBACK;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
20+
21+
SELECT CASE WHEN min_version('3.8.0') THEN plan(2) ELSE plan(1) END;
22+
23+
CREATE TABLE i1074(
24+
id serial PRIMARY KEY,
25+
the_geom geometry(LineString, 4326)
26+
);
27+
28+
INSERT INTO i1074(the_geom) VALUES
29+
('SRID=4326;LineString (0 0, 2 1)'),
30+
('SRID=4326;LineString (0 2, 2 1)'),
31+
('SRID=4326;LineString (2 1, 5 1)'),
32+
('SRID=4326;LineString (1 2, 1 0)'),
33+
('SRID=4326;LineString (3 2, 3 0)'),
34+
('SRID=4326;LineString (4 2, 4 0)'),
35+
('SRID=4326;LineString (5 2, 5 0)');
36+
37+
38+
CREATE OR REPLACE FUNCTION issue_test()
39+
RETURNS SETOF TEXT AS
40+
$BODY$
41+
BEGIN
42+
43+
IF NOT min_version('3.8.0') THEN
44+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
45+
RETURN;
46+
END IF;
47+
48+
CREATE TABLE i1074_r AS
49+
SELECT *
50+
FROM pgr_separateTouching('SELECT id, the_geom AS geom FROM i1074');
51+
52+
RETURN QUERY
53+
SELECT has_total_edges_vertices('i1074_r', 2, 3);
54+
55+
END;
56+
$BODY$ LANGUAGE plpgsql;
57+
58+
SELECT issue_test();
59+
SELECT finish();
60+
ROLLBACK;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
20+
21+
SELECT CASE WHEN min_version('3.8.0') THEN plan(2) ELSE plan(1) END;
22+
23+
CREATE TABLE i1336(
24+
id serial NOT NULL PRIMARY KEY,
25+
the_geom geometry(LineString, 2154)
26+
);
27+
28+
29+
INSERT INTO i1336(the_geom)
30+
VALUES
31+
('SRID=2154;LineString (843731.96837530436459929 6520224.37815147917717695, 843720.94724064960610121 6520301.25479774083942175, 843720.39054300379939377 6520305.10738470777869225, 843720.05595255247317255 6520307.44336138013750315)'),
32+
('SRID=2154;LineString (843681.62641362368594855 6520255.06193162966519594, 843726.45216981507837772 6520262.85580295417457819)'),
33+
('SRID=2154;LineString (840244.02465303440112621 6519477.50229732040315866, 840223.44937284057959914 6519479.99790611304342747, 840211.45880026079248637 6519479.72390817571431398, 840199.53777986904606223 6519474.36406740732491016, 840190.58289291337132454 6519464.75101129896938801, 840181.41248250298667699 6519451.97837869636714458, 840170.42565293482039124 6519434.3100799722597003, 840168.55425586295314133 6519430.80164159927517176, 840151.01772376440931112 6519396.24404330458492041, 840139.96531795407645404 6519372.58710443042218685, 840138.63576878234744072 6519367.48039372358471155, 840146.19430478441063315 6519303.77102805394679308, 840150.080136300297454 6519274.91238123551011086, 840119.29845047416165471 6519150.59983278997242451, 840117.11253627086989582 6519135.32088061515241861, 840114.83395825664047152 6519129.54824385419487953, 840108.43866820889525115 6519120.18260038271546364, 840107.31546254467684776 6519117.61322824936360121, 840099.29079487535636872 6519102.64529608283191919)'),
34+
('SRID=2154;LineString (840225.44422620115801692 6519369.90784595627337694, 840164.1949518381152302 6519407.88627272564917803, 840153.53890225966461003 6519408.40932532399892807, 840127.25395868462510407 6519400.12230102065950632, 840102.82493207952938974 6519361.2863945122808218, 840094.13878045929595828 6519332.39617275167256594)');
35+
36+
37+
CREATE OR REPLACE FUNCTION issue_test()
38+
RETURNS SETOF TEXT AS
39+
$BODY$
40+
BEGIN
41+
42+
IF NOT min_version('3.8.0') THEN
43+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
44+
RETURN;
45+
END IF;
46+
47+
CREATE TABLE i1336_r AS
48+
SELECT *
49+
FROM pgr_separateTouching('SELECT id, the_geom AS geom FROM i1336', 0.1);
50+
51+
RETURN QUERY
52+
SELECT has_total_edges_vertices('i1336_r', 2, 3);
53+
54+
END;
55+
$BODY$ LANGUAGE plpgsql;
56+
57+
SELECT issue_test();
58+
SELECT finish();
59+
ROLLBACK;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
20+
21+
SELECT CASE WHEN min_version('3.8.0') THEN plan(2) ELSE plan(1) END;
22+
23+
CREATE TABLE i1882
24+
(
25+
way_id bigint not null,
26+
geom geometry(LineString, 3857)
27+
);
28+
29+
INSERT INTO i1882 (way_id, geom) VALUES
30+
(232581694, '0102000020110F0000220000009433D64721A31D41B71925D407E05941CA5C010F95A71D41E806C9FE93DF594144DFFA7E37A81D4116054AFE15DF59412FC795CFE9931D41FA51F971E1DE5941112565E3717D1D41E120556047DE594145740FF7706E1D41248032921DDE594109DD8A0660591D4188ADA23B21DE5941743A3AEFCF2A1D4125F22DA4B7DE5941F8B01B00231B1D41528D50CC14DF5941ECB65A01F2E91C4197E88847FDE059418E37E68E57D01C41E67EA13ADAE15941710BF1A26DC31C412C33780485E25941F7F28B0830BC1C41BC156B6B2DE3594120B360A5C4B51C4130634511F6E3594167337B1314A91C4101B27B13C7E45941EC1B629A606F1C41FE1EB436F7E65941B7125E1903531C4185DA09BC58E85941414F3531060C1C41E383E15CDCEB5941AABED32B9BED1B41D4CBC45F43EC59418D4AC7D72BC01B41D55C090688ED5941448C33AB37941B4196CA561EA2EE594109E0467ABF5D1B41294ED4590AF05941BC4397399DA115412BD8175E7D365A4190A7AA298E0E084174E0C098549B5A417795433D9E44E340400372503DFE5A41AD0742F3E7D6D840F12ECE3D1A075B41883E6A7B29FAD1401C27686851065B4177B8CF3B9971AD4060069FD1020E5B4168F25B08BACE94C05B3E576CB00E5B412244441B6985CBC07886598F2C155B41C4D5FBAB28FCD2C09D89F57E12175B4104B09A0ED961D4C0E94C181D27165B413E1C299817FCD4C0D6596A705C155B412A71001290F1D5C05E83CC1105165B41'),
31+
(32340204, '0102000020110F00001D0000005266A5CE8561DEC08801A9D64F2A5B411DFAF6129967DEC0A6F1E0D31A2A5B41432D06F12149DEC020B0BEA4E9295B41A52550F2785EDCC013F8002646285B41DFDCE355A4DFDAC056B5158E70265B41214ACF4BEEB0D9C023ED392418245B41BC4EE68326F0D6C0A49C91CBD81C5B41A55CE1165295D5C0E4B51FDEB1195B41A2F4005882A2D3C0C8689A0335175B413785A1458497CBC09B8E43D50D155B41118AE4431EE795C0CF22EB4A700E5B415BFBB1923CB0AC40371606DFD30D5B41274251C536F8D140746B5B5E23065B41C11B581767BAD840A00531E8E7065B414AAF77DE331AE3407DD49539D9FD5A411EEE0D27F0BD07419E0114DF4B995A4125703ACEDA8115419B17AAED8F345A41B1DD9832E45A1B41740471F8E9EF59415A4801D5DC931B41E8FD638879EE5941D32AE153C0BD1B41159B8836FCEC59415904666AC2F01B410C8D3E9E8BEB5941805E426577061C41549EE739B3EA5941022067606F0B1C41ED54E76F39EA59416242BB9CF70D1C4101DA8D65DAE95941A42209C23E0F1C41423E138B5EE959412AB9EF37E30D1C41A193C58E77E8594118B33C0F470D1C41407A33ED7EE759413B399393960E1C41BCFDDAA914E759410821003052121C4144407AF507E75941'),
32+
(96109913, '0102000020110F000016000000EEBCF0195538FFC04781F75FB0C95B41B592B413563DFFC0576352A6C2C95B41B8519910CA7EFFC070460384D1CA5B41BA2363B20988FFC0F399036F50CB5B4173D98997E869FFC098647FED39CC5B41449136033266FFC043AB6DFC4BCD5B41EF3C6D000079FFC0215C277AAECE5B41ABE26251547BFFC049C2BC1FC9CF5B410F22D9BE03C1FEC0B81BAF51A5D45B41BB767E123CC0FDC0B800FE3D88D55B4132E6E38CF021EBC0BAF4B35EF1C15B41C7435AB05FC1154125BF22CF6A385A41EEB58EB69A601B41F95331BA2AF05941B9A3FF7592941B413F1AA7B5CAEE59413D652473C0B51B41C36F710868ED594187A32BA032F11B41ACA50A0A99EB5941B01A7BD0BC061C410D4D2DC8B8EA59415C65DC64EF0B1C411A182F473CEA5941C826FCC96D0E1C4155D621A8DBE95941FB018622A90F1C417BC9E5305EE959412546E99D6B0D1C414F0032F704E7594147DB1BB1C40B1C41B3B451B9BDE65941'),
33+
(96053700, '0102000020110F0000180000007C369C66FFAB1541BB413AAD397D59412E41BF8912AD15417BF5CECD497D594135D0591C48B115415E816474667D59413F16AA26A8C415418C509310247E59419ADE2459ECC61541398A43DE517E59415BAB10E3B3C615412305F87DA17E59419E9EB23CE4A21541EF1FC8179581594160020966AE591541F31C9741098859418F931C496E1815419BA31942B287594126DB1669D2701441CE8E90D7438B594105FBB8E7C92912419A6E3CD654BC59411DCFD46255111241DAD7D86A6AD65941B9E72CD1C0451241EC610135FDB55A41964DE61FFF1BEBC0BFDD4ADB03C25B4135630C5843BAFDC07F4C3A04B8D55B412030F64EE8CAFEC090D49588B7D45B41C18E18E6727CFFC0BAAC6468CCCF5B4119F31B635C7AFFC08AFE6BFBACCE5B419A0BF7C50368FFC073BE3E664CCD5B4175E38DEE256CFFC0E406357C3ACC5B41D2CF18472889FFC06FE8A4E250CB5B411823F594087FFFC06595BFBCD0CA5B41003FA6D6DB3DFFC0A2BEA361C1C95B41EEBCF0195538FFC04781F75FB0C95B41');
34+
35+
CREATE OR REPLACE FUNCTION issue_test()
36+
RETURNS SETOF TEXT AS
37+
$BODY$
38+
BEGIN
39+
40+
IF NOT min_version('3.8.0') THEN
41+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
42+
RETURN;
43+
END IF;
44+
45+
CREATE TABLE i1882_r AS
46+
SELECT *
47+
FROM pgr_separateTouching('SELECT way_id AS id, geom AS geom FROM i1882', 0.0001);
48+
49+
RETURN QUERY
50+
SELECT has_total_edges_vertices('i1882_r', 0, 0);
51+
52+
END;
53+
$BODY$ LANGUAGE plpgsql;
54+
55+
SELECT issue_test();
56+
SELECT finish();
57+
ROLLBACK;
58+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2025 pgRouting developers
4+
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+
BEGIN;
20+
21+
SELECT CASE WHEN min_version('3.8.0') THEN plan(2) ELSE plan(1) END;
22+
23+
CREATE TABLE i280 (id INTEGER, the_geom geometry(linestring) );
24+
INSERT INTO i280 VALUES
25+
(1, 'linestring(0 0, 10 10)'::geometry),
26+
(2, 'linestring(2 0, 8 10)'::geometry);
27+
28+
CREATE OR REPLACE FUNCTION issue_test()
29+
RETURNS SETOF TEXT AS
30+
$BODY$
31+
BEGIN
32+
33+
IF NOT min_version('3.8.0') THEN
34+
RETURN QUERY SELECT skip(1, 'pgr_separateTouching new on 3.8.0');
35+
RETURN;
36+
END IF;
37+
38+
CREATE TABLE i280_r AS
39+
SELECT *
40+
FROM pgr_separateTouching('SELECT id, the_geom AS geom FROM i280', 0.001);
41+
42+
RETURN QUERY
43+
SELECT has_total_edges_vertices('i280_r', 0, 0);
44+
45+
END;
46+
$BODY$ LANGUAGE plpgsql;
47+
48+
SELECT issue_test();
49+
SELECT finish();
50+
ROLLBACK;

0 commit comments

Comments
 (0)