-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_graph_reduce.m
35 lines (32 loc) · 1.1 KB
/
test_graph_reduce.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% Tests for graph_reduce
%% Test: no_ext_nodes
G = [2, -1, -1; -1, 2, -1; -1, -1, 2];
is_ext_node = [0, 0, 0];
out = graph_reduce(G, is_ext_node);
assert(isequal(out.G, []));
assert(isequal(out.removed_nodes, [1, 2, 3]));
assert(isequal(out.new_nodes, []));
assert(isequal(out.is_ext_node, []));
%% Test: dangling_network
G = [1, -1, 0, 0; -1 2 -1 0; 0, -1, 2, -1; 0, 0, -1, 1];
is_ext_node = [1, 1, 0, 0];
out = graph_reduce(G, is_ext_node);
assert(isequal(out.G, [1, -1 0; -1, 2, -1; 0, -1, 1]));
assert(isequal(out.removed_nodes, 4));
assert(isequal(out.new_nodes, [1, 2, 3]));
assert(isequal(out.is_ext_node, [1, 1, 0]));
%% Test: twoconn_component_artnodes
G = [
1, -1, 0, 0, 0, 0;
-1, 4, -1, -1, -1, 0;
0, -1, 2, 0, -1, 0;
0, -1, 0, 2, -1, 0;
0, -1, -1, -1, 4, -1;
0, 0, 0, 0, -1, 1;
];
is_ext_node = [1, 0, 0, 0, 0, 1];
out = graph_reduce(G, is_ext_node);
assert(isequal(out.G, [1, -1, 0, 0; -1, 3, -2, 0; 0, -2, 3, -1; 0, 0, -1, 1]));
assert(isequal(out.removed_nodes, [3, 4]));
assert(isequal(out.new_nodes, [1, 2, 5, 6]));
assert(isequal(out.is_ext_node, [1, 0, 0, 1]));