OpenFPM_io  0.2.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Functions Variables Typedefs
GraphMLWriter_unit_tests.hpp
1 /*
2  * GraphMLWriter_unit_tests.hpp
3  *
4  * Created on: Dec 9, 2014
5  * Author: i-bird
6  */
7 
8 #ifndef GRAPHMLWRITER_UNIT_TESTS_HPP_
9 #define GRAPHMLWRITER_UNIT_TESTS_HPP_
10 
11 #define GS_SIZE 8
12 
13 #include "GraphMLWriter.hpp"
14 #include "Graph/CartesianGraphFactory.hpp"
15 #include "util.hpp"
16 
17 BOOST_AUTO_TEST_SUITE( graphml_writer_test )
18 
19 
25 struct ne_cp
26 {
28  typedef boost::fusion::vector<float,float,float,double,long int,int,std::string> type;
29 
30  typedef typename memory_traits_inte<type>::type memory_int;
31  typedef typename memory_traits_lin<type>::type memory_lin;
32 
34  type data;
35 
37  static const unsigned int x = 0;
39  static const unsigned int y = 1;
41  static const unsigned int z = 2;
43  static const unsigned int double_num = 3;
45  static const unsigned int long_num = 4;
47  static const unsigned int integer = 5;
49  static const unsigned int string = 6;
51  static const unsigned int max_prop = 7;
52 
54  float & get_x() {return boost::fusion::at_c<x>(data);}
56  float & get_y() {return boost::fusion::at_c<y>(data);}
58  float & get_z() {return boost::fusion::at_c<z>(data);}
60  double & get_dn() {return boost::fusion::at_c<double_num>(data);}
62  long int & get_ln() {return boost::fusion::at_c<long_num>(data);}
64  int & get_i() {return boost::fusion::at_c<integer>(data);}
66  std::string & get_str() {return boost::fusion::at_c<string>(data);}
67 
69  struct attributes
70  {
71  static const std::string name[max_prop];
72  };
73 
75  typedef float s_type;
76 };
77 
78 // Initialize the attributes strings array
79 const std::string ne_cp::attributes::name[] = {"x","y","z","double_num","long_num","integer","string"};
80 
81 BOOST_AUTO_TEST_CASE( graphml_writer_use)
82 {
83  Graph_CSR<ne_cp,ne_cp> g_csr2;
84 
85  // Add 4 vertex and connect
86 
87  struct ne_cp n1;
88  n1.get_x() = 1.0;
89  n1.get_y() = 2.0;
90  n1.get_z() = 3.0;
91  n1.get_dn() = 4.0;
92  n1.get_ln() = 5.0;
93  n1.get_i() = 6.0;
94  n1.get_str() = std::string("test");
95  g_csr2.addVertex(n1);
96  n1.get_str() = std::string("tes2");
97  g_csr2.addVertex(n1);
98  n1.get_str() = std::string("test3");
99  g_csr2.addVertex(n1);
100  n1.get_str() = std::string("test4");
101  g_csr2.addVertex(n1);
102  n1.get_str() = std::string("test5");
103 
104  g_csr2.addEdge(0,1,n1);
105  n1.get_str() = std::string("test6");
106  g_csr2.addEdge(2,1,n1);
107  n1.get_str() = std::string("test7");
108  g_csr2.addEdge(3,1,n1);
109  n1.get_str() = std::string("test8");
110  g_csr2.addEdge(2,0,n1);
111  n1.get_str() = std::string("test9");
112  g_csr2.addEdge(3,2,n1);
113 
114  // Create a graph ML
116  gv2.write("test_graph2.graphml");
117 
118  // check that match
119 
120  bool test = compare("test_graph2.graphml","test_graph2_test.graphml");
121  BOOST_REQUIRE_EQUAL(true,test);
122 
124 
125  CartesianGraphFactory<3,Graph_CSR<ne_cp,ne_cp>> g_factory;
126 
127  // Cartesian grid
128  size_t sz[] = {GS_SIZE,GS_SIZE,GS_SIZE};
129 
130  // Box
131  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
132 
133  // Boundary conditions, non periodic
134  size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
135 
136  Graph_CSR<ne_cp,ne_cp> g_csr = g_factory.construct<5,NO_VERTEX_ID,float,2,ne_cp::x,ne_cp::y,ne_cp::z>(sz,box,bc);
137 
138  // Create a graph ML
140  gw.write("test_graph.graphml");
141 
142 
143  // check that match
144  test = compare("test_graph.graphml","test_graph_test.graphml");
145  BOOST_REQUIRE_EQUAL(true,test);
146 }
147 
148 BOOST_AUTO_TEST_SUITE_END()
149 
150 
151 #endif /* GRAPHMLWRITER_UNIT_TESTS_HPP_ */
float & get_x()
get x
float s_type
type of the spatial information
float & get_y()
get y
type data
The data.
std::string & get_str()
get string
float & get_z()
get z
int & get_i()
get integer
double & get_dn()
get double number
boost::fusion::vector< float, float, float, double, long int, int, std::string > type
The node contain several properties.
define attributes names
long int & get_ln()
get long number
static const unsigned int z
z property id in boost::fusion::vector
static const unsigned int x
x property id in boost::fusion::vector
static const unsigned int y
y property id in boost::fusion::vector