20 #include "ns3/length.h"
22 #include "ns3/object.h"
23 #include "ns3/string.h"
27 #include <boost/units/base_units/us/foot.hpp>
28 #include <boost/units/systems/si.hpp>
29 #include <boost/units/systems/si/prefixes.hpp>
35 #include <initializer_list>
106 void TestDefaultLengthIsZero();
111 void TestConstructLengthFromQuantity();
117 void TestConstructLengthFromSIUnits();
123 void TestConstructLengthFromUSUnits();
129 void TestLengthCopyConstructor();
135 void TestLengthMoveConstructor();
144 void TestConstructLengthFromString(
double unitValue,
147 const std::initializer_list<std::string>& symbols);
153 void TestConstructLengthFromMeterString();
154 void TestConstructLengthFromNanoMeterString();
155 void TestConstructLengthFromMicroMeterString();
156 void TestConstructLengthFromMilliMeterString();
157 void TestConstructLengthFromCentiMeterString();
158 void TestConstructLengthFromKiloMeterString();
159 void TestConstructLengthFromNauticalMileString();
160 void TestConstructLengthFromInchString();
161 void TestConstructLengthFromFootString();
162 void TestConstructLengthFromYardString();
163 void TestConstructLengthFromMileString();
166 #ifdef HAVE_BOOST_UNITS
171 void TestConstructLengthFromBoostUnits();
172 void TestConstructLengthFromBoostUnitsMeters();
173 void TestConstructLengthFromBoostUnitsKiloMeters();
174 void TestConstructLengthFromBoostUnitsFeet();
182 void TestBuilderFreeFunctions();
188 void TestTryParseReturnsFalse();
193 void TestTryParseReturnsTrue();
199 void TestCopyAssignment();
205 void TestMoveAssignment();
210 void TestQuantityAssignment();
216 void TestIsEqualReturnsTrue();
217 void TestIsEqualReturnsFalse();
218 void TestIsEqualWithToleranceReturnsTrue();
219 void TestIsEqualWithToleranceReturnsFalse();
220 void TestIsNotEqualReturnsTrue();
221 void TestIsNotEqualReturnsFalse();
222 void TestIsNotEqualWithToleranceReturnsTrue();
223 void TestIsNotEqualWithToleranceReturnsFalse();
224 void TestIsLessReturnsTrue();
225 void TestIsLessReturnsFalse();
226 void TestIsLessWithToleranceReturnsFalse();
227 void TestIsGreaterReturnsTrue();
228 void TestIsGreaterReturnsFalse();
229 void TestIsGreaterWithToleranceReturnsFalse();
235 void TestOutputStreamOperator();
241 void TestInputStreamOperator();
255 void TestLengthSerialization(
const Length& l,
257 const std::string& expectedOutput,
258 const std::string& context);
263 void TestSerializeLengthWithUnit();
269 void TestOperatorEqualsReturnsTrue();
270 void TestOperatorEqualsReturnsFalse();
271 void TestOperatorNotEqualsReturnsTrue();
272 void TestOperatorNotEqualsReturnsFalse();
273 void TestOperatorLessThanReturnsTrue();
274 void TestOperatorLessThanReturnsFalse();
275 void TestOperatorLessOrEqualReturnsTrue();
276 void TestOperatorLessOrEqualReturnsFalse();
277 void TestOperatorGreaterThanReturnsTrue();
278 void TestOperatorGreaterThanReturnsFalse();
279 void TestOperatorGreaterOrEqualReturnsTrue();
280 void TestOperatorGreaterOrEqualReturnsFalse();
287 void TestAddingTwoLengths();
288 void TestAddingLengthAndQuantity();
289 void TestAddingQuantityAndLength();
290 void TestSubtractingTwoLengths();
291 void TestSubtractingLengthAndQuantity();
292 void TestSubtractingQuantityAndLength();
293 void TestMultiplyLengthByScalar();
294 void TestMultiplyScalarByLength();
295 void TestDivideLengthByScalar();
296 void TestDivideLengthByLength();
297 void TestDivideLengthByLengthReturnsNaN();
304 void TestDivReturnsCorrectResult();
305 void TestDivReturnsZeroRemainder();
306 void TestDivReturnsCorrectRemainder();
313 void TestModReturnsZero();
314 void TestModReturnsNonZero();
317 void DoRun()
override;
337 "length constructed from meters has wrong value");
343 using TestEntry = std::tuple<Length, std::string>;
345 const double expectedMeters = 1;
346 const std::initializer_list<TestEntry> inputs{
347 std::make_tuple(
Length(1e9, Unit::Nanometer),
"nanometer"),
348 std::make_tuple(
Length(1e6, Unit::Micrometer),
"micrometer"),
349 std::make_tuple(
Length(1e3, Unit::Millimeter),
"millimeter"),
350 std::make_tuple(
Length(1e2, Unit::Centimeter),
"centimeter"),
351 std::make_tuple(
Length(1e-3, Unit::Kilometer),
"kilometer"),
352 std::make_tuple(
Length((1 / 1852.0), Unit::NauticalMile),
"nautical_mile")};
354 for (
const TestEntry& entry : inputs)
356 const Length& l = std::get<0>(entry);
357 const std::string& context = std::get<1>(entry);
361 context <<
": constructed length from SI unit has wrong value");
368 using TestEntry = std::tuple<Length, std::string>;
370 const double expectedMeters = 0.3048;
371 const double tolerance = 0.0001;
373 const std::initializer_list<TestEntry> inputs{
374 std::make_tuple(
Length(12.0, Unit::Inch),
"inch"),
375 std::make_tuple(
Length(1.0, Unit::Foot),
"foot"),
376 std::make_tuple(
Length((1 / 3.0), Unit::Yard),
"yard"),
377 std::make_tuple(
Length((1 / 5280.0), Unit::Mile),
"mile"),
380 for (
const TestEntry& entry : inputs)
382 const Length& l = std::get<0>(entry);
383 const std::string& context = std::get<1>(entry);
388 "constructed length from US unit (" << context
389 <<
") has wrong value");
396 const double value = 5;
397 Length original(value, Unit::Meter);
403 "copy constructed length has wrong value");
409 const double value = 5;
410 Length original(value, Unit::Meter);
412 Length copy(std::move(original));
421 const std::initializer_list<std::string>& symbols)
423 const std::array<std::string, 2> SEPARATORS{{
"",
" "}};
425 for (
const std::string& symbol : symbols)
427 for (
const std::string& separator : SEPARATORS)
429 std::ostringstream stream;
431 stream << unitValue << separator << symbol;
435 std::ostringstream msg;
436 msg <<
"string constructed length has wrong value: '" << stream.str() <<
"'";
446 const double value = 5;
448 TestConstructLengthFromString(value, value, 0, {
"m",
"meter",
"meters",
"metre",
"metres"});
454 const double value = 5;
455 const double expectedValue = 5e-9;
457 TestConstructLengthFromString(value,
460 {
"nm",
"nanometer",
"nanometers",
"nanometre",
"nanometres"});
466 const double value = 5;
467 const double expectedValue = 5e-6;
468 const double tolerance = 1e-7;
470 TestConstructLengthFromString(value,
473 {
"um",
"micrometer",
"micrometers",
"micrometre",
"micrometres"});
479 const double value = 5;
480 const double expectedValue = 5e-3;
481 const double tolerance = 1e-4;
483 TestConstructLengthFromString(value,
486 {
"mm",
"millimeter",
"millimeters",
"millimetre",
"millimetres"});
492 const double value = 5;
493 const double expectedValue = 5e-2;
494 const double tolerance = 1e-3;
496 TestConstructLengthFromString(value,
499 {
"cm",
"centimeter",
"centimeters",
"centimetre",
"centimetres"});
505 const double value = 5;
506 const double expectedValue = 5e3;
508 TestConstructLengthFromString(value,
511 {
"km",
"kilometer",
"kilometers",
"kilometre",
"kilometres"});
517 const double value = 5;
518 const double expectedValue = 9260;
520 TestConstructLengthFromString(value,
523 {
"nmi",
"nautical mile",
"nautical miles"});
529 const double value = 5;
530 const double expectedValue = 0.127;
531 const double tolerance = 1e-4;
533 TestConstructLengthFromString(value, expectedValue, tolerance, {
"in",
"inch",
"inches"});
539 const double value = 5;
540 const double expectedValue = 1.524;
541 const double tolerance = 1e-4;
543 TestConstructLengthFromString(value, expectedValue, tolerance, {
"ft",
"foot",
"feet"});
549 const double value = 5;
550 const double expectedValue = 4.572;
551 const double tolerance = 1e-4;
553 TestConstructLengthFromString(value, expectedValue, tolerance, {
"yd",
"yard",
"yards"});
559 const double value = 5;
560 const double expectedValue = 8046.72;
561 const double tolerance = 1e-3;
563 TestConstructLengthFromString(value, expectedValue, tolerance, {
"mi",
"mile",
"miles"});
566 #ifdef HAVE_BOOST_UNITS
568 LengthTestCase::TestConstructLengthFromBoostUnits()
570 TestConstructLengthFromBoostUnitsMeters();
571 TestConstructLengthFromBoostUnitsKiloMeters();
572 TestConstructLengthFromBoostUnitsFeet();
576 LengthTestCase::TestConstructLengthFromBoostUnitsMeters()
578 namespace bu = boost::units;
580 auto meters = 5 * bu::si::meter;
586 "Construction from boost::units meters produced "
591 LengthTestCase::TestConstructLengthFromBoostUnitsKiloMeters()
593 namespace bu = boost::units;
594 auto kilometer = bu::si::kilo * bu::si::meter;
596 const double expectedValue = 5000;
597 auto quantity = 5 * kilometer;
603 "Construction from boost::units kilometers produced "
608 LengthTestCase::TestConstructLengthFromBoostUnitsFeet()
610 namespace bu = boost::units;
612 bu::us::foot_base_unit::unit_type Foot;
614 const double expectedValue = 3.048;
615 auto feet = 10 * Foot;
622 "Construction from boost::units foot produced "
630 using Builder = std::function<
Length(
double)>;
632 double inputValue = 10;
634 std::map<Unit, Builder> TESTDATA{
648 for (
auto& entry : TESTDATA)
650 Length expected(inputValue, entry.first);
652 Length output = entry.second(inputValue);
656 "The builder free function for "
658 <<
" did not create a Length with the correct value");
667 AssertFalse(l.has_value(),
"TryParse returned true on bad input");
673 using TestInput = std::pair<double, std::string>;
674 using TestArgs = std::pair<double, double>;
675 std::map<TestInput, TestArgs> tests{
678 {{5,
"kilometer"}, {5e3, 0}},
679 {{5,
" kilometer"}, {5e3, 0}},
682 for (
auto& entry : tests)
684 TestInput input = entry.first;
685 TestArgs
args = entry.second;
689 AssertTrue(l.has_value(),
"TryParse returned false when expecting true");
691 std::stringstream stream;
692 stream <<
"Parsing input (" << input.first <<
", " << input.second
693 <<
") returned the wrong value";
702 const double value = 5;
715 const double value = 5;
720 copy = std::move(original);
741 const double value = 5;
745 AssertTrue(one.
IsEqual(
two),
"IsEqual returned false for equal lengths");
751 const double value = 5;
755 AssertFalse(one.
IsEqual(
two),
"IsEqual returned true for unequal lengths");
761 const double value = 5;
762 const double tolerance = 0.1;
767 AssertTrue(one.
IsEqual(
two, tolerance),
"IsEqual returned false for almost equal lengths");
773 const double value = 5;
774 const double tolerance = 0.01;
779 AssertFalse(one.
IsEqual(
two, tolerance),
"IsEqual returned true for almost equal lengths");
785 const double value = 5;
790 AssertTrue(one.
IsNotEqual(
two),
"IsNotEqual returned false for not equal lengths");
796 const double value = 5;
801 AssertFalse(one.
IsNotEqual(
two),
"IsNotEqual returned true for equal lengths");
807 const double tolerance = 0.001;
809 Length one(5.01, Unit::Meter);
813 "IsNotEqual with tolerance returned false for not equal lengths");
819 const double tolerance = 0.01;
821 Length one(5.01, Unit::Meter);
825 "IsNotEqual with tolerance returned true for not equal lengths");
831 const double value = 5;
836 AssertTrue(one.
IsLess(
two),
"IsLess returned false for non equal lengths");
842 const double value = 5;
847 AssertFalse(one.
IsLess(
two),
"IsLess returned true for equal lengths");
853 const double tolerance = 0.01;
855 Length one(5.1234, Unit::Meter);
858 AssertFalse(one.
IsLess(
two, tolerance),
"IsLess with tolerance returned true");
864 Length one(2.0, Unit::Meter);
867 AssertTrue(one.
IsGreater(
two),
"IsGreater returned false");
873 Length one(2.0, Unit::Meter);
876 AssertFalse(
two.IsGreater(one),
"IsGreater returned true");
882 const double tolerance = 0.01;
884 Length one(5.1234, Unit::Meter);
887 AssertFalse(
two.IsGreater(one, tolerance),
"IsGreater returned true");
893 Length l(1.0, Unit::Meter);
895 std::stringstream stream;
905 const double value = 5;
909 std::stringstream stream;
911 stream <<
value <<
"m";
922 const std::string& expectedOutput,
923 const std::string& context)
925 const std::string msg = context +
": unexpected output when serializing length";
927 std::ostringstream stream;
929 stream << std::fixed << std::setprecision(5) << l.
As(unit);
937 Length l(1.0, Unit::Meter);
939 TestLengthSerialization(l, Unit::Nanometer,
"1000000000.00000 nm",
"nanometers");
940 TestLengthSerialization(l, Unit::Micrometer,
"1000000.00000 um",
"micrometers");
941 TestLengthSerialization(l, Unit::Millimeter,
"1000.00000 mm",
"millimeters");
942 TestLengthSerialization(l, Unit::Centimeter,
"100.00000 cm",
"centimeters");
943 TestLengthSerialization(l, Unit::Meter,
"1.00000 m",
"meters");
944 TestLengthSerialization(l, Unit::Kilometer,
"0.00100 km",
"kilometers");
945 TestLengthSerialization(l, Unit::NauticalMile,
"0.00054 nmi",
"nautical_mile");
946 TestLengthSerialization(l, Unit::Inch,
"39.37008 in",
"inches");
947 TestLengthSerialization(l, Unit::Foot,
"3.28084 ft",
"feet");
948 TestLengthSerialization(l, Unit::Yard,
"1.09361 yd",
"yards");
949 TestLengthSerialization(l, Unit::Mile,
"0.00062 mi",
"miles");
955 const double value = 5;
960 AssertTrue(one ==
two,
"operator== returned false for equal lengths");
966 const double value = 5;
971 AssertFalse(one ==
two,
"operator== returned true for non equal lengths");
977 const double value = 5;
982 AssertTrue(one !=
two,
"operator!= returned false for non equal lengths");
988 const double value = 5;
993 AssertFalse(one !=
two,
"operator!= returned true for equal lengths");
999 const double value = 5;
1004 AssertTrue(one <
two,
"operator< returned false for smaller length");
1010 const double value = 5;
1015 AssertFalse(
two < one,
"operator< returned true for larger length");
1021 const double value = 5;
1027 AssertTrue(one <=
two,
"operator<= returned false for smaller length");
1029 AssertTrue(one <= three,
"operator<= returned false for equal lengths");
1035 const double value = 5;
1040 AssertFalse(
two <= one,
"operator<= returned true for larger length");
1046 const double value = 5;
1051 AssertTrue(
two > one,
"operator> returned false for larger length");
1057 const double value = 5;
1062 AssertFalse(one >
two,
"operator> returned true for smaller length");
1068 const double value = 5;
1074 AssertTrue(
two >= one,
"operator>= returned false for larger length");
1076 AssertTrue(one >= three,
"operator>= returned false for equal lengths");
1082 const double value = 5;
1087 AssertFalse(one >=
two,
"operator>= returned true for smaller length");
1093 const double value = 1;
1094 const double expectedOutput = 2;
1109 const double value = 1;
1110 const double expectedOutput = 2;
1123 const double value = 1;
1124 const double expectedOutput = 2;
1137 const double value = 1;
1138 const double expectedOutput = 0;
1153 const double value = 1;
1154 const double expectedOutput = 0;
1167 const double value = 1;
1168 const double expectedOutput = 0;
1181 const double value = 1;
1182 const double scalar = 5;
1183 const double expectedOutput =
value * scalar;
1186 Length result = one * scalar;
1195 const double value = 1;
1196 const double scalar = 5;
1197 const double expectedOutput =
value * scalar;
1200 Length result = scalar * one;
1209 const double value = 10;
1210 const double scalar = 5;
1211 const double expectedOutput =
value / scalar;
1214 Length result = one / scalar;
1223 const double valueOne = 100;
1224 const double valueTwo = 2;
1225 const double expectedOutput = valueOne / valueTwo;
1227 Length one(valueOne, Unit::Meter);
1230 double result = one /
two;
1240 const double value = 1;
1245 double result = one /
two;
1247 AssertTrue(std::isnan(result),
"operator/ did not return NaN when dividing by zero");
1253 const double topValue = 100;
1254 const double bottomValue = 20;
1255 const int64_t expectedOutput = 5;
1257 Length numerator(topValue, Unit::Meter);
1258 Length denominator(bottomValue, Unit::Meter);
1260 auto result =
Div(numerator, denominator);
1268 const double topValue = 100;
1269 const double bottomValue = 20;
1270 const int64_t expectedOutput = 5;
1271 const int64_t expectedRemainder = 0;
1273 Length numerator(topValue, Unit::Meter);
1274 Length denominator(bottomValue, Unit::Meter);
1277 auto result =
Div(numerator, denominator, &remainder);
1282 "Div() returned an incorrect remainder");
1288 const double topValue = 110;
1289 const double bottomValue = 20;
1290 const int64_t expectedOutput = 5;
1291 const int64_t expectedRemainder = 10;
1293 Length numerator(topValue, Unit::Meter);
1294 Length denominator(bottomValue, Unit::Meter);
1297 auto result =
Div(numerator, denominator, &remainder);
1302 "Div() returned an incorrect remainder");
1308 Length numerator(10, Unit::Meter);
1309 Length denominator(2, Unit::Meter);
1311 auto result =
Mod(numerator, denominator);
1319 Length numerator(14, Unit::Meter);
1320 Length denominator(3, Unit::Meter);
1321 const double expectedValue = 2;
1323 auto result =
Mod(numerator, denominator);
1331 TestDefaultLengthIsZero();
1333 TestConstructLengthFromQuantity();
1335 TestConstructLengthFromSIUnits();
1337 TestConstructLengthFromUSUnits();
1339 TestLengthCopyConstructor();
1341 TestLengthMoveConstructor();
1343 TestConstructLengthFromMeterString();
1344 TestConstructLengthFromNanoMeterString();
1345 TestConstructLengthFromMicroMeterString();
1346 TestConstructLengthFromMilliMeterString();
1347 TestConstructLengthFromCentiMeterString();
1348 TestConstructLengthFromKiloMeterString();
1349 TestConstructLengthFromNauticalMileString();
1350 TestConstructLengthFromInchString();
1351 TestConstructLengthFromFootString();
1352 TestConstructLengthFromYardString();
1353 TestConstructLengthFromMileString();
1355 #ifdef HAVE_BOOST_UNITS
1356 TestConstructLengthFromBoostUnits();
1359 TestBuilderFreeFunctions();
1361 TestTryParseReturnsFalse();
1362 TestTryParseReturnsTrue();
1364 TestCopyAssignment();
1365 TestMoveAssignment();
1366 TestQuantityAssignment();
1368 TestIsEqualReturnsTrue();
1369 TestIsEqualReturnsFalse();
1370 TestIsEqualWithToleranceReturnsTrue();
1371 TestIsEqualWithToleranceReturnsFalse();
1372 TestIsNotEqualReturnsTrue();
1373 TestIsNotEqualReturnsFalse();
1374 TestIsNotEqualWithToleranceReturnsTrue();
1375 TestIsNotEqualWithToleranceReturnsFalse();
1376 TestIsLessReturnsTrue();
1377 TestIsLessReturnsFalse();
1378 TestIsLessWithToleranceReturnsFalse();
1379 TestIsGreaterReturnsTrue();
1380 TestIsGreaterReturnsFalse();
1381 TestIsGreaterWithToleranceReturnsFalse();
1383 TestOutputStreamOperator();
1385 TestSerializeLengthWithUnit();
1387 TestOperatorEqualsReturnsTrue();
1388 TestOperatorEqualsReturnsFalse();
1389 TestOperatorNotEqualsReturnsTrue();
1390 TestOperatorNotEqualsReturnsFalse();
1391 TestOperatorLessThanReturnsTrue();
1392 TestOperatorLessThanReturnsFalse();
1393 TestOperatorLessOrEqualReturnsTrue();
1394 TestOperatorLessOrEqualReturnsFalse();
1395 TestOperatorGreaterThanReturnsTrue();
1396 TestOperatorGreaterThanReturnsFalse();
1397 TestOperatorGreaterOrEqualReturnsTrue();
1398 TestOperatorGreaterOrEqualReturnsFalse();
1400 TestAddingTwoLengths();
1401 TestAddingLengthAndQuantity();
1402 TestAddingQuantityAndLength();
1403 TestSubtractingTwoLengths();
1404 TestSubtractingLengthAndQuantity();
1405 TestSubtractingQuantityAndLength();
1406 TestMultiplyLengthByScalar();
1407 TestMultiplyScalarByLength();
1408 TestDivideLengthByScalar();
1409 TestDivideLengthByLength();
1410 TestDivideLengthByLengthReturnsNaN();
1412 TestDivReturnsCorrectResult();
1413 TestDivReturnsZeroRemainder();
1414 TestDivReturnsCorrectRemainder();
1416 TestModReturnsZero();
1417 TestModReturnsNonZero();
1452 static TypeId GetTypeId();
1471 void TestAttributeConstructor();
1476 void TestAttributeSerialization();
1481 void TestAttributeDeserialization();
1486 void TestObjectAttribute();
1491 void TestSetAttributeUsingStringValue();
1494 void DoRun()
override;
1500 static TypeId tid =
TypeId(
"LengthValueTestCase::TestObject")
1502 .SetGroupName(
"Test")
1504 .AddAttribute(
"Length",
1530 std::string output = value.SerializeToString(checker);
1541 std::ostringstream stream;
1545 bool result = value.DeserializeFromString(stream.str(), checker);
1554 Length expected(5, Unit::Kilometer);
1557 obj->SetAttribute(
"Length",
LengthValue(expected));
1560 obj->GetAttribute(
"Length", val);
1568 Length expected(5, Unit::Kilometer);
1571 std::stringstream stream;
1572 stream << expected.
As(Unit::Kilometer);
1574 obj->SetAttribute(
"Length",
StringValue(stream.str()));
1577 obj->GetAttribute(
"Length", val);
1585 TestAttributeConstructor();
1586 TestAttributeSerialization();
1587 TestAttributeDeserialization();
1588 TestObjectAttribute();
1589 TestSetAttributeUsingStringValue();
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.
double Value() const
The value of the quantity.
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.
Quantity As(Unit unit) const
Create a Quantity in a specific unit from a Length.
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.
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, TestDuration 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.
#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.
Ptr< const AttributeChecker > MakeLengthChecker()
Ptr< const AttributeAccessor > MakeLengthAccessor(T1 a1)
-ray-to-three-gpp-ch-calibration