Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSoC 2022: Nitish Chauhan Week 11 #256

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions pgtap/circuits/hawickCircuits/edge_cases.pg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BEGIN;

UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost);
SELECT CASE WHEN NOT min_version('3.4.0') THEN plan(1) ELSE plan(10) END;
SELECT CASE WHEN NOT min_version('3.4.0') THEN plan(1) ELSE plan(9) END;

CREATE OR REPLACE FUNCTION edge_cases()
RETURNS SETOF TEXT AS
Expand Down Expand Up @@ -34,17 +34,16 @@ SELECT is_empty('hawickCircuits1', 'Graph with 0 edge and 0 vertex -> Empty row
-- 1 vertex test

PREPARE q2 AS
SELECT id, source, 2 AS target, cost, reverse_cost
SELECT id, source, target, cost, reverse_cost
FROM edge_table
WHERE id = 2;

PREPARE hawickCircuits2 AS
SELECT * FROM pgr_hawickCircuits('q2');
SELECT * FROM pgr_hawickcircuits('q2');

RETURN QUERY
SELECT is_empty('hawickCircuits2', 'One vertex graph can not have circuits -> Empty row is returned');


-- 2 vertices test (connected)

PREPARE q3 AS
Expand All @@ -53,19 +52,19 @@ FROM edge_table
WHERE id = 7;

RETURN QUERY
SELECT set_eq('q3', $$VALUES (7, 3, 7, 1, 1)$$, 'Graph with two connected vertices 3 and 7');
SELECT set_eq('q3', $$VALUES (7, 8, 5, 1, 1)$$, 'Graph with two connected vertices 8 and 5');

PREPARE hawickCircuits3 AS
SELECT * FROM pgr_hawickcircuits('q3');

RETURN QUERY
SELECT set_eq('hawickCircuits3',
$$VALUES
(1, 1, 0, 3, 3, 3, 7, 1, 0),
(2, 1, 1, 3, 3, 7, 7, 1, 1),
(3, 1, 2, 3, 3, 3, -1, 0, 2)
(1, 1, 0, 8, 8, 8, 7, 1, 0),
(2, 1, 1, 8, 8, 5, 7, 1, 1),
(3, 1, 2, 8, 8, 8, -1, 0, 2)
$$,
'Circuit between the vertex 3 and 7');
'Circuit between the vertex 8 and 5');

-- 3 vertices test

Expand All @@ -75,19 +74,19 @@ FROM edge_table
WHERE id <= 2;

RETURN QUERY
SELECT set_eq('q4', $$VALUES (1, 5, 6, 1, 1), (2, 6, 10, -1, 1)$$, 'Graph with three vertices 5, 6 and 10');
SELECT set_eq('q4', $$VALUES (1, 1, 2, 1, 1), (2, 2, 3, -1, 1)$$, 'Graph with three vertices 1, 2 and 3');

PREPARE hawickCircuits4 AS
SELECT * FROM pgr_hawickCircuits('q4');
SELECT * FROM pgr_hawickcircuits('q4');

RETURN QUERY
SELECT set_eq('hawickCircuits4',
$$VALUES
(1, 1, 0, 5, 5, 5, 1, 1, 0),
(2, 1, 1, 5, 5, 6, 1, 1, 1),
(3, 1, 2, 5, 5, 5, -1, 0, 2)
(1, 1, 0, 1, 1, 1, 1, 1, 0),
(2, 1, 1, 1, 1, 2, 1, 1, 1),
(3, 1, 2, 1, 1, 1, -1, 0, 2)
$$,
'Circuit between 5 and 6 expected');
'Circuit between the vertex 1 and 2');

-- 4 vertices test

Expand All @@ -99,33 +98,32 @@ WHERE id IN (3, 5, 9, 16);
RETURN QUERY
SELECT set_eq('q5',
$$VALUES
(5, 10, 11, 1, -1),
(3, 10, 15, -1, 1),
(9, 11, 16, 1, 1),
(16, 15, 16, 1, 1)
(3, 3, 4, -1, 1),
(5, 3, 6, 1, -1),
(9, 6, 9, 1, 1),
(16, 4, 9, 1, 1)
$$,
'Graph with four vertices 10, 11, 16 and 15'
);
'Graph with four vertices 3, 4, 6 and 9');

PREPARE hawickCircuits5 AS
SELECT * FROM pgr_hawickCircuits('q5');

RETURN QUERY
SELECT set_eq('hawickCircuits5',
$$VALUES
(1, 1, 0, 10, 10, 10, 5, 1, 0),
(2, 1, 1, 10, 10, 11, 9, 1, 1),
(3, 1, 2, 10, 10, 16, 16, 1, 2),
(4, 1, 3, 10, 10, 15, 3, 1, 3),
(5, 1, 4, 10, 10, 10, -1, 0, 4),
(6, 2, 0, 11, 11, 11, 9, 1, 0),
(7, 2, 1, 11, 11, 16, 9, 1, 1),
(8, 2, 2, 11, 11, 11, -1, 0, 2),
(9, 3, 0, 15, 15, 15, 16, 1, 0),
(10, 3, 1, 15, 15, 16, 16, 1, 1),
(11, 3, 2, 15, 15, 15, -1, 0, 2)
(1, 1, 0, 3, 3, 3, 5, 1, 0),
(2, 1, 1, 3, 3, 6, 9, 1, 1),
(3, 1, 2, 3, 3, 9, 16, 1, 2),
(4, 1, 3, 3, 3, 4, 3, 1, 3),
(5, 1, 4, 3, 3, 3, -1, 0, 4),
(6, 2, 0, 4, 4, 4, 16, 1, 0),
(7, 2, 1, 4, 4, 9, 16, 1, 1),
(8, 2, 2, 4, 4, 4, -1, 0, 2),
(9, 3, 0, 6, 6, 6, 9, 1, 0),
(10, 3, 1, 6, 6, 9, 9, 1, 1),
(11, 3, 2, 6, 6, 6, -1, 0, 2)
$$,
'Circuit between 10->11->16->15->10, 11->16->11 & 15->16->15 expected');
'Circuit between 3->6->9->4->3, 4->9->4 & 6->9->6 expected');

END;
$BODY$
Expand Down