File: metis_graph_test.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (126 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function metis_graph_test
%METIS_GRAPH_TEST tests the metis_graph installation
% Your current directory must be dimacs10/
%
% Example
%
%   metis_graph_test
%
% See also metis_graph_read, metis_graph_install

% DIMACS10, Copyright (c) 2011, Timothy A Davis. All Rights Reserved.
% SPDX-License-Identifier: BSD-3-clause

%-------------------------------------------------------------------------------
% tests with valid graphs
%-------------------------------------------------------------------------------

graphs = {
'fig8a.graph'
'fig8b.graph'
'fig8c.graph'
'fig8d.graph'
'adjnoun.graph'
'ilp_test.graph'
'multi.graph'
} ;

clf ;

for i = 1:length (graphs)
    fprintf ('\n----------------------------METIS graph %s :\n', graphs {i}) ;
    [A w fmt] = metis_graph_read (graphs {i}) ;
    k = size (w, 2) ;
    fprintf ('fmt: %3d : ', fmt) ;
    switch fmt
        case {0, 100}
            fprintf ('no node weights, no edge weights.\n') ;
        case 1
            fprintf ('no node weights, has edge weights.\n') ;
        case 10
            fprintf ('has %d node weight(s) per node, no edge weights.\n', k) ;
        case 11
            fprintf ('has %d node weight(s) per node, has edge weights.\n', k) ;
    end
    if (fmt == 100)
        fprintf ('DIMACS10 extension: may have self-edges and multiple\n') ;
        fprintf ('edges.  A(i,j) is the # of edges (i,j)\n') ;
    else
        fprintf ('No self-edges and no multiple edges present in the graph.\n');
    end
    subplot (2,4,i) ;
    spy (A) ;
    if (size (A,1) < 10)
        A = full (A) ;
        display (A) ;
    end
    title (graphs {i}) ;
    if (size (w,2) > 0)
        display (w) ;
    end
end

%-------------------------------------------------------------------------------
% error testing with invalid graphs or invalid usage
%-------------------------------------------------------------------------------

err = 0 ;
bad_graphs = {
'nosuchfile.graph'
'bad1.graph'
'bad2.graph'
'bad3.graph'
'bad4.graph'
'bad5.graph'
'bad6.graph'
'bad7.graph'
'bad8.graph'
'bad9.graph'
} ;

fprintf ('\nTesting error handling (errors and warnings are expected):\n') ;
lastwarn ('') ;
for i = 1:length (bad_graphs)
    fprintf ('%-20s : ', bad_graphs {i}) ;
    try
        [A w fmt] = metis_graph_read (bad_graphs {i}) ;                     %#ok
        if (isempty (lastwarn))
            err = err + 1 ;
        end
    catch me
        fprintf ('expected error: %s\n', me.message) ;
    end
end

fprintf ('invalid usage        : ') ;
try
    % too few input arguments
    [A w fmt] = metis_graph_read ;                                          %#ok
    err = err + 1 ;
catch me
    fprintf ('expected error: %s\n', me.message) ;
end

fprintf ('invalid usage        : ') ;
try
    % too many output arguments
    [i j x w fmt gunk] = metis_graph_read_mex ('fig8a.graph') ;             %#ok
    err = err + 1 ;
catch me
    fprintf ('expected error: %s\n', me.message) ;
end

fprintf ('invalid usage        : ') ;
try
    % invalid input
    [i j x w fmt] = metis_graph_read_mex (0) ;                              %#ok
    err = err + 1 ;
catch me
    fprintf ('expected error: %s\n', me.message) ;
end

if (err > 0)
    error ('%d errors not caught!', err) ;
end

fprintf ('\nAll tests passed.\n') ;