A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spectrum-test.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  * Copyright (c) 2011 CTTC
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program 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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Nicola Baldo <nbaldo@cttc.es>
20  * part of the code copied from test.h
21  */
22 
23 #include <ns3/test.h>
24 #include <ns3/spectrum-value.h>
25 
26 
40 #define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL(actual, expected, tol, msg) \
41  NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL_INTERNAL (actual, expected, tol, msg, __FILE__, __LINE__)
42 
43 
47 #define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL_INTERNAL(actual, expected, tol, msg, file, line) \
48  do \
49  { \
50  Bands::const_iterator i = (actual).Begin (); \
51  Bands::const_iterator j = (expected).Begin (); \
52  uint32_t k = 0; \
53  while (i != (actual).End () && j != (expected).End ()) \
54  { \
55  if ((i->fl > j->fl + (tol)) || (i->fl < j->fl - (tol)) \
56  || (i->fc > j->fc + (tol)) || (i->fc < j->fc - (tol)) \
57  || (i->fh > j->fh + (tol)) || (i->fh < j->fh - (tol))) \
58  { \
59  ASSERT_ON_FAILURE; \
60  std::ostringstream indexStream; \
61  indexStream << "[" << k << "]"; \
62  std::ostringstream msgStream; \
63  msgStream << (msg); \
64  std::ostringstream actualStream; \
65  actualStream << i->fl << " <-- " << i->fc << " --> " << i->fh; \
66  std::ostringstream expectedStream; \
67  expectedStream << j->fl << " <-- " << j->fc << " --> " << j->fh; \
68  ReportTestFailure (std::string (# actual) + indexStream.str () + " == " + std::string (# expected) + indexStream.str (), \
69  actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
70  CONTINUE_ON_FAILURE; \
71  } \
72  ++i; \
73  ++j; \
74  ++k; \
75  } \
76  if (i != (actual).End () || j != (expected).End ()) \
77  { \
78  std::ostringstream msgStream; \
79  msgStream << (msg); \
80  std::ostringstream actualStream; \
81  actualStream << (i != (actual).End ()); \
82  std::ostringstream expectedStream; \
83  expectedStream << (j != (expected).End ()); \
84  ReportTestFailure ("Bands::iterator == End ()", \
85  actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
86  } \
87  } \
88  while (false); \
89 
90 
104 #define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
105  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL (actual, expected, tol, msg, __FILE__, __LINE__)
106 
107 
111 #define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL(actual, expected, tol, msg, file, line) \
112  do \
113  { \
114  Values::const_iterator i = (actual).ConstValuesBegin (); \
115  Values::const_iterator j = (expected).ConstValuesBegin (); \
116  uint32_t k = 0; \
117  while (i != (actual).ConstValuesEnd () && j != (expected).ConstValuesEnd ()) \
118  { \
119  if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
120  { \
121  ASSERT_ON_FAILURE; \
122  std::ostringstream indexStream; \
123  indexStream << "[" << k << "]"; \
124  std::ostringstream msgStream; \
125  msgStream << msg; \
126  std::ostringstream actualStream; \
127  actualStream << actual; \
128  std::ostringstream expectedStream; \
129  expectedStream << expected; \
130  ReportTestFailure (std::string (# actual) + indexStream.str () + " == " + std::string (# expected) + indexStream.str (), \
131  actualStream.str (), expectedStream.str (), msgStream.str (), file, line); \
132  CONTINUE_ON_FAILURE; \
133  } \
134  ++i; \
135  ++j; \
136  ++k; \
137  } \
138  if (i != (actual).ConstValuesEnd () || j != (expected).ConstValuesEnd ()) \
139  { \
140  std::ostringstream msgStream; \
141  msgStream << (msg); \
142  std::ostringstream actualStream; \
143  actualStream << (i != (actual).ConstValuesEnd ()); \
144  std::ostringstream expectedStream; \
145  expectedStream << (j != (expected).ConstValuesEnd ()); \
146  ReportTestFailure ("Values::const_iterator == ConstValuesEnd ()", \
147  actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
148  } \
149  } \
150  while (false); \
151 
152 
153 
154