A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-test.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 * Copyright (c) 2011 CTTC
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Nicola Baldo <nbaldo@cttc.es>
19 * part of the code copied from test.h
20 */
21
22#ifndef SPECTRUM_TEST_H
23#define SPECTRUM_TEST_H
24
25#include <ns3/spectrum-value.h>
26#include <ns3/test.h>
27
28/**
29 * \ingroup spectrum
30 * \defgroup spectrum-test Spectrum module tests
31 */
32
33/**
34 * \ingroup spectrum-tests
35 *
36 * \brief Test if two SpectrumModel instances are equal within a given tolerance.
37 *
38 * This test compares component-by-component the two SpectrumModel
39 * instances; if any pair of components differs by more than the given
40 * tolerance, the test fails.
41 *
42 * \param actual the actual value obtained by the simulator
43 * \param expected the expected value obtained by off-line calculations
44 * \param tol the tolerance
45 * \param msg the message to print if the test fails
46 *
47 */
48#define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL(actual, expected, tol, msg) \
49 do \
50 { \
51 auto i = (actual).Begin(); \
52 auto j = (expected).Begin(); \
53 uint32_t k = 0; \
54 while (i != (actual).End() && j != (expected).End()) \
55 { \
56 if ((i->fl > j->fl + (tol)) || (i->fl < j->fl - (tol)) || (i->fc > j->fc + (tol)) || \
57 (i->fc < j->fc - (tol)) || (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() + \
69 " == " + std::string(#expected) + indexStream.str(), \
70 actualStream.str(), \
71 expectedStream.str(), \
72 msgStream.str(), \
73 (__FILE__), \
74 (__LINE__)); \
75 CONTINUE_ON_FAILURE; \
76 } \
77 ++i; \
78 ++j; \
79 ++k; \
80 } \
81 if (i != (actual).End() || j != (expected).End()) \
82 { \
83 std::ostringstream msgStream; \
84 msgStream << (msg); \
85 std::ostringstream actualStream; \
86 actualStream << (i != (actual).End()); \
87 std::ostringstream expectedStream; \
88 expectedStream << (j != (expected).End()); \
89 ReportTestFailure("Bands::iterator == End ()", \
90 actualStream.str(), \
91 expectedStream.str(), \
92 msgStream.str(), \
93 (__FILE__), \
94 (__LINE__)); \
95 } \
96 } while (false);
97
98/**
99 * \ingroup spectrum-tests
100 *
101 * \brief Test if two SpectrumValue instances are equal within a given tolerance.
102 *
103 * This test compares component-by-component the two SpectrumValue
104 * instances; if any pair of components differs by more than the given
105 * tolerance, the test fails.
106 *
107 * \param actual the actual value obtained by the simulator
108 * \param expected the expected value obtained by off-line calculations
109 * \param tol the tolerance
110 * \param msg the message to print if the test fails
111 *
112 */
113#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
114 do \
115 { \
116 auto i = (actual).ConstValuesBegin(); \
117 auto j = (expected).ConstValuesBegin(); \
118 uint32_t k = 0; \
119 while (i != (actual).ConstValuesEnd() && j != (expected).ConstValuesEnd()) \
120 { \
121 if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
122 { \
123 ASSERT_ON_FAILURE; \
124 std::ostringstream indexStream; \
125 indexStream << "[" << k << "]"; \
126 std::ostringstream msgStream; \
127 msgStream << msg; \
128 std::ostringstream actualStream; \
129 actualStream << actual; \
130 std::ostringstream expectedStream; \
131 expectedStream << expected; \
132 ReportTestFailure(std::string(#actual) + indexStream.str() + \
133 " == " + std::string(#expected) + indexStream.str(), \
134 actualStream.str(), \
135 expectedStream.str(), \
136 msgStream.str(), \
137 __FILE__, \
138 __LINE__); \
139 CONTINUE_ON_FAILURE; \
140 } \
141 ++i; \
142 ++j; \
143 ++k; \
144 } \
145 if (i != (actual).ConstValuesEnd() || j != (expected).ConstValuesEnd()) \
146 { \
147 std::ostringstream msgStream; \
148 msgStream << (msg); \
149 std::ostringstream actualStream; \
150 actualStream << (i != (actual).ConstValuesEnd()); \
151 std::ostringstream expectedStream; \
152 expectedStream << (j != (expected).ConstValuesEnd()); \
153 ReportTestFailure("Values::const_iterator == ConstValuesEnd ()", \
154 actualStream.str(), \
155 expectedStream.str(), \
156 msgStream.str(), \
157 (__FILE__), \
158 (__LINE__)); \
159 } \
160 } while (false);
161
162#endif // SPECTRUM_TEST_H