torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RouteNodeUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit test for the RouteNode class.
18 
19 #include <boost/test/unit_test.hpp>
21 
22 namespace torc {
23 namespace router {
24 
25 BOOST_AUTO_TEST_SUITE(router)
26 
27 /// \brief Unit test for the RouteNode class.
28 BOOST_AUTO_TEST_CASE(RouteNodeT) {
29  typedef architecture::Tilewire Tilewire;
30  typedef architecture::Arc Arc;
31  // create accessory wires and tiles
36  boost::int32_t cost1 = 4;
37  boost::int32_t cost2 = 5;
38  Arc arc1(tilewire1, tilewire2);
39  Arc arc2(tilewire2, tilewire3);
40 
41 
42  // features tested:
43  // sizeof(RouteNode)
44  BOOST_CHECK_EQUAL(sizeof(RouteNode), sizeof(architecture::Arc) + sizeof(RouteNode*)
45  + (3 * sizeof(boost::int32_t)));
46  BOOST_CHECK_EQUAL(sizeof(RouteNode), 32u);
47 
48  // functions tested:
49  // RouteNode(void);
50  // RouteNode(Tilewire inSource, Tilewire inSink, RouteNodeCost inCost,
51  // RouteNode* inParent);
52  RouteNode* routenode1 = new RouteNode(tilewire1, tilewire2, cost1, cost1, 0, 0);
53  RouteNode* routenode2 = new RouteNode(arc2, cost1, cost1, 1, routenode1);
54  RouteNode* routenode3 = new RouteNode(tilewire3, tilewire4, cost2, cost2, 2, routenode2);
55  RouteNode* routenode4 = new RouteNode();
56  BOOST_CHECK_EQUAL(routenode1 != 0, true);
57  BOOST_CHECK_EQUAL(routenode2 != 0, true);
58  BOOST_CHECK_EQUAL(routenode3 != 0, true);
59  BOOST_CHECK_EQUAL(routenode4 != 0, true);
60 
61  // functions tested:
62  // const Arc& getArc() const;
63  // const Tilewire& getSourceTilewire() const;
64  // const Tilewire& getSinkTilewire() const;
65  // const boost::int32_t getCost() const;
66  // void setCost(boost::int32_t inCost);
67  // RouteNode* getParent() const;
68  // RouteNode* getTop();
69  architecture::Arc arc1t = routenode1->getArc();
70  BOOST_CHECK_EQUAL(arc1t == arc1, true);
71  BOOST_CHECK_EQUAL(routenode2->getSourceTilewire() == tilewire2, true);
72  BOOST_CHECK_EQUAL(routenode2->getSinkTilewire() == tilewire3, true);
73  BOOST_CHECK_EQUAL(routenode3->getCost() == cost2, true);
74  BOOST_CHECK_EQUAL(routenode4->getCost() == 0, true);
75  BOOST_CHECK_EQUAL(routenode3->getPathCost() == cost2, true);
76  routenode4->setCost(42);
77  BOOST_CHECK_EQUAL(routenode4->getCost() == 42, true);
78  BOOST_CHECK_EQUAL(routenode3->getParent() == routenode2, true);
79  BOOST_CHECK_EQUAL(routenode3->getTop() == routenode1, true);
80 
81  // Test the comparison class
83  BOOST_CHECK_EQUAL(compare(routenode1, routenode1), false);
84  BOOST_CHECK_EQUAL(compare(routenode2, routenode3), false);
85  BOOST_CHECK_EQUAL(compare(routenode3, routenode2), true);
86 
87  delete routenode1;
88  delete routenode2;
89  delete routenode3;
90  delete routenode4;
91 }
92 
93 BOOST_AUTO_TEST_SUITE_END()
94 
95 } // namespace router
96 } // namespace torc
const boost::int32_t getPathCost() const
Get the path cost.
Definition: RouteNode.hpp:90
Encapsulation of a tile index in an unsigned 32-bit integer.
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
RouteNode * getParent() const
Get the node's parent.
Definition: RouteNode.hpp:98
Header for the RouteNode class.
Encapsulation of a wire index in an unsigned 16-bit integer.
Binary predicate for comparing RouteNode pointers based on cost.
Definition: RouteNode.hpp:118
const Tilewire & getSinkTilewire() const
Get the sink Tilewire.
Definition: RouteNode.hpp:84
void setCost(boost::int32_t inHeuristicCost)
Set the heuristic node cost.
Definition: RouteNode.hpp:88
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
const Tilewire & getSourceTilewire() const
Get the source Tilewire.
Definition: RouteNode.hpp:82
const Arc & getArc() const
Get the associated Arc.
Definition: RouteNode.hpp:80
RouteNode * getTop()
Return the top node by tracing parent pointers.
Definition: RouteNode.hpp:100
An object that holds an arc and path information for routing.
Definition: RouteNode.hpp:40
BOOST_AUTO_TEST_CASE(NetRouterHeuristicT)
Unit test for the Heuristic.
const boost::int32_t getCost() const
Get the heuristic node cost.
Definition: RouteNode.hpp:86