Debian Codegraph @

testsuite/unittests/catch/test_ag.cc

raw
1 /*
2 * This file is part of MUSIC.
3 * Copyright (C) 2008, 2009 INCF
4 *
5 * MUSIC is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MUSIC is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
19 #define CATCH_CONFIG_NO_VARIADIC_MACROS
20 #include "music/application_graph.hh"
21 #include <string>
22
23 #include "catch.hpp"
24 /*#define CATCH_CONFIG_RUNNER
25 #include <mpi.h>
26 int main( int argc, char* argv[] )
27 {
28 MPI_Init(&argc, &argv);
29
30 int result = Catch::Session().run( argc, argv );
31
32 MPI_Finalize();
33
34 return result;
35 }*/
36 using namespace MUSIC;
37 typedef AGraph<std::string, char> T_AGraph;
38 typedef ANode<std::string, char> T_ANode;
39 typedef AEdge<std::string, char> T_AEdge;
40
41 class TC_AGraph : public T_AGraph
42 {
43 protected:
44 int c_loops_;
45 public:
46 TC_AGraph() :
47 T_AGraph(1, 2, 1), c_loops_(0)
48 {
49 }
50 ;
51 protected:
52 void
53 handleLoop(T_ANode &x, std::vector<T_AEdge> & path)
54 {
55 c_loops_++;
56 T_AGraph::handleLoop(x, path);
57 }
58 void
59 reset()
60 {
61 c_loops_ = 0;
62 T_AGraph::reset();
63
64 }
65 };
66
67 TEST_CASE_METHOD(TC_AGraph, "Create AGraph with nAppls = 2; nEdges = 1, color = 1", "[agraph]" )
68 {
69
70 REQUIRE( n_apps_ == 2);
71 REQUIRE( c_apps_ == 0);
72 REQUIRE( n_edges_ == 1);
73 REQUIRE( c_edges_ == 0);
74 REQUIRE( color_ == 1);
75 REQUIRE( nNodes() == c_apps_);
76 REQUIRE(nEdges() == c_edges_);
77 REQUIRE(local_node_color() == color_);
78
79 bool edge_ = 1;
80 std::string data1("node1");
81 std::string data2("node2");
82 addNode(T_ANode(edge_, !edge_, data1), color_);
83 addNode(T_ANode(!edge_, edge_, data2), color_ - 1);
84 SECTION( "TEST TemporalNegotiatorGraph::addNode()", "[agraph]" )
85 {
86 REQUIRE( c_apps_ == 2);
87 }
88
89 T_ANode &node1 = at(color_);
90 T_ANode &node2 = at(color_ - 1);
91 SECTION( "TEST TemporalNegotiatorGraph::at()", "[agraph]" )
92 {
93 REQUIRE( &(node1.data()) == &data1);
94 REQUIRE(&(node2.data()) == &data2);
95 }
96 SECTION( "TEST TemporalNegotiatorGraph::local_node()", "[agraph]" )
97 {
98 T_ANode &lnode = local_node();
99 REQUIRE( &lnode == &node1);
100 }
101
102 SECTION( "TEST TemporalNegotiatorGraph::iterator", "[agraph]" )
103 {
104 iterator it;
105 int k = 1; //nodes are stored in the order according to the color
106 for (it = begin(); it < end(); ++it, ++k)
107 REQUIRE((it->data()[4] - 48) == (k % 2 + 1));
108 }
109
110 T_AEdge &cur_edge = addEdge(T_AEdge(node1, node2, data1[4]));
111 SECTION( "TEST TemporalNegotiatorGraph::addEdge()", "[agraph]" )
112 {
113 REQUIRE( c_edges_ == 1);
114 REQUIRE(&(cur_edge.data()) == &data1[4]);
115 T_ANode::edge_iterator it;
116 int c_edges = 0;
117 for (it = node1.begin_o(); it < node1.end_o(); ++it, ++c_edges)
118 {
119 REQUIRE( &((*it)->pre()) == &node1);
120 REQUIRE( &((*it)->post()) == &node2);
121 }
122 REQUIRE(c_edges == 1);
123 for (it = node2.begin_o(); it < node2.end_o(); ++it)
124 {
125 REQUIRE(false);
126 }
127 for (it = node1.begin_i(); it < node1.end_i(); ++it)
128 {
129 REQUIRE(false);
130 }
131 c_edges = 0;
132 for (it = node2.begin_i(); it < node2.end_i(); ++it, ++c_edges)
133 {
134 REQUIRE( &((*it)->pre()) == &node1);
135 REQUIRE( &((*it)->post()) == &node2);
136 }
137 REQUIRE(c_edges == 1);
138 }
139 SECTION( "TEST TemporalNegotiatorGraph::edge()", "[agraph]" )
140 {
141 T_AEdge tmp_edge = edge(node1, 0);
142 REQUIRE( &tmp_edge.data() == &data1[4]);
143 }
144 std::vector<T_AEdge> path;
145 depthFirst(node1, path);
146 //very poor check
147 SECTION( "TEST TemporalNegotiatorGraph::depthFirst()", "[agraph]" )
148 {
149 REQUIRE(c_loops_ == 0);
150 iterator it;
151 for (it = begin(); it < end(); ++it)
152 REQUIRE(it->visited);
153
154 }
155
156 reset();
157 SECTION( "TEST TemporalNegotiatorGraph::reset()", "[agraph]" )
158 {
159 iterator it;
160 for (it = begin(); it < end(); ++it)
161 REQUIRE_FALSE(it->visited);
162
163 for (it = begin(); it < end(); ++it)
164 REQUIRE_FALSE(it->in_path);
165 }
166
167 }