A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
* SPDX-License-Identifier: GPL-2.0-only
6
*
7
* Author: Nicola Baldo <nbaldo@cttc.es>
8
* part of the code copied from test.h
9
*/
10
11
#ifndef SPECTRUM_TEST_H
12
#define SPECTRUM_TEST_H
13
14
#include <ns3/spectrum-value.h>
15
#include <ns3/test.h>
16
17
/**
18
* @ingroup spectrum
19
* @defgroup spectrum-test Spectrum module tests
20
*/
21
22
/**
23
* @ingroup spectrum-tests
24
*
25
* @brief Test if two SpectrumModel instances are equal within a given tolerance.
26
*
27
* This test compares component-by-component the two SpectrumModel
28
* instances; if any pair of components differs by more than the given
29
* tolerance, the test fails.
30
*
31
* @param actual the actual value obtained by the simulator
32
* @param expected the expected value obtained by off-line calculations
33
* @param tol the tolerance
34
* @param msg the message to print if the test fails
35
*
36
*/
37
#define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL(actual, expected, tol, msg) \
38
do \
39
{ \
40
auto i = (actual).Begin(); \
41
auto j = (expected).Begin(); \
42
uint32_t k = 0; \
43
while (i != (actual).End() && j != (expected).End()) \
44
{ \
45
if ((i->fl > j->fl + (tol)) || (i->fl < j->fl - (tol)) || (i->fc > j->fc + (tol)) || \
46
(i->fc < j->fc - (tol)) || (i->fh > j->fh + (tol)) || (i->fh < j->fh - (tol))) \
47
{ \
48
ASSERT_ON_FAILURE; \
49
std::ostringstream indexStream; \
50
indexStream << "[" << k << "]"; \
51
std::ostringstream msgStream; \
52
msgStream << (msg); \
53
std::ostringstream actualStream; \
54
actualStream << i->fl << " <-- " << i->fc << " --> " << i->fh; \
55
std::ostringstream expectedStream; \
56
expectedStream << j->fl << " <-- " << j->fc << " --> " << j->fh; \
57
ReportTestFailure(std::string(#actual) + indexStream.str() + \
58
" == " + std::string(#expected) + indexStream.str(), \
59
actualStream.str(), \
60
expectedStream.str(), \
61
msgStream.str(), \
62
(__FILE__), \
63
(__LINE__)); \
64
CONTINUE_ON_FAILURE; \
65
} \
66
++i; \
67
++j; \
68
++k; \
69
} \
70
if (i != (actual).End() || j != (expected).End()) \
71
{ \
72
std::ostringstream msgStream; \
73
msgStream << (msg); \
74
std::ostringstream actualStream; \
75
actualStream << (i != (actual).End()); \
76
std::ostringstream expectedStream; \
77
expectedStream << (j != (expected).End()); \
78
ReportTestFailure("Bands::iterator == End ()", \
79
actualStream.str(), \
80
expectedStream.str(), \
81
msgStream.str(), \
82
(__FILE__), \
83
(__LINE__)); \
84
} \
85
} while (false);
86
87
/**
88
* @ingroup spectrum-tests
89
*
90
* @brief Test if two SpectrumValue instances are equal within a given tolerance.
91
*
92
* This test compares component-by-component the two SpectrumValue
93
* instances; if any pair of components differs by more than the given
94
* tolerance, the test fails.
95
*
96
* @param actual the actual value obtained by the simulator
97
* @param expected the expected value obtained by off-line calculations
98
* @param tol the tolerance
99
* @param msg the message to print if the test fails
100
*
101
*/
102
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
103
do \
104
{ \
105
auto i = (actual).ConstValuesBegin(); \
106
auto j = (expected).ConstValuesBegin(); \
107
uint32_t k = 0; \
108
while (i != (actual).ConstValuesEnd() && j != (expected).ConstValuesEnd()) \
109
{ \
110
if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
111
{ \
112
ASSERT_ON_FAILURE; \
113
std::ostringstream indexStream; \
114
indexStream << "[" << k << "]"; \
115
std::ostringstream msgStream; \
116
msgStream << msg; \
117
std::ostringstream actualStream; \
118
actualStream << actual; \
119
std::ostringstream expectedStream; \
120
expectedStream << expected; \
121
ReportTestFailure(std::string(#actual) + indexStream.str() + \
122
" == " + std::string(#expected) + indexStream.str(), \
123
actualStream.str(), \
124
expectedStream.str(), \
125
msgStream.str(), \
126
__FILE__, \
127
__LINE__); \
128
CONTINUE_ON_FAILURE; \
129
} \
130
++i; \
131
++j; \
132
++k; \
133
} \
134
if (i != (actual).ConstValuesEnd() || j != (expected).ConstValuesEnd()) \
135
{ \
136
std::ostringstream msgStream; \
137
msgStream << (msg); \
138
std::ostringstream actualStream; \
139
actualStream << (i != (actual).ConstValuesEnd()); \
140
std::ostringstream expectedStream; \
141
expectedStream << (j != (expected).ConstValuesEnd()); \
142
ReportTestFailure("Values::const_iterator == ConstValuesEnd ()", \
143
actualStream.str(), \
144
expectedStream.str(), \
145
msgStream.str(), \
146
(__FILE__), \
147
(__LINE__)); \
148
} \
149
} while (false);
150
151
#endif
// SPECTRUM_TEST_H
src
spectrum
test
spectrum-test.h
Generated on Wed Dec 4 2024 09:20:50 for ns-3 by
1.11.0