Classes | Typedefs | Functions
test_indexedgraph.cxx File Reference
#include "WireCellUtil/IndexedGraph.h"
#include "WireCellUtil/Testing.h"
#include <boost/graph/graphviz.hpp>

Go to the source code of this file.

Classes

struct  if_node_t
 
struct  std::hash< if_node_t >
 

Typedefs

typedef std::shared_ptr< int > iptr_t
 
typedef std::shared_ptr< float > fptr_t
 
typedef std::variant< iptr_t, fptr_tif_t
 

Functions

char foo (size_t ind)
 
int main ()
 

Typedef Documentation

typedef std::shared_ptr<float> fptr_t

Definition at line 14 of file test_indexedgraph.cxx.

typedef std::variant<iptr_t, fptr_t> if_t

Definition at line 15 of file test_indexedgraph.cxx.

typedef std::shared_ptr<int> iptr_t

Definition at line 13 of file test_indexedgraph.cxx.

Function Documentation

char foo ( size_t  ind)

Definition at line 8 of file test_indexedgraph.cxx.

9 {
10  return "if"[ind];
11 }
int main ( void  )

Definition at line 45 of file test_indexedgraph.cxx.

46 {
47 
48 
49  std::unordered_map<if_t, int> p2i;
50 
51  typedef IndexedGraph<if_node_t> indexed_graph_t;
52  indexed_graph_t g;
53  if_t one = std::make_shared<int>(42);
54  if_t two = std::make_shared<float>(6.9);
55  if_t tre = std::make_shared<float>(33);
56 
57  p2i[one] = 1;
58  p2i[two] = 2;
59  p2i[tre] = 3;
60 
61  // test variant
62  Assert(1 == tre.index());
63  Assert(*std::get<1>(two) < *std::get<1>(tre));
64  Assert(one < two); // caution: compares against indices first!
65  Assert(*std::get<0>(one) == 42);
66  Assert(nullptr == std::get_if<1>(&one));
67  Assert('i' == foo(0));
68  Assert('f' == foo(1));
69 
70  if_t oneprime = one;
71  Assert(one == oneprime);
72 
73  auto v1 = g.vertex(one);
74  auto v2 = g.vertex(one);
75  Assert(v1 == v2);
76  g.edge(one, two);
77  g.edge(one, two);
78  g.edge(two, one);
79  g.edge(one, tre);
80  auto verts = boost::vertices(g.graph());
81  Assert(verts.second-verts.first == 3);
82 
83  Assert(g.has(oneprime));
84 
85  indexed_graph_t g2(g.graph());
86 
87  for (auto n : g2.neighbors(two)) {
88  Assert(g2.has(n));
89  }
90 
91 
92 
93  std::vector<std::string> names{"one","two","tre"};
94  std::unordered_map<indexed_graph_t::vdesc_t, std::string> ids;
95  for (auto u : boost::make_iterator_range(vertices(g2.graph()))) {
96  ids[u] = names[ids.size()];
97  }
98  boost::default_writer w;
99  boost::write_graphviz(std::cout,
100  g2.graph(),
101  w,w,w,
102  boost::make_assoc_property_map(ids));
103 
104  return 0;
105 
106 }
std::variant< iptr_t, fptr_t > if_t
char foo(size_t ind)
static const double g
Definition: Units.h:145
#define Assert
Definition: Testing.h:7
std::size_t n
Definition: format.h:3399