21 #include "ns3/length.h"
23 #include "ns3/object.h"
24 #include "ns3/string.h"
28 #include <boost/units/base_units/us/foot.hpp>
29 #include <boost/units/systems/si.hpp>
30 #include <boost/units/systems/si/prefixes.hpp>
36 #include <initializer_list>
109 void TestDefaultLengthIsZero ();
114 void TestConstructLengthFromQuantity ();
120 void TestConstructLengthFromSIUnits ();
126 void TestConstructLengthFromUSUnits ();
132 void TestLengthCopyConstructor ();
138 void TestLengthMoveConstructor ();
144 void TestConstructLengthFromString (
double unitValue,
147 const std::initializer_list<std::string>& symbols);
149 void TestConstructLengthFromMeterString ();
150 void TestConstructLengthFromNanoMeterString ();
151 void TestConstructLengthFromMicroMeterString ();
152 void TestConstructLengthFromMilliMeterString ();
153 void TestConstructLengthFromCentiMeterString ();
154 void TestConstructLengthFromKiloMeterString ();
155 void TestConstructLengthFromNauticalMileString ();
156 void TestConstructLengthFromInchString ();
157 void TestConstructLengthFromFootString ();
158 void TestConstructLengthFromYardString ();
159 void TestConstructLengthFromMileString ();
162 #ifdef HAVE_BOOST_UNITS
167 void TestConstructLengthFromBoostUnits ();
168 void TestConstructLengthFromBoostUnitsMeters ();
169 void TestConstructLengthFromBoostUnitsKiloMeters ();
170 void TestConstructLengthFromBoostUnitsFeet ();
178 void TestBuilderFreeFunctions ();
184 void TestTryParseReturnsFalse ();
189 void TestTryParseReturnsTrue ();
196 void TestCopyAssignment ();
202 void TestMoveAssignment ();
207 void TestQuantityAssignment ();
213 void TestIsEqualReturnsTrue ();
214 void TestIsEqualReturnsFalse ();
215 void TestIsEqualWithToleranceReturnsTrue ();
216 void TestIsEqualWithToleranceReturnsFalse ();
217 void TestIsNotEqualReturnsTrue ();
218 void TestIsNotEqualReturnsFalse ();
219 void TestIsNotEqualWithToleranceReturnsTrue ();
220 void TestIsNotEqualWithToleranceReturnsFalse ();
221 void TestIsLessReturnsTrue ();
222 void TestIsLessReturnsFalse ();
223 void TestIsLessWithToleranceReturnsFalse ();
224 void TestIsGreaterReturnsTrue ();
225 void TestIsGreaterReturnsFalse ();
226 void TestIsGreaterWithToleranceReturnsFalse ();
232 void TestOutputStreamOperator ();
238 void TestInputStreamOperator ();
252 void TestLengthSerialization (
const Length& l,
254 const std::string& expectedOutput,
255 const std::string& context);
260 void TestSerializeLengthWithUnit ();
266 void TestOperatorEqualsReturnsTrue ();
267 void TestOperatorEqualsReturnsFalse ();
268 void TestOperatorNotEqualsReturnsTrue ();
269 void TestOperatorNotEqualsReturnsFalse ();
270 void TestOperatorLessThanReturnsTrue ();
271 void TestOperatorLessThanReturnsFalse ();
272 void TestOperatorLessOrEqualReturnsTrue ();
273 void TestOperatorLessOrEqualReturnsFalse ();
274 void TestOperatorGreaterThanReturnsTrue ();
275 void TestOperatorGreaterThanReturnsFalse ();
276 void TestOperatorGreaterOrEqualReturnsTrue ();
277 void TestOperatorGreaterOrEqualReturnsFalse ();
284 void TestAddingTwoLengths ();
285 void TestAddingLengthAndQuantity ();
286 void TestAddingQuantityAndLength ();
287 void TestSubtractingTwoLengths ();
288 void TestSubtractingLengthAndQuantity ();
289 void TestSubtractingQuantityAndLength ();
290 void TestMultiplyLengthByScalar ();
291 void TestMultiplyScalarByLength ();
292 void TestDivideLengthByScalar ();
293 void TestDivideLengthByLength ();
294 void TestDivideLengthByLengthReturnsNaN ();
301 void TestDivReturnsCorrectResult ();
302 void TestDivReturnsZeroRemainder ();
303 void TestDivReturnsCorrectRemainder ();
310 void TestModReturnsZero ();
311 void TestModReturnsNonZero ();
314 virtual void DoRun ();
333 "length constructed from meters has wrong value");
339 using TestEntry = std::tuple<Length, std::string>;
341 const double expectedMeters = 1;
342 const std::initializer_list<TestEntry> inputs {
343 std::make_tuple (
Length (1e9, Unit::Nanometer),
"nanometer"),
344 std::make_tuple (
Length (1e6, Unit::Micrometer),
"micrometer"),
345 std::make_tuple (
Length (1e3, Unit::Millimeter),
"millimeter"),
346 std::make_tuple (
Length (1e2, Unit::Centimeter),
"centimeter"),
347 std::make_tuple (
Length (1e-3, Unit::Kilometer),
"kilometer"),
348 std::make_tuple (
Length ( (1 / 1852.0), Unit::NauticalMile),
"nautical_mile")
351 for (
const TestEntry& entry : inputs )
353 const Length& l = std::get<0> (entry);
354 const std::string& context = std::get<1> (entry);
357 context <<
": constructed length from SI unit has wrong value");
364 using TestEntry = std::tuple<Length, std::string>;
366 const double expectedMeters = 0.3048;
367 const double tolerance = 0.0001;
369 const std::initializer_list<TestEntry> inputs {
370 std::make_tuple (
Length (12.0, Unit::Inch),
"inch"),
371 std::make_tuple (
Length (1.0, Unit::Foot),
"foot"),
372 std::make_tuple (
Length ((1 / 3.0), Unit::Yard),
"yard"),
373 std::make_tuple (
Length ((1 / 5280.0), Unit::Mile),
"mile"),
376 for (
const TestEntry& entry : inputs )
378 const Length& l = std::get<0> (entry);
379 const std::string& context = std::get<1> (entry);
382 "constructed length from US unit (" << context <<
") has wrong value");
389 const double value = 5;
390 Length original (value, Unit::Meter);
395 "copy constructed length has wrong value");
401 const double value = 5;
402 Length original (value, Unit::Meter);
404 Length copy (std::move (original));
407 "move constructed length has wrong value");
414 const std::initializer_list<std::string>& symbols)
416 const std::array<std::string, 2> SEPARATORS {{
"",
" "}};
418 for (
const std::string& symbol : symbols)
420 for (
const std::string& separator : SEPARATORS )
422 std::ostringstream stream;
424 stream << unitValue << separator << symbol;
428 std::ostringstream msg;
429 msg <<
"string constructed length has wrong value: '" << stream.str () <<
"'";
439 const double value = 5;
441 TestConstructLengthFromString (value, value, 0,
442 {
"m",
"meter",
"meters",
"metre",
"metres"});
448 const double value = 5;
449 const double expectedValue = 5e-9;
451 TestConstructLengthFromString (value, expectedValue, 0,
452 {
"nm",
"nanometer",
"nanometers",
453 "nanometre",
"nanometres"});
459 const double value = 5;
460 const double expectedValue = 5e-6;
461 const double tolerance = 1e-7;
463 TestConstructLengthFromString (value, expectedValue, tolerance,
464 {
"um",
"micrometer",
"micrometers",
465 "micrometre",
"micrometres"});
471 const double value = 5;
472 const double expectedValue = 5e-3;
473 const double tolerance = 1e-4;
475 TestConstructLengthFromString (value, expectedValue, tolerance,
476 {
"mm",
"millimeter",
"millimeters",
477 "millimetre",
"millimetres"});
483 const double value = 5;
484 const double expectedValue = 5e-2;
485 const double tolerance = 1e-3;
487 TestConstructLengthFromString (value, expectedValue, tolerance,
488 {
"cm",
"centimeter",
"centimeters",
489 "centimetre",
"centimetres"});
495 const double value = 5;
496 const double expectedValue = 5e3;
498 TestConstructLengthFromString (value, expectedValue, 0,
499 {
"km",
"kilometer",
"kilometers",
500 "kilometre",
"kilometres"});
506 const double value = 5;
507 const double expectedValue = 9260;
509 TestConstructLengthFromString (value, expectedValue, 0,
510 {
"nmi",
"nautical mile",
"nautical miles"});
515 const double value = 5;
516 const double expectedValue = 0.127;
517 const double tolerance = 1e-4;
519 TestConstructLengthFromString (value, expectedValue, tolerance,
520 {
"in",
"inch",
"inches"});
526 const double value = 5;
527 const double expectedValue = 1.524;
528 const double tolerance = 1e-4;
530 TestConstructLengthFromString (value, expectedValue, tolerance,
531 {
"ft",
"foot",
"feet"});
537 const double value = 5;
538 const double expectedValue = 4.572;
539 const double tolerance = 1e-4;
541 TestConstructLengthFromString (value, expectedValue, tolerance,
542 {
"yd",
"yard",
"yards"});
548 const double value = 5;
549 const double expectedValue = 8046.72;
550 const double tolerance = 1e-3;
552 TestConstructLengthFromString (value, expectedValue, tolerance,
553 {
"mi",
"mile",
"miles"});
556 #ifdef HAVE_BOOST_UNITS
558 LengthTestCase::TestConstructLengthFromBoostUnits ()
560 TestConstructLengthFromBoostUnitsMeters ();
561 TestConstructLengthFromBoostUnitsKiloMeters ();
562 TestConstructLengthFromBoostUnitsFeet ();
566 LengthTestCase::TestConstructLengthFromBoostUnitsMeters ()
568 namespace bu = boost::units;
570 auto meters = 5 * bu::si::meter;
575 "Construction from boost::units meters produced "
580 LengthTestCase::TestConstructLengthFromBoostUnitsKiloMeters ()
582 namespace bu = boost::units;
583 auto kilometer = bu::si::kilo * bu::si::meter;
585 const double expectedValue = 5000;
586 auto quantity = 5 * kilometer;
591 "Construction from boost::units kilometers produced "
596 LengthTestCase::TestConstructLengthFromBoostUnitsFeet ()
598 namespace bu = boost::units;
600 bu::us::foot_base_unit::unit_type Foot;
602 const double expectedValue = 3.048;
603 auto feet = 10 * Foot;
608 "Construction from boost::units foot produced "
616 using Builder = std::function<
Length (
double)>;
618 double inputValue = 10;
620 std::map<Unit, Builder> TESTDATA{
634 for (
auto& entry : TESTDATA)
636 Length expected (inputValue, entry.first);
638 Length output = entry.second (inputValue);
641 "The builder free function for " << entry.first <<
642 " did not create a Length with the correct value");
654 AssertFalse (result,
"TryParse returned true on bad input");
660 using TestInput = std::pair<double, std::string>;
661 using TestArgs = std::pair<double, double>;
662 std::map<TestInput, TestArgs> tests{
665 {{5,
"kilometer"}, {5e3, 0}},
666 {{5,
" kilometer"}, {5e3, 0}}
669 for (
auto& entry : tests)
671 TestInput input = entry.first;
672 TestArgs args = entry.second;
679 AssertTrue (result,
"TryParse returned false when expecting true");
681 std::stringstream stream;
682 stream <<
"Parsing input (" << input.first <<
", " << input.second
683 <<
") returned the wrong value";
693 const double value = 5;
695 Length original (value, Unit::Meter);
701 "copy assignment failed");
707 const double value = 5;
709 Length original (value, Unit::Meter);
712 copy = std::move (original);
715 "move assignment failed");
729 "quantity assignment failed");
735 const double value = 5;
736 Length one (value, Unit::Meter);
739 AssertTrue (one.
IsEqual (two),
"IsEqual returned false for equal lengths");
745 const double value = 5;
746 Length one (value, Unit::Meter);
747 Length two ( value, Unit::Foot );
749 AssertFalse (one.
IsEqual (two),
"IsEqual returned true for unequal lengths");
755 const double value = 5;
756 const double tolerance = 0.1;
758 Length one (value, Unit::Meter);
759 Length two ( (value + 0.1), Unit::Meter);
761 AssertTrue (one.
IsEqual (two, tolerance),
762 "IsEqual returned false for almost equal lengths");
768 const double value = 5;
769 const double tolerance = 0.01;
771 Length one (value, Unit::Meter);
772 Length two ( (value + 0.1), Unit::Meter);
774 AssertFalse (one.
IsEqual (two, tolerance),
775 "IsEqual returned true for almost equal lengths");
781 const double value = 5;
783 Length one (value, Unit::Meter);
784 Length two ( (value + 0.1), Unit::Meter);
787 "IsNotEqual returned false for not equal lengths");
793 const double value = 5;
795 Length one (value, Unit::Meter);
799 "IsNotEqual returned true for equal lengths");
805 const double tolerance = 0.001;
807 Length one ( 5.01, Unit::Meter);
808 Length two ( 5.02, Unit::Meter);
811 "IsNotEqual with tolerance returned false for not equal lengths");
817 const double tolerance = 0.01;
819 Length one ( 5.01, Unit::Meter);
820 Length two ( 5.02, Unit::Meter);
823 "IsNotEqual with tolerance returned true for not equal lengths");
829 const double value = 5;
831 Length one (value, Unit::Meter);
832 Length two ( (value + 0.1), Unit::Meter);
834 AssertTrue (one.
IsLess (two),
835 "IsLess returned false for non equal lengths");
841 const double value = 5;
843 Length one (value, Unit::Meter);
846 AssertFalse (one.
IsLess (two),
847 "IsLess returned true for equal lengths");
853 const double tolerance = 0.01;
855 Length one ( 5.1234, Unit::Meter );
856 Length two ( 5.1278, Unit::Meter );
858 AssertFalse (one.
IsLess (two, tolerance),
859 "IsLess with tolerance returned true");
865 Length one (2.0, Unit::Meter);
866 Length two (1.0, Unit::Meter);
869 "IsGreater returned false");
875 Length one (2.0, Unit::Meter);
876 Length two (1.0, Unit::Meter);
879 "IsGreater returned true");
885 const double tolerance = 0.01;
887 Length one (5.1234, Unit::Meter);
888 Length two (5.1278, Unit::Meter);
890 AssertFalse (two.
IsGreater (one, tolerance),
891 "IsGreater returned true");
897 Length l (1.0, Unit::Meter);
899 std::stringstream stream;
904 "unexpected output from operator<<");
910 const double value = 5;
914 std::stringstream stream;
916 stream << value <<
"m";
921 "unexpected length from operator>>");
928 const std::string& expectedOutput,
929 const std::string& context)
931 const std::string msg = context +
": unexpected output when serializing length";
933 std::ostringstream stream;
936 << std::setprecision (5)
945 Length l (1.0, Unit::Meter);
947 TestLengthSerialization (l, Unit::Nanometer,
"1000000000.00000 nm",
"nanometers");
948 TestLengthSerialization (l, Unit::Micrometer,
"1000000.00000 um",
"micrometers");
949 TestLengthSerialization (l, Unit::Millimeter,
"1000.00000 mm",
"millimeters");
950 TestLengthSerialization (l, Unit::Centimeter,
"100.00000 cm",
"centimeters");
951 TestLengthSerialization (l, Unit::Meter,
"1.00000 m",
"meters");
952 TestLengthSerialization (l, Unit::Kilometer,
"0.00100 km",
"kilometers");
953 TestLengthSerialization (l, Unit::NauticalMile,
"0.00054 nmi",
"nautical_mile");
954 TestLengthSerialization (l, Unit::Inch,
"39.37008 in",
"inches");
955 TestLengthSerialization (l, Unit::Foot,
"3.28084 ft",
"feet");
956 TestLengthSerialization (l, Unit::Yard,
"1.09361 yd",
"yards");
957 TestLengthSerialization (l, Unit::Mile,
"0.00062 mi",
"miles");
963 const double value = 5;
965 Length one ( value, Unit::Meter );
966 Length two ( value, Unit::Meter );
968 AssertTrue ( one == two,
969 "operator== returned false for equal lengths");
975 const double value = 5;
977 Length one ( value, Unit::Meter );
978 Length two ( value, Unit::Kilometer );
980 AssertFalse ( one == two,
981 "operator== returned true for non equal lengths");
987 const double value = 5;
989 Length one ( value, Unit::Meter );
990 Length two ( value, Unit::Kilometer);
992 AssertTrue ( one != two,
993 "operator!= returned false for non equal lengths");
1000 const double value = 5;
1002 Length one ( value, Unit::Meter );
1003 Length two ( value, Unit::Meter );
1005 AssertFalse ( one != two,
1006 "operator!= returned true for equal lengths");
1013 const double value = 5;
1015 Length one ( value, Unit::Meter );
1016 Length two ( value, Unit::Kilometer);
1018 AssertTrue ( one < two,
1019 "operator< returned false for smaller length");
1025 const double value = 5;
1027 Length one ( value, Unit::Meter );
1028 Length two ( value, Unit::Kilometer);
1030 AssertFalse ( two < one,
1031 "operator< returned true for larger length");
1037 const double value = 5;
1039 Length one ( value, Unit::Meter );
1040 Length two ( value, Unit::Kilometer);
1043 AssertTrue ( one <= two,
1044 "operator<= returned false for smaller length");
1046 AssertTrue ( one <= three,
1047 "operator<= returned false for equal lengths");
1053 const double value = 5;
1055 Length one ( value, Unit::Meter );
1056 Length two ( value, Unit::Kilometer);
1058 AssertFalse ( two <= one,
1059 "operator<= returned true for larger length");
1065 const double value = 5;
1067 Length one ( value, Unit::Meter );
1068 Length two ( value, Unit::Kilometer);
1070 AssertTrue ( two > one,
1071 "operator> returned false for larger length");
1077 const double value = 5;
1079 Length one ( value, Unit::Meter );
1080 Length two ( value, Unit::Kilometer);
1082 AssertFalse ( one > two,
1083 "operator> returned true for smaller length");
1089 const double value = 5;
1091 Length one ( value, Unit::Meter );
1092 Length two ( value, Unit::Kilometer);
1095 AssertTrue ( two >= one,
1096 "operator>= returned false for larger length");
1098 AssertTrue ( one >= three,
1099 "operator>= returned false for equal lengths");
1105 const double value = 5;
1107 Length one ( value, Unit::Meter );
1108 Length two ( value, Unit::Kilometer);
1110 AssertFalse ( one >= two,
1111 "operator>= returned true for smaller length");
1117 const double value = 1;
1118 const double expectedOutput = 2;
1120 Length one ( value, Unit::Meter );
1121 Length two ( value, Unit::Meter );
1123 Length result = one + two;
1126 "operator+ modified first operand");
1128 "operator+ modified second operand");
1130 "operator+ returned incorrect value");
1136 const double value = 1;
1137 const double expectedOutput = 2;
1139 Length one ( value, Unit::Meter );
1144 "operator+ modified first operand");
1146 "operator+ returned incorrect value");
1152 const double value = 1;
1153 const double expectedOutput = 2;
1155 Length one ( value, Unit::Meter );
1160 "operator+ modified first operand");
1162 "operator+ returned incorrect value");
1168 const double value = 1;
1169 const double expectedOutput = 0;
1171 Length one ( value, Unit::Meter );
1172 Length two ( value, Unit::Meter );
1174 Length result = one - two;
1177 "operator- modified first operand");
1179 "operator- modified second operand");
1181 "operator- returned incorrect value");
1187 const double value = 1;
1188 const double expectedOutput = 0;
1190 Length one ( value, Unit::Meter );
1195 "operator- modified first operand");
1197 "operator- returned incorrect value");
1203 const double value = 1;
1204 const double expectedOutput = 0;
1206 Length one ( value, Unit::Meter );
1211 "operator- modified second operand");
1213 "operator- returned incorrect value");
1219 const double value = 1;
1220 const double scalar = 5;
1221 const double expectedOutput = value * scalar;
1223 Length one ( value, Unit::Meter );
1224 Length result = one * scalar;
1227 "operator* modified first operand");
1229 "operator* returned incorrect value");
1235 const double value = 1;
1236 const double scalar = 5;
1237 const double expectedOutput = value * scalar;
1239 Length one ( value, Unit::Meter );
1240 Length result = scalar * one;
1243 "operator* modified second operand");
1245 "operator* returned incorrect value");
1251 const double value = 10;
1252 const double scalar = 5;
1253 const double expectedOutput = value / scalar;
1255 Length one ( value, Unit::Meter );
1256 Length result = one / scalar;
1259 "operator/ modified first operand");
1261 "operator/ returned incorrect value");
1267 const double valueOne = 100;
1268 const double valueTwo = 2;
1269 const double expectedOutput = valueOne / valueTwo;
1271 Length one ( valueOne, Unit::Meter );
1272 Length two ( valueTwo, Unit::Meter );
1274 double result = one / two;
1277 "operator/ modified first operand");
1279 "operator/ modified second operand");
1281 "operator/ returned incorrect value");
1288 const double value = 1;
1290 Length one ( value, Unit::Meter );
1293 double result = one / two;
1295 AssertTrue ( std::isnan (result),
1296 "operator/ did not return NaN when dividing by zero");
1302 const double topValue = 100;
1303 const double bottomValue = 20;
1304 const int64_t expectedOutput = 5;
1306 Length numerator (topValue, Unit::Meter);
1307 Length denominator (bottomValue, Unit::Meter);
1309 auto result =
Div (numerator, denominator);
1312 "Div() returned an incorrect value");
1318 const double topValue = 100;
1319 const double bottomValue = 20;
1320 const int64_t expectedOutput = 5;
1321 const int64_t expectedRemainder = 0;
1323 Length numerator (topValue, Unit::Meter);
1324 Length denominator (bottomValue, Unit::Meter);
1327 auto result =
Div (numerator, denominator, &remainder);
1330 "Div() returned an incorrect value");
1332 "Div() returned an incorrect remainder");
1338 const double topValue = 110;
1339 const double bottomValue = 20;
1340 const int64_t expectedOutput = 5;
1341 const int64_t expectedRemainder = 10;
1343 Length numerator (topValue, Unit::Meter);
1344 Length denominator (bottomValue, Unit::Meter);
1347 auto result =
Div (numerator, denominator, &remainder);
1350 "Div() returned an incorrect value");
1352 "Div() returned an incorrect remainder");
1358 Length numerator (10, Unit::Meter);
1359 Length denominator (2, Unit::Meter);
1361 auto result =
Mod (numerator, denominator);
1364 "Mod() returned a non zero value");
1370 Length numerator (14, Unit::Meter);
1371 Length denominator (3, Unit::Meter);
1372 const double expectedValue = 2;
1374 auto result =
Mod (numerator, denominator);
1377 "Mod() returned the wrong value");
1383 TestDefaultLengthIsZero ();
1385 TestConstructLengthFromQuantity ();
1387 TestConstructLengthFromSIUnits ();
1389 TestConstructLengthFromUSUnits ();
1391 TestLengthCopyConstructor ();
1393 TestLengthMoveConstructor ();
1395 TestConstructLengthFromMeterString ();
1396 TestConstructLengthFromNanoMeterString ();
1397 TestConstructLengthFromMicroMeterString ();
1398 TestConstructLengthFromMilliMeterString ();
1399 TestConstructLengthFromCentiMeterString ();
1400 TestConstructLengthFromKiloMeterString ();
1401 TestConstructLengthFromNauticalMileString ();
1402 TestConstructLengthFromInchString ();
1403 TestConstructLengthFromFootString ();
1404 TestConstructLengthFromYardString ();
1405 TestConstructLengthFromMileString ();
1407 #ifdef HAVE_BOOST_UNITS
1408 TestConstructLengthFromBoostUnits ();
1411 TestBuilderFreeFunctions ();
1413 TestTryParseReturnsFalse ();
1414 TestTryParseReturnsTrue ();
1416 TestCopyAssignment ();
1417 TestMoveAssignment ();
1418 TestQuantityAssignment ();
1420 TestIsEqualReturnsTrue ();
1421 TestIsEqualReturnsFalse ();
1422 TestIsEqualWithToleranceReturnsTrue ();
1423 TestIsEqualWithToleranceReturnsFalse ();
1424 TestIsNotEqualReturnsTrue ();
1425 TestIsNotEqualReturnsFalse ();
1426 TestIsNotEqualWithToleranceReturnsTrue ();
1427 TestIsNotEqualWithToleranceReturnsFalse ();
1428 TestIsLessReturnsTrue ();
1429 TestIsLessReturnsFalse ();
1430 TestIsLessWithToleranceReturnsFalse ();
1431 TestIsGreaterReturnsTrue ();
1432 TestIsGreaterReturnsFalse ();
1433 TestIsGreaterWithToleranceReturnsFalse ();
1435 TestOutputStreamOperator ();
1437 TestSerializeLengthWithUnit ();
1439 TestOperatorEqualsReturnsTrue ();
1440 TestOperatorEqualsReturnsFalse ();
1441 TestOperatorNotEqualsReturnsTrue ();
1442 TestOperatorNotEqualsReturnsFalse ();
1443 TestOperatorLessThanReturnsTrue ();
1444 TestOperatorLessThanReturnsFalse ();
1445 TestOperatorLessOrEqualReturnsTrue ();
1446 TestOperatorLessOrEqualReturnsFalse ();
1447 TestOperatorGreaterThanReturnsTrue ();
1448 TestOperatorGreaterThanReturnsFalse ();
1449 TestOperatorGreaterOrEqualReturnsTrue ();
1450 TestOperatorGreaterOrEqualReturnsFalse ();
1452 TestAddingTwoLengths ();
1453 TestAddingLengthAndQuantity ();
1454 TestAddingQuantityAndLength ();
1455 TestSubtractingTwoLengths ();
1456 TestSubtractingLengthAndQuantity ();
1457 TestSubtractingQuantityAndLength ();
1458 TestMultiplyLengthByScalar ();
1459 TestMultiplyScalarByLength ();
1460 TestDivideLengthByScalar ();
1461 TestDivideLengthByLength ();
1462 TestDivideLengthByLengthReturnsNaN ();
1464 TestDivReturnsCorrectResult ();
1465 TestDivReturnsZeroRemainder ();
1466 TestDivReturnsCorrectRemainder ();
1468 TestModReturnsZero ();
1469 TestModReturnsNonZero ();
1498 static TypeId GetTypeId ();
1515 void TestAttributeConstructor ();
1520 void TestAttributeSerialization ();
1525 void TestAttributeDeserialization ();
1530 void TestObjectAttribute ();
1535 void TestSetAttributeUsingStringValue ();
1538 virtual void DoRun ();
1544 static TypeId tid =
TypeId (
"LengthValueTestCase::TestObject")
1546 .SetGroupName (
"Test")
1548 .AddAttribute (
"Length",
1578 "Length attribute serialization has wrong output");
1587 std::ostringstream stream;
1594 "Length attribute deserialization failed");
1596 "Length attribute has wrong value after deserialization");
1602 Length expected (5, Unit::Kilometer);
1605 obj->SetAttribute (
"Length",
LengthValue (expected));
1608 obj->GetAttribute (
"Length", val);
1611 "Length attribute does not have expected value");
1617 Length expected (5, Unit::Kilometer);
1620 std::stringstream stream;
1621 stream << expected.
As (Unit::Kilometer);
1623 obj->SetAttribute (
"Length",
StringValue (stream.str()));
1626 obj->GetAttribute (
"Length", val);
1629 "Length attribute does not have expected value");
1635 TestAttributeConstructor ();
1636 TestAttributeSerialization ();
1637 TestAttributeDeserialization ();
1638 TestObjectAttribute ();
1639 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.
virtual void DoRun()
Implementation to actually run this TestCase.
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.
virtual ~LengthTestCase()=default
Destructor.
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 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.
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.
static TypeId GetTypeId()
Test case for LengthValue attribute.
virtual ~LengthValueTestCase()
Destructor.
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.
virtual void DoRun()
Implementation to actually run this TestCase.
void TestSetAttributeUsingStringValue()
Test that a StringValue is converted to LengthValue.
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.
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.
static std::tuple< bool, Length > TryParse(double value, const std::string &unit)
Attempt to construct a Length object from a value and a unit string.
bool IsNotEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is not equal in value to this instance.
Define LengthValue class to support using Length objects as attributes.
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
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.
Ptr< const AttributeChecker > MakeLengthChecker(void)
Ptr< const AttributeAccessor > MakeLengthAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Length KiloMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length MilliMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length NauticalMiles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Yards(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Feet(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Mod(const Length &numerator, const Length &denominator)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length MicroMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Miles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Meters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length CentiMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length NanoMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Length Inches(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
#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.