00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <mln/util/graph.hh>
00027 #include <iostream>
00028
00029 int main ()
00030 {
00031 using namespace mln;
00032
00033 util::graph g;
00034
00035 g.add_vertices(6);
00036 g.add_edge (0, 1);
00037 g.add_edge (0, 2);
00038 g.add_edge (3, 4);
00039 g.add_edge (4, 5);
00040 g.add_edge (5, 4);
00041 g.add_edge (1, 0);
00042 g.add_edge (5, 3);
00043 g.add_edge (2, 1);
00044
00045
00046
00047 {
00048 unsigned i = 0;
00049 mln_vertex_fwd_iter_(util::graph) v(g);
00050 for_all(v)
00051 mln_assertion(i++ == v.id());
00052 mln_assertion(i != 0);
00053
00054 i = 0;
00055 mln_edge_fwd_iter_(util::graph) e(g);
00056 for_all(e)
00057 mln_assertion(i++ == e.id());
00058 mln_assertion(i != 0);
00059 }
00060 {
00061 unsigned i = g.v_nmax() - 1;
00062 mln_vertex_bkd_iter_(util::graph) v(g);
00063 for_all(v)
00064 mln_assertion(i-- == v.id());
00065 mln_assertion(i != g.v_nmax() - 1);
00066
00067 i = g.e_nmax() - 1;
00068 mln_edge_bkd_iter_(util::graph) e(g);
00069 for_all(e)
00070 mln_assertion(i-- == e.id());
00071 mln_assertion(i != g.e_nmax() - 1);
00072 }
00073
00074
00075 {
00076 mln_vertex_fwd_iter_(util::graph) v(g);
00077 mln_vertex_nbh_edge_fwd_iter_(util::graph) n(v);
00078 for_all(v)
00079 {
00080 unsigned i = 0;
00081 for_all(n)
00082 mln_assertion(i++ == n.index());
00083 mln_assertion(i != 0);
00084 }
00085 }
00086 {
00087 mln_vertex_bkd_iter_(util::graph) v(g);
00088 mln_vertex_nbh_edge_bkd_iter_(util::graph) e(v);
00089 for_all(v)
00090 {
00091 unsigned i = v.nmax_nbh_edges();
00092 for_all(e)
00093 mln_assertion(--i == e.index());
00094 mln_assertion((v.nmax_nbh_edges() == 0 && i == 0) || i != v.nmax_nbh_edges());
00095 }
00096 }
00097
00098 {
00099 mln_edge_fwd_iter_(util::graph) e(g);
00100 mln_edge_nbh_edge_fwd_iter_(util::graph) n(e);
00101 for_all(e)
00102 {
00103 unsigned i = 0;
00104 for_all(n)
00105 ++i;
00106
00107
00108 mln_assertion((i == 0 && e.nmax_nbh_edges() < 2) || i == e.nmax_nbh_edges() - 2);
00109 }
00110 }
00111 {
00112 mln_edge_bkd_iter_(util::graph) e(g);
00113 mln_edge_nbh_edge_bkd_iter_(util::graph) n(e);
00114 for_all(e)
00115 {
00116
00117 unsigned i = e.nmax_nbh_edges();
00118 for_all(n)
00119 --i;
00120
00121
00122 mln_assertion((i == e.nmax_nbh_edges() && e.nmax_nbh_edges() < 2) || i == 2);
00123
00124 }
00125 }
00126
00127 {
00128 mln_vertex_fwd_iter_(util::graph) v(g);
00129 mln_vertex_nbh_vertex_fwd_iter_(util::graph) n(v);
00130 for_all(v)
00131 {
00132 unsigned i = 0;
00133 for_all(n)
00134 ++i;
00135 mln_assertion(i == v.nmax_nbh_vertices());
00136 }
00137 }
00138 {
00139 mln_vertex_bkd_iter_(util::graph) v(g);
00140 mln_vertex_nbh_vertex_bkd_iter_(util::graph) n(v);
00141 for_all(v)
00142 {
00143 unsigned i = v.nmax_nbh_vertices();
00144 for_all(n)
00145 --i;
00146 mln_assertion(i == 0);
00147 }
00148 }
00149 }