From 7357bcf88dfd140ee15e48810b655b24011ef9ca Mon Sep 17 00:00:00 2001 From: "David F. Gleich" Date: Wed, 25 Nov 2009 09:42:23 -0800 Subject: [PATCH] Fixed bug with root vertex for mst_prim and added regression test --- mst_prim.m | 3 ++- test/test_main.m | 1 + test/test_mst_prim.m | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/test_mst_prim.m diff --git a/mst_prim.m b/mst_prim.m index a24e52c..1532882 100644 --- a/mst_prim.m +++ b/mst_prim.m @@ -24,11 +24,12 @@ % History: % 2009-05-02: Added example +% 2009-11-25: Fixed bug with target % TODO: Add example if ~exist('full','var') || isempty(full), full=0; end -if ~exist('target','var') || isempty(full), u=1; end +if ~exist('u','var') || isempty(u), u=1; end if isstruct(A), rp=A.rp; ci=A.ci; ai=A.ai; diff --git a/test/test_main.m b/test/test_main.m index 07354e8..dd12019 100644 --- a/test/test_main.m +++ b/test/test_main.m @@ -10,5 +10,6 @@ test_examples % test_dijkstra % required for floydwarshall test_floydwarshall +test_mst_prim end diff --git a/test/test_mst_prim.m b/test/test_mst_prim.m new file mode 100644 index 0000000..1c38ded --- /dev/null +++ b/test/test_mst_prim.m @@ -0,0 +1,21 @@ +function test_mst_prim +msgid = 'gaimc:mst_prim'; +load_gaimc_graph('clr-24-1'); +A(2,3) = 9; A(3,2) = 9; +T = mst_prim(A); % root the tree at vertex +Ttrueijv = [ + 2 8 1 4 6 9 3 5 4 3 7 6 8 1 7 3 + 1 1 2 3 3 3 4 4 5 6 6 7 7 8 8 9 + 4 8 4 7 4 2 7 9 9 4 2 2 1 8 1 2 ]; +Ttrue = sparse(Ttrueijv(1,:), Ttrueijv(2,:), Ttrueijv(3,:), 9,9); +if nnz(T - Ttrue) ~= 0 + error(msgid, 'mst_prim failed'); +end + +load_gaimc_graph('clr-24-1'); +T1 = mst_prim(A); % root the tree at vertex +T2 = mst_prim(A,[],5); +T1T2diff = sparse(9,9); T1T2diff(2,3) = 8; T1T2diff(1,8) = -8; +if nnz(triu(T1-T2)-T1T2diff) ~= 0 + error(msgid, 'mst_prim failed rooted test'); +end