test/graph_test.h
changeset 1026 699c7eac2c6d
parent 1025 c8fa41fcc4a7
child 1027 8b2b9e61d8ce
equal deleted inserted replaced
8:5084435d43f4 9:c9806a845753
    41   }
    41   }
    42 
    42 
    43   template<class Graph>
    43   template<class Graph>
    44   void checkGraphRedNodeList(const Graph &G, int cnt)
    44   void checkGraphRedNodeList(const Graph &G, int cnt)
    45   {
    45   {
    46     typename Graph::RedIt n(G);
    46     typename Graph::RedNodeIt n(G);
    47     for(int i=0;i<cnt;i++) {
    47     for(int i=0;i<cnt;i++) {
    48       check(n!=INVALID,"Wrong red Node list linking.");
    48       check(n!=INVALID,"Wrong red Node list linking.");
    49       check(G.red(n),"Wrong node set check.");
    49       check(G.red(n),"Wrong node set check.");
    50       check(!G.blue(n),"Wrong node set check.");
    50       check(!G.blue(n),"Wrong node set check.");
    51       typename Graph::Node nn = n;
    51       typename Graph::Node nn = n;
    63   }
    63   }
    64 
    64 
    65   template<class Graph>
    65   template<class Graph>
    66   void checkGraphBlueNodeList(const Graph &G, int cnt)
    66   void checkGraphBlueNodeList(const Graph &G, int cnt)
    67   {
    67   {
    68     typename Graph::BlueIt n(G);
    68     typename Graph::BlueNodeIt n(G);
    69     for(int i=0;i<cnt;i++) {
    69     for(int i=0;i<cnt;i++) {
    70       check(n!=INVALID,"Wrong blue Node list linking.");
    70       check(n!=INVALID,"Wrong blue Node list linking.");
    71       check(G.blue(n),"Wrong node set check.");
    71       check(G.blue(n),"Wrong node set check.");
    72       check(!G.red(n),"Wrong node set check.");
    72       check(!G.red(n),"Wrong node set check.");
    73       typename Graph::Node nn = n;
    73       typename Graph::Node nn = n;
   223 
   223 
   224   template <typename Graph>
   224   template <typename Graph>
   225   void checkRedNodeIds(const Graph& G) {
   225   void checkRedNodeIds(const Graph& G) {
   226     typedef typename Graph::RedNode RedNode;
   226     typedef typename Graph::RedNode RedNode;
   227     std::set<int> values;
   227     std::set<int> values;
   228     for (typename Graph::RedIt n(G); n != INVALID; ++n) {
   228     for (typename Graph::RedNodeIt n(G); n != INVALID; ++n) {
   229       check(G.red(n), "Wrong partition");
   229       check(G.red(n), "Wrong partition");
   230       check(values.find(G.id(n)) == values.end(), "Wrong id");
   230       check(values.find(G.id(n)) == values.end(), "Wrong id");
   231       check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
   231       check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
   232       values.insert(G.id(n));
   232       values.insert(G.id(n));
   233     }
   233     }
   236 
   236 
   237   template <typename Graph>
   237   template <typename Graph>
   238   void checkBlueNodeIds(const Graph& G) {
   238   void checkBlueNodeIds(const Graph& G) {
   239     typedef typename Graph::BlueNode BlueNode;
   239     typedef typename Graph::BlueNode BlueNode;
   240     std::set<int> values;
   240     std::set<int> values;
   241     for (typename Graph::BlueIt n(G); n != INVALID; ++n) {
   241     for (typename Graph::BlueNodeIt n(G); n != INVALID; ++n) {
   242       check(G.blue(n), "Wrong partition");
   242       check(G.blue(n), "Wrong partition");
   243       check(values.find(G.id(n)) == values.end(), "Wrong id");
   243       check(values.find(G.id(n)) == values.end(), "Wrong id");
   244       check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
   244       check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
   245       values.insert(G.id(n));
   245       values.insert(G.id(n));
   246     }
   246     }
   302     //   check(map[it] == 12, "Wrong operator[].");
   302     //   check(map[it] == 12, "Wrong operator[].");
   303     // }
   303     // }
   304   }
   304   }
   305 
   305 
   306   template <typename Graph>
   306   template <typename Graph>
   307   void checkGraphRedMap(const Graph& G) {
   307   void checkGraphRedNodeMap(const Graph& G) {
   308     typedef typename Graph::Node Node;
   308     typedef typename Graph::Node Node;
   309     typedef typename Graph::RedIt RedIt;
   309     typedef typename Graph::RedNodeIt RedNodeIt;
   310 
   310 
   311     typedef typename Graph::template RedMap<int> IntRedMap;
   311     typedef typename Graph::template RedNodeMap<int> IntRedNodeMap;
   312     IntRedMap map(G, 42);
   312     IntRedNodeMap map(G, 42);
   313     for (RedIt it(G); it != INVALID; ++it) {
   313     for (RedNodeIt it(G); it != INVALID; ++it) {
   314       check(map[it] == 42, "Wrong map constructor.");
   314       check(map[it] == 42, "Wrong map constructor.");
   315     }
   315     }
   316     int s = 0;
   316     int s = 0;
   317     for (RedIt it(G); it != INVALID; ++it) {
   317     for (RedNodeIt it(G); it != INVALID; ++it) {
   318       map[it] = 0;
   318       map[it] = 0;
   319       check(map[it] == 0, "Wrong operator[].");
   319       check(map[it] == 0, "Wrong operator[].");
   320       map.set(it, s);
   320       map.set(it, s);
   321       check(map[it] == s, "Wrong set.");
   321       check(map[it] == s, "Wrong set.");
   322       ++s;
   322       ++s;
   323     }
   323     }
   324     s = s * (s - 1) / 2;
   324     s = s * (s - 1) / 2;
   325     for (RedIt it(G); it != INVALID; ++it) {
   325     for (RedNodeIt it(G); it != INVALID; ++it) {
   326       s -= map[it];
   326       s -= map[it];
   327     }
   327     }
   328     check(s == 0, "Wrong sum.");
   328     check(s == 0, "Wrong sum.");
   329 
   329 
   330     // map = constMap<Node>(12);
   330     // map = constMap<Node>(12);
   332     //   check(map[it] == 12, "Wrong operator[].");
   332     //   check(map[it] == 12, "Wrong operator[].");
   333     // }
   333     // }
   334   }
   334   }
   335 
   335 
   336   template <typename Graph>
   336   template <typename Graph>
   337   void checkGraphBlueMap(const Graph& G) {
   337   void checkGraphBlueNodeMap(const Graph& G) {
   338     typedef typename Graph::Node Node;
   338     typedef typename Graph::Node Node;
   339     typedef typename Graph::BlueIt BlueIt;
   339     typedef typename Graph::BlueNodeIt BlueNodeIt;
   340 
   340 
   341     typedef typename Graph::template BlueMap<int> IntBlueMap;
   341     typedef typename Graph::template BlueNodeMap<int> IntBlueNodeMap;
   342     IntBlueMap map(G, 42);
   342     IntBlueNodeMap map(G, 42);
   343     for (BlueIt it(G); it != INVALID; ++it) {
   343     for (BlueNodeIt it(G); it != INVALID; ++it) {
   344       check(map[it] == 42, "Wrong map constructor.");
   344       check(map[it] == 42, "Wrong map constructor.");
   345     }
   345     }
   346     int s = 0;
   346     int s = 0;
   347     for (BlueIt it(G); it != INVALID; ++it) {
   347     for (BlueNodeIt it(G); it != INVALID; ++it) {
   348       map[it] = 0;
   348       map[it] = 0;
   349       check(map[it] == 0, "Wrong operator[].");
   349       check(map[it] == 0, "Wrong operator[].");
   350       map.set(it, s);
   350       map.set(it, s);
   351       check(map[it] == s, "Wrong set.");
   351       check(map[it] == s, "Wrong set.");
   352       ++s;
   352       ++s;
   353     }
   353     }
   354     s = s * (s - 1) / 2;
   354     s = s * (s - 1) / 2;
   355     for (BlueIt it(G); it != INVALID; ++it) {
   355     for (BlueNodeIt it(G); it != INVALID; ++it) {
   356       s -= map[it];
   356       s -= map[it];
   357     }
   357     }
   358     check(s == 0, "Wrong sum.");
   358     check(s == 0, "Wrong sum.");
   359 
   359 
   360     // map = constMap<Node>(12);
   360     // map = constMap<Node>(12);