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/util.hpp"
16
17BOOST_AUTO_TEST_SUITE( graphml_writer_test )
18
19/*!
20 *
21 * Test node and edge
22 *
23 */
24
25struct ne_cp
26{
27 //! The node contain several properties
28 typedef boost::fusion::vector<float,float,float,double,long int,int,std::string> type;
29
30 //! The data
31 type data;
32
33 //! x property id in boost::fusion::vector
34 static const unsigned int x = 0;
35 //! y property id in boost::fusion::vector
36 static const unsigned int y = 1;
37 //! z property id in boost::fusion::vector
38 static const unsigned int z = 2;
39 //! double_num property id in boost::fusion::vector
40 static const unsigned int double_num = 3;
41 //! long_num property id in boost::fusion::vector
42 static const unsigned int long_num = 4;
43 //! integer property id in boost::fusion::vector
44 static const unsigned int integer = 5;
45 //! string property id in boost::fusion::vector
46 static const unsigned int string = 6;
47 //! total number of properties boost::fusion::vector
48 static const unsigned int max_prop = 7;
49
50 //! get x
51 float & get_x() {return boost::fusion::at_c<x>(data);}
52 //! get y
53 float & get_y() {return boost::fusion::at_c<y>(data);}
54 //! get z
55 float & get_z() {return boost::fusion::at_c<z>(data);}
56 //! get double number
57 double & get_dn() {return boost::fusion::at_c<double_num>(data);}
58 //! get long number
59 long int & get_ln() {return boost::fusion::at_c<long_num>(data);}
60 //! get integer
61 int & get_i() {return boost::fusion::at_c<integer>(data);}
62 //! get string
63 std::string & get_str() {return boost::fusion::at_c<string>(data);}
64
65 //! define attributes names
66 struct attributes
67 {
68 static const std::string name[max_prop];
69 };
70
71 static inline bool noPointers()
72 {
73 return true;
74 }
75
76 //! type of the spatial information
77 typedef float s_type;
78};
79
80// Initialize the attributes strings array
81const std::string ne_cp::attributes::name[] = {"x","y","z","double_num","long_num","integer","string"};
82
83BOOST_AUTO_TEST_CASE( graphml_writer_use)
84{
85 Vcluster<> & v_cl = create_vcluster();
86
87 if (v_cl.getProcessUnitID() != 0)
88 return;
89
90 Graph_CSR<ne_cp,ne_cp> g_csr2;
91
92 // Add 4 vertex and connect
93
94 struct ne_cp n1;
95 n1.get_x() = 1.0;
96 n1.get_y() = 2.0;
97 n1.get_z() = 3.0;
98 n1.get_dn() = 4.0;
99 n1.get_ln() = 5.0;
100 n1.get_i() = 6.0;
101 n1.get_str() = std::string("test");
102 g_csr2.addVertex(n1);
103 n1.get_str() = std::string("tes2");
104 g_csr2.addVertex(n1);
105 n1.get_str() = std::string("test3");
106 g_csr2.addVertex(n1);
107 n1.get_str() = std::string("test4");
108 g_csr2.addVertex(n1);
109 n1.get_str() = std::string("test5");
110
111 g_csr2.addEdge(0,1,n1);
112 n1.get_str() = std::string("test6");
113 g_csr2.addEdge(2,1,n1);
114 n1.get_str() = std::string("test7");
115 g_csr2.addEdge(3,1,n1);
116 n1.get_str() = std::string("test8");
117 g_csr2.addEdge(2,0,n1);
118 n1.get_str() = std::string("test9");
119 g_csr2.addEdge(3,2,n1);
120
121 // Create a graph ML
122 GraphMLWriter<Graph_CSR<ne_cp,ne_cp>> gv2(g_csr2);
123 gv2.write("test_graph2.graphml");
124
125 // check that match
126
127 bool test = compare("test_graph2.graphml","test_data/test_graph2_test.graphml");
128 BOOST_REQUIRE_EQUAL(true,test);
129
130 //! Create a graph
131
132 CartesianGraphFactory<3,Graph_CSR<ne_cp,ne_cp>> g_factory;
133
134 // Cartesian grid
135 size_t sz[] = {GS_SIZE,GS_SIZE,GS_SIZE};
136
137 // Box
138 Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
139
140 // Boundary conditions, non periodic
141 size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
142
143 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);
144
145 // Create a graph ML
146 GraphMLWriter<Graph_CSR<ne_cp,ne_cp>> gw(g_csr);
147 gw.write("test_graph.graphml");
148
149
150 // check that match
151 test = compare("test_graph.graphml","test_data/test_graph_test.graphml");
152 BOOST_REQUIRE_EQUAL(true,test);
153}
154
155BOOST_AUTO_TEST_SUITE_END()
156
157
158#endif /* GRAPHMLWRITER_UNIT_TESTS_HPP_ */
159