From 395d8a87f6aa68caa7d1910887d6ade234bb4438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:45 +0300 Subject: [PATCH] unit tests --- tests.sql | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests.sql b/tests.sql index 8b2f35c..9d2fa69 100644 --- a/tests.sql +++ b/tests.sql @@ -15,7 +15,7 @@ drop table if exists figures; create table figures (name text, way geometry); insert into figures (name, way) values ('fig3',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0,60 0)')); insert into figures (name, way) values ('fig3-1',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0)')); -insert into figures (name, way) values ('fig5',ST_GeomFromText('LINESTRING(0 39,19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45,63 15,91 0,91 0)')); +insert into figures (name, way) values ('fig5',ST_GeomFromText('LINESTRING(0 39,19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45,63 15,91 0)')); insert into figures (name, way) values ('inflection-1',ST_GeomFromText('LINESTRING(110 24,114 20,133 20,145 15,145 0,136 5,123 7,114 7,111 2)')); -- tables are for manual inspection using, say, qgis @@ -53,9 +53,16 @@ declare vbends geometry[]; vinflections geometry[]; begin + -- fig5 + select detect_bends((select way from figures where name='fig5')) into vbends; + select fix_gentle_inflections(vbends) into vinflections; + perform assert_equals('LINESTRING(0 39,19 52,27 77)', st_astext(vinflections[1])); + perform assert_equals('LINESTRING(19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45)', st_astext(vinflections[2])); + perform assert_equals('LINESTRING(65 75,53 45,63 15,91 0)', st_astext(vinflections[3])); + + -- inflections-1, the example in fix_gentle_inflections docstring select detect_bends((select way from figures where name='inflection-1')) into vbends; select fix_gentle_inflections(vbends) into vinflections; - perform assert_equals(vbends[1], vinflections[1]); -- unchanged perform assert_equals('LINESTRING(114 20,133 20,145 15,145 0,136 5,123 7,114 7)', st_astext(vinflections[2])); perform assert_equals('LINESTRING(123 7,114 7,111 2)', st_astext(vinflections[3]));