Tools to define and execute unit tests. More...
Modules | |
Testing Implementation | |
Internal implementation of the Testing system. | |
Files | |
file | example-as-test.cc |
Implementation of classes ns3::ExampleAsTestSuite and ns3::ExampleTestCase. | |
file | example-as-test.h |
Enable examples to be run as meaningful tests. | |
file | sample-test-suite.cc |
Example use of TestSuite. | |
file | test.cc |
ns3::TestCase, ns3::TestSuite, ns3::TestRunner implementations, | |
file | test.h |
ns3::TestCase, ns3::TestSuite, ns3::TestRunner declarations, and NS_TEST_ASSERT macro definitions. | |
Classes | |
class | ns3::ExampleAsTestCase |
Execute an example program as a test, by comparing the output to a reference file. More... | |
class | ns3::ExampleAsTestSuite |
Execute an example program as a test suite. More... | |
class | ns3::TestCase |
encapsulates test code More... | |
class | ns3::TestSuite |
A suite of tests to run. More... | |
class | ns3::TestVectors< T > |
A simple way to store test vectors (for stimulus or from responses) More... | |
Macros | |
#define | ASSERT_ON_FAILURE |
Check if we should assert on errors, and do so. More... | |
#define | CONTINUE_ON_FAILURE |
If we shouldn't continue on errors, return. More... | |
#define | CONTINUE_ON_FAILURE_RETURNS_BOOL |
If we shouldn't continue on errors, return test status. More... | |
#define | NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) |
Test that an actual and expected (limit) value are equal and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) |
Test that an actual and expected (limit) value are equal and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_GT(actual, limit, msg) |
Test that an actual value is greater than a limit and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) |
Test that an actual value is greater than or equal to a limit and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_LT(actual, limit, msg) |
Test that an actual value is less than a limit and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) |
Test that an actual value is less than or equal to a limit and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_NE(actual, limit, msg) |
Test that an actual and expected (limit) value are not equal and report and abort if not. More... | |
#define | NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) |
Test that an actual and expected (limit) value are not equal and report and abort if not. More... | |
#define | NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) |
Test that an actual and expected (limit) value are equal and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_GT(actual, limit, msg) |
Test that an actual value is greater than a limit and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) |
Test that an actual value is greater than or equal to limit and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_LT(actual, limit, msg) |
Test that an actual value is less than a limit and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) |
Test that an actual value is less than or equal to a limit and report if not. More... | |
#define | NS_TEST_EXPECT_MSG_NE(actual, limit, msg) |
Test that an actual and expected (limit) value are not equal and report if not. More... | |
Functions | |
bool | ns3::TestDoubleIsEqual (const double a, const double b, const double epsilon=std::numeric_limits< double >::epsilon()) |
Compare two double precision floating point numbers and declare them equal if they are within some epsilon of each other. More... | |
Tools to define and execute unit tests.
This module lists the normal Testing API. Most of these macros forward to the implementation macros in testingimpl. You should generally use these macros only.
#define ASSERT_ON_FAILURE |
#define CONTINUE_ON_FAILURE |
#define CONTINUE_ON_FAILURE_RETURNS_BOOL |
#define NS_TEST_ASSERT_MSG_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are equal and report and abort if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are equal and report and abort if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | msg | Message that is output if the test does not pass. |
This function returns a Boolean value.
#define NS_TEST_ASSERT_MSG_EQ_TOL | ( | actual, | |
limit, | |||
tol, | |||
msg | |||
) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.
In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an SNR that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.
This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | tol | Tolerance of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL | ( | actual, | |
limit, | |||
tol, | |||
msg | |||
) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.
In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an SNR that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.
This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | tol | Tolerance of the test. |
[in] | msg | Message that is output if the test does not pass. |
This function returns a Boolean value.
#define NS_TEST_ASSERT_MSG_GT | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is greater than a limit and report and abort if not.
Check to see if the actual value found in a test case is greater than the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_GT_OR_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is greater than or equal to a limit and report and abort if not.
Check to see if the actual value found in a test case is greater than or equal to the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_LT | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is less than a limit and report and abort if not.
Check to see if the actual value found in a test case is less than the limit value. If the actual value is lesser nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_LT_OR_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is less than or equal to a limit and report and abort if not.
Check to see if the actual value found in a test case is less than or equal to the limit value. If the actual value is lesser or equal nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_NE | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are not equal and report and abort if not.
Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are not equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the value that actual is tested against. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are not equal and report and abort if not.
Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | msg | Message that is output if the test does not pass. |
This function returns a Boolean value.
#define NS_TEST_EXPECT_MSG_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are equal and report if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_EQ_TOL | ( | actual, | |
limit, | |||
tol, | |||
msg | |||
) |
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not.
Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.
In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an SNR that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.
This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the expected value of the test. |
[in] | tol | Tolerance of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_GT | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is greater than a limit and report if not.
Check to see if the actual value found in a test case is greater than the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_GT_OR_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is greater than or equal to limit and report if not.
Check to see if the actual value found in a test case is greater than or equal to the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_LT | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is less than a limit and report if not.
Check to see if the actual value found in a test case is less than the limit value. If the actual value is lesser nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_LT_OR_EQ | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual value is less than or equal to a limit and report if not.
Check to see if the actual value found in a test case is less than or equal to the limit value. If the actual value is lesser or equal nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the limit value of the test. |
[in] | msg | Message that is output if the test does not pass. |
#define NS_TEST_EXPECT_MSG_NE | ( | actual, | |
limit, | |||
msg | |||
) |
Test that an actual and expected (limit) value are not equal and report if not.
Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are not equal nothing happens, but if the comparison fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.
The message is interpreted as a stream, for example:
is legal.
[in] | actual | Expression for the actual value found during the test. |
[in] | limit | Expression for the value that actual is tested against. |
[in] | msg | Message that is output if the test does not pass. |
bool ns3::TestDoubleIsEqual | ( | const double | a, |
const double | b, | ||
const double | epsilon = std::numeric_limits< double >::epsilon() |
||
) |
Compare two double precision floating point numbers and declare them equal if they are within some epsilon of each other.
Approximate comparison of floating point numbers near equality is trickier than one may expect and is well-discussed in the literature. Basic strategies revolve around a suggestion by Knuth to compare the floating point numbers as binary integers, supplying a maximum difference between them . This max difference is specified in Units in the Last Place (ulps) or a floating point epsilon.
This routine is based on the GNU Scientific Library function gsl_fcmp.
[in] | a | The first of double precision floating point numbers to compare |
[in] | b | The second of double precision floating point numbers to compare |
[in] | epsilon | The tolerance to use in the comparison. |
true
if the doubles are equal to a precision defined by epsilon Definition at line 45 of file test.cc.
References two-ray-to-three-gpp-ch-calibration::delta, epsilon, max, and NS_LOG_FUNCTION.
Referenced by WifiOfdmMaskSlopesTestCase::InterpolateAndAppendValues(), and TestInterBssConstantObssPdAlgo::NotifyPhyTxBegin().