|
| 1 | +/* :file: This file is part of the pgRouting project. |
| 2 | +:copyright: Copyright (c) 2016-2026 pgRouting developers |
| 3 | +:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */ |
| 4 | + |
| 5 | +BEGIN; |
| 6 | + |
| 7 | +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); |
| 8 | +SELECT CASE WHEN min_lib_version('4.0.2') THEN plan(12) ELSE plan(12) END; |
| 9 | + |
| 10 | +CREATE OR REPLACE FUNCTION test(fn TEXT) RETURNS SETOF TEXT AS |
| 11 | +$BODY$ |
| 12 | +DECLARE |
| 13 | + stmt TEXT = 'SELECT * FROM ' || fn; |
| 14 | +BEGIN |
| 15 | + |
| 16 | + RAISE NOTICE '%', stmt; |
| 17 | + RETURN QUERY |
| 18 | + SELECT throws_ok(stmt || $$('edges', 1, -3.5)$$); |
| 19 | + |
| 20 | + RETURN QUERY |
| 21 | + SELECT throws_ok(stmt || $$('edges', 1, -3.5)$$, |
| 22 | + 'XX000', $$Negative value found on 'distance'$$, fn || ': Negative distance throws'); |
| 23 | + |
| 24 | + RETURN QUERY |
| 25 | + SELECT lives_ok(stmt || $$('edges', 1, 0)$$, fn || ': 0 is ok'); |
| 26 | +END; |
| 27 | +$BODY$ |
| 28 | +LANGUAGE plpgsql; |
| 29 | + |
| 30 | +CREATE OR REPLACE FUNCTION test_function() RETURNS SETOF TEXT AS |
| 31 | +$BODY$ |
| 32 | +BEGIN |
| 33 | + |
| 34 | + PREPARE edges AS |
| 35 | + SELECT id, source, target, cost FROM edges; |
| 36 | + |
| 37 | + PREPARE points AS |
| 38 | + SELECT pid, edge_id, fraction, side from pointsOfInterest; |
| 39 | + |
| 40 | + RETURN QUERY |
| 41 | + SELECT test('pgr_drivingDistance'); |
| 42 | + RETURN QUERY |
| 43 | + SELECT test('pgr_primDD'); |
| 44 | + RETURN QUERY |
| 45 | + SELECT test('pgr_kruskalDD'); |
| 46 | + |
| 47 | + RETURN QUERY |
| 48 | + SELECT throws_ok($$SELECT * FROM pgr_withPointsDD('edges', 'points', 1, -3.5)$$); |
| 49 | + |
| 50 | + RETURN QUERY |
| 51 | + SELECT throws_ok($$SELECT * FROM pgr_withPointsDD('edges', 'points', 1, -3.5)$$, |
| 52 | + 'XX000', $$Negative value found on 'distance'$$, 'wpDD: Negative distance throws'); |
| 53 | + |
| 54 | + -- distance 0 do not throw |
| 55 | + |
| 56 | + RETURN QUERY |
| 57 | + SELECT lives_ok($$SELECT * FROM pgr_withPointsDD('edges', 'points', 1, 0)$$, 'wpDD: 0 is ok'); |
| 58 | +END; |
| 59 | +$BODY$ |
| 60 | +LANGUAGE plpgsql; |
| 61 | + |
| 62 | +SELECT test_function(); |
| 63 | + |
| 64 | +SELECT finish(); |
| 65 | +ROLLBACK; |
0 commit comments