11#include "ns3/object.h"
12#include "ns3/string.h"
16#include <boost/units/base_units/us/foot.hpp>
17#include <boost/units/systems/si.hpp>
18#include <boost/units/systems/si/prefixes.hpp>
24#include <initializer_list>
136 const std::initializer_list<std::string>&
symbols);
155#ifdef HAVE_BOOST_UNITS
247 const std::string& context);
306 void DoRun()
override;
326 "length constructed from meters has wrong value");
332 using TestEntry = std::tuple<Length, std::string>;
335 const std::initializer_list<TestEntry>
inputs{
336 std::make_tuple(
Length(1
e9, Unit::Nanometer),
"nanometer"),
337 std::make_tuple(
Length(1
e6, Unit::Micrometer),
"micrometer"),
338 std::make_tuple(
Length(1
e3, Unit::Millimeter),
"millimeter"),
339 std::make_tuple(
Length(1
e2, Unit::Centimeter),
"centimeter"),
340 std::make_tuple(
Length(1e-3, Unit::Kilometer),
"kilometer"),
341 std::make_tuple(
Length((1 / 1852.0), Unit::NauticalMile),
"nautical_mile")};
346 const std::string& context = std::get<1>(
entry);
350 context <<
": constructed length from SI unit has wrong value");
357 using TestEntry = std::tuple<Length, std::string>;
362 const std::initializer_list<TestEntry>
inputs{
363 std::make_tuple(
Length(12.0, Unit::Inch),
"inch"),
364 std::make_tuple(
Length(1.0, Unit::Foot),
"foot"),
365 std::make_tuple(
Length((1 / 3.0), Unit::Yard),
"yard"),
366 std::make_tuple(
Length((1 / 5280.0), Unit::Mile),
"mile"),
372 const std::string& context = std::get<1>(
entry);
377 "constructed length from US unit (" << context
378 <<
") has wrong value");
385 const double value = 5;
392 "copy constructed length has wrong value");
398 const double value = 5;
410 const std::initializer_list<std::string>&
symbols)
412 const std::array<std::string, 2>
SEPARATORS{{
"",
" "}};
418 std::ostringstream stream;
424 std::ostringstream
msg;
425 msg <<
"string constructed length has wrong value: '" << stream.str() <<
"'";
435 const double value = 5;
443 const double value = 5;
449 {
"nm",
"nanometer",
"nanometers",
"nanometre",
"nanometres"});
455 const double value = 5;
462 {
"um",
"micrometer",
"micrometers",
"micrometre",
"micrometres"});
468 const double value = 5;
475 {
"mm",
"millimeter",
"millimeters",
"millimetre",
"millimetres"});
481 const double value = 5;
488 {
"cm",
"centimeter",
"centimeters",
"centimetre",
"centimetres"});
494 const double value = 5;
500 {
"km",
"kilometer",
"kilometers",
"kilometre",
"kilometres"});
506 const double value = 5;
512 {
"nmi",
"nautical mile",
"nautical miles"});
518 const double value = 5;
528 const double value = 5;
538 const double value = 5;
548 const double value = 5;
555#ifdef HAVE_BOOST_UNITS
557LengthTestCase::TestConstructLengthFromBoostUnits()
565LengthTestCase::TestConstructLengthFromBoostUnitsMeters()
567 namespace bu = boost::units;
569 auto meters = 5 * bu::si::meter;
575 "Construction from boost::units meters produced "
580LengthTestCase::TestConstructLengthFromBoostUnitsKiloMeters()
582 namespace bu = boost::units;
583 auto kilometer = bu::si::kilo * bu::si::meter;
592 "Construction from boost::units kilometers produced "
597LengthTestCase::TestConstructLengthFromBoostUnitsFeet()
599 namespace bu = boost::units;
601 bu::us::foot_base_unit::unit_type Foot;
604 auto feet = 10 * Foot;
611 "Construction from boost::units foot produced "
645 "The builder free function for "
647 <<
" did not create a Length with the correct value");
656 AssertFalse(
l.has_value(),
"TryParse returned true on bad input");
662 using TestInput = std::pair<double, std::string>;
663 using TestArgs = std::pair<double, double>;
664 std::map<TestInput, TestArgs> tests{
667 {{5,
"kilometer"}, {5
e3, 0}},
668 {{5,
" kilometer"}, {5
e3, 0}},
671 for (
auto&
entry : tests)
678 AssertTrue(
l.has_value(),
"TryParse returned false when expecting true");
680 std::stringstream stream;
681 stream <<
"Parsing input (" <<
input.first <<
", " <<
input.second
682 <<
") returned the wrong value";
691 const double value = 5;
704 const double value = 5;
730 const double value = 5;
740 const double value = 5;
750 const double value = 5;
762 const double value = 5;
774 const double value = 5;
785 const double value = 5;
798 Length one(5.01, Unit::Meter);
802 "IsNotEqual with tolerance returned false for not equal lengths");
810 Length one(5.01, Unit::Meter);
814 "IsNotEqual with tolerance returned true for not equal lengths");
820 const double value = 5;
831 const double value = 5;
844 Length one(5.1234, Unit::Meter);
853 Length one(2.0, Unit::Meter);
862 Length one(2.0, Unit::Meter);
873 Length one(5.1234, Unit::Meter);
884 std::stringstream stream;
894 const double value = 5;
898 std::stringstream stream;
900 stream <<
value <<
"m";
912 const std::string& context)
914 const std::string
msg = context +
": unexpected output when serializing length";
916 std::ostringstream stream;
918 stream << std::fixed << std::setprecision(5) <<
l.As(unit);
944 const double value = 5;
949 AssertTrue(one ==
two,
"operator== returned false for equal lengths");
955 const double value = 5;
960 AssertFalse(one ==
two,
"operator== returned true for non equal lengths");
966 const double value = 5;
971 AssertTrue(one !=
two,
"operator!= returned false for non equal lengths");
977 const double value = 5;
982 AssertFalse(one !=
two,
"operator!= returned true for equal lengths");
988 const double value = 5;
993 AssertTrue(one <
two,
"operator< returned false for smaller length");
999 const double value = 5;
1004 AssertFalse(
two < one,
"operator< returned true for larger length");
1010 const double value = 5;
1016 AssertTrue(one <=
two,
"operator<= returned false for smaller length");
1018 AssertTrue(one <=
three,
"operator<= returned false for equal lengths");
1024 const double value = 5;
1029 AssertFalse(
two <= one,
"operator<= returned true for larger length");
1035 const double value = 5;
1040 AssertTrue(
two > one,
"operator> returned false for larger length");
1046 const double value = 5;
1051 AssertFalse(one >
two,
"operator> returned true for smaller length");
1057 const double value = 5;
1063 AssertTrue(
two >= one,
"operator>= returned false for larger length");
1065 AssertTrue(one >=
three,
"operator>= returned false for equal lengths");
1071 const double value = 5;
1076 AssertFalse(one >=
two,
"operator>= returned true for smaller length");
1082 const double value = 1;
1098 const double value = 1;
1112 const double value = 1;
1126 const double value = 1;
1142 const double value = 1;
1156 const double value = 1;
1170 const double value = 1;
1184 const double value = 1;
1198 const double value = 10;
1219 double result = one /
two;
1229 const double value = 1;
1234 double result = one /
two;
1236 AssertTrue(std::isnan(result),
"operator/ did not return NaN when dividing by zero");
1271 "Div() returned an incorrect remainder");
1291 "Div() returned an incorrect remainder");
1344#ifdef HAVE_BOOST_UNITS
1483 void DoRun()
override;
1489 static TypeId tid =
TypeId(
"LengthValueTestCase::TestObject")
1491 .SetGroupName(
"Test")
1493 .AddAttribute(
"Length",
1519 std::string
output =
value.SerializeToString(checker);
1530 std::ostringstream stream;
1549 obj->GetAttribute(
"Length",
val);
1560 std::stringstream stream;
1561 stream <<
expected.As(Unit::Kilometer);
1566 obj->GetAttribute(
"Length",
val);
Implements tests for the Length class.
void TestAddingLengthAndQuantity()
Test arithmetic operations.
void TestIsGreaterReturnsFalse()
Test member comparison operators.
void TestOperatorGreaterOrEqualReturnsTrue()
Test free function comparison operators.
void TestOperatorEqualsReturnsFalse()
Test free function comparison operators.
void TestTryParseReturnsTrue()
Test the TryParse function returns true on success.
void TestConstructLengthFromMeterString()
Test that a length object can be constructed from a string.
void TestDivReturnsZeroRemainder()
Test Div function.
void TestBuilderFreeFunctions()
Test constructing length objects using the builder free functions.
void TestConstructLengthFromMileString()
Test that a length object can be constructed from a string.
void TestIsEqualWithToleranceReturnsFalse()
Test member comparison operators.
void TestDivReturnsCorrectRemainder()
Test Div function.
void TestModReturnsZero()
Test Mod function.
void TestConstructLengthFromCentiMeterString()
Test that a length object can be constructed from a string.
void TestDivideLengthByScalar()
Test arithmetic operations.
void TestModReturnsNonZero()
Test Mod function.
void TestLengthMoveConstructor()
Test that the value from one length is copied to another using the move constructor.
void TestTryParseReturnsFalse()
Test the TryParse function returns false on bad input.
void TestCopyAssignment()
Test that a length object can be updated by assignment from another length object.
void TestIsNotEqualReturnsTrue()
Test member comparison operators.
void TestConstructLengthFromFootString()
Test that a length object can be constructed from a string.
void TestInputStreamOperator()
Test reading length object from a stream produces the expected length value.
void TestDivideLengthByLengthReturnsNaN()
Test arithmetic operations.
void TestIsNotEqualWithToleranceReturnsFalse()
Test member comparison operators.
void TestOperatorLessOrEqualReturnsTrue()
Test free function comparison operators.
void TestIsLessReturnsFalse()
Test member comparison operators.
void TestSubtractingQuantityAndLength()
Test arithmetic operations.
void TestConstructLengthFromMilliMeterString()
Test that a length object can be constructed from a string.
void TestConstructLengthFromInchString()
Test that a length object can be constructed from a string.
void TestConstructLengthFromSIUnits()
Test that a Length object constructed from various SI units has the correct value in meters.
void DoRun() override
Implementation to actually run this TestCase.
void TestConstructLengthFromNanoMeterString()
Test that a length object can be constructed from a string.
void TestMultiplyLengthByScalar()
Test arithmetic operations.
void AssertTrue(bool condition, std::string msg)
Helper function to compare results with true.
void TestIsEqualReturnsFalse()
Test member comparison operators.
void TestConstructLengthFromQuantity()
Test that a Length object can be constructed from a Quantity object.
void TestConstructLengthFromKiloMeterString()
Test that a length object can be constructed from a string.
void TestDefaultLengthIsZero()
Test that a default constructed Length object has a value of 0.
void TestOperatorEqualsReturnsTrue()
Test free function comparison operators.
void TestConstructLengthFromUSUnits()
Test that a Length object constructed from various US units has the correct value in meters.
void AssertFalse(bool condition, std::string msg)
Helper function to compare results with false.
void TestIsEqualReturnsTrue()
Test member comparison operators.
void TestIsNotEqualWithToleranceReturnsTrue()
Test member comparison operators.
void TestOperatorLessThanReturnsFalse()
Test free function comparison operators.
void TestIsGreaterWithToleranceReturnsFalse()
Test member comparison operators.
void TestLengthSerialization(const Length &l, const T &unit, const std::string &expectedOutput, const std::string &context)
Generic function for testing serialization of a Length object in various units.
void TestSubtractingLengthAndQuantity()
Test arithmetic operations.
void TestSubtractingTwoLengths()
Test arithmetic operations.
void TestDivideLengthByLength()
Test arithmetic operations.
void TestDivReturnsCorrectResult()
Test Div function.
void TestAddingQuantityAndLength()
Test arithmetic operations.
void TestIsNotEqualReturnsFalse()
Test member comparison operators.
void TestConstructLengthFromMicroMeterString()
Test that a length object can be constructed from a string.
void TestOperatorGreaterThanReturnsTrue()
Test free function comparison operators.
void TestOutputStreamOperator()
Test writing length object to a stream produces the expected output.
LengthTestCase()
Constructor.
void TestConstructLengthFromYardString()
Test that a length object can be constructed from a string.
void TestAddingTwoLengths()
Test arithmetic operations.
void TestConstructLengthFromNauticalMileString()
Test that a length object can be constructed from a string.
void TestIsLessReturnsTrue()
Test member comparison operators.
void TestOperatorGreaterThanReturnsFalse()
Test free function comparison operators.
void TestOperatorLessThanReturnsTrue()
Test free function comparison operators.
void TestOperatorNotEqualsReturnsFalse()
Test free function comparison operators.
void TestMoveAssignment()
Test that a length object can be updated by assignment from a moved length object.
void TestOperatorLessOrEqualReturnsFalse()
Test free function comparison operators.
void TestConstructLengthFromString(double unitValue, double meterValue, double tolerance, const std::initializer_list< std::string > &symbols)
Test that a length object can be constructed from a string.
void TestSerializeLengthWithUnit()
Test serializing a length object to all of the supported unit types.
void TestOperatorGreaterOrEqualReturnsFalse()
Test free function comparison operators.
void TestLengthCopyConstructor()
Test that the value from one length is copied to another using the copy constructor.
~LengthTestCase() override=default
Destructor.
void TestOperatorNotEqualsReturnsTrue()
Test free function comparison operators.
void TestMultiplyScalarByLength()
Test arithmetic operations.
void TestIsLessWithToleranceReturnsFalse()
Test member comparison operators.
void TestIsGreaterReturnsTrue()
Test member comparison operators.
void TestQuantityAssignment()
Test that a length object can be updated by assignment from a quantity.
void TestIsEqualWithToleranceReturnsTrue()
Test member comparison operators.
The Test Suite that runs the test case.
LengthTestSuite()
Default Constructor.
Class with Length attribute.
static TypeId GetTypeId()
Get the type ID.
Length m_length
Length object.
Test case for LengthValue attribute.
void TestAttributeSerialization()
Test that a LengthValue can be serialized to a string.
void TestObjectAttribute()
Test that a LengthValue works as an attribute.
LengthValueTestCase()
Default Constructor.
void TestAttributeConstructor()
Test that a LengthValue can be constructed from a Length instance.
void TestAttributeDeserialization()
Test that a LengthValue can be deserialized from a string.
void DoRun() override
Implementation to actually run this TestCase.
void TestSetAttributeUsingStringValue()
Test that a StringValue is converted to LengthValue.
~LengthValueTestCase() override
Destructor.
An immutable class which represents a value in a specific length unit.
Represents a length in meters.
double GetDouble() const
Current length value.
bool IsGreater(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is less in value than this instance.
bool IsEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is equal in value to this instance.
static std::optional< Length > TryParse(double value, const std::string &unit)
Attempt to construct a Length object from a value and a unit string.
Unit
Units of length in various measurement systems that are supported by the Length class.
bool IsLess(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is greater in value than this instance.
bool IsNotEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is not equal in value to this instance.
AttributeValue implementation for Length.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Length KiloMeters(double value)
Construct a length from a value in the indicated unit.
Length MilliMeters(double value)
Construct a length from a value in the indicated unit.
Length NauticalMiles(double value)
Construct a length from a value in the indicated unit.
Length Yards(double value)
Construct a length from a value in the indicated unit.
Length Feet(double value)
Construct a length from a value in the indicated unit.
Length Mod(const Length &numerator, const Length &denominator)
Calculate the amount remaining after dividing two lengths.
Length MicroMeters(double value)
Construct a length from a value in the indicated unit.
Length Miles(double value)
Construct a length from a value in the indicated unit.
Length Meters(double value)
Construct a length from a value in the indicated unit.
Length CentiMeters(double value)
Construct a length from a value in the indicated unit.
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
Calculate how many times numerator can be split into denominator sized pieces.
Length NanoMeters(double value)
Construct a length from a value in the indicated unit.
Length Inches(double value)
Construct a length from a value in the indicated unit.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.
#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...
static LengthTestSuite gLengthTestSuite
LengthTestSuite instance.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static unsigned int value(char c)
Ptr< const AttributeChecker > MakeLengthChecker()
Ptr< const AttributeAccessor > MakeLengthAccessor(T1 a1)
-ray-to-three-gpp-ch-calibration