Permalink
Browse files

Fixed bug with root vertex for mst_prim and added regression test

  • Loading branch information...
1 parent ca8170d commit 7357bcf88dfd140ee15e48810b655b24011ef9ca David F. Gleich committed Nov 25, 2009
Showing with 24 additions and 1 deletion.
  1. +2 −1 mst_prim.m
  2. +1 −0 test/test_main.m
  3. +21 −0 test/test_mst_prim.m
View
@@ -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;
View
@@ -10,5 +10,6 @@
test_examples
% test_dijkstra % required for floydwarshall
test_floydwarshall
+test_mst_prim
end
View
@@ -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

0 comments on commit 7357bcf

Please sign in to comment.