A Discrete-Event Network Simulator
API
length-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 Lawrence Livermore National Laboratory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathew Bielejeski<bielejeski1@llnl.gov>
19  */
20 
21 #include "ns3/length.h"
22 #include "ns3/log.h"
23 #include "ns3/object.h"
24 #include "ns3/string.h"
25 #include "ns3/test.h"
26 
27 #ifdef HAVE_BOOST
28 #include <boost/units/base_units/us/foot.hpp>
29 #include <boost/units/systems/si.hpp>
30 #include <boost/units/systems/si/prefixes.hpp>
31 #endif
32 
33 #include <array>
34 #include <cmath>
35 #include <functional>
36 #include <initializer_list>
37 #include <iomanip>
38 #include <limits>
39 #include <map>
40 #include <sstream>
41 #include <string>
42 #include <tuple>
43 
57 using namespace ns3;
58 
63 
67 class LengthTestCase : public TestCase
68 {
69 public:
74  : TestCase ("length-tests")
75  {}
76 
80  virtual ~LengthTestCase () = default;
81 
82 protected:
89  void AssertFalse (bool condition, std::string msg)
90  {
91  NS_TEST_ASSERT_MSG_EQ (condition, false, msg);
92  }
93 
100  void AssertTrue (bool condition, std::string msg)
101  {
102  NS_TEST_ASSERT_MSG_EQ (condition, true, msg);
103  }
104 
105 private:
109  void TestDefaultLengthIsZero ();
110 
114  void TestConstructLengthFromQuantity ();
115 
120  void TestConstructLengthFromSIUnits ();
121 
126  void TestConstructLengthFromUSUnits ();
127 
132  void TestLengthCopyConstructor ();
133 
138  void TestLengthMoveConstructor ();
139 
144  void TestConstructLengthFromString (double unitValue,
145  double meterValue,
146  double tolerance,
147  const std::initializer_list<std::string>& symbols);
148 
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
163 
167  void TestConstructLengthFromBoostUnits ();
168  void TestConstructLengthFromBoostUnitsMeters ();
169  void TestConstructLengthFromBoostUnitsKiloMeters ();
170  void TestConstructLengthFromBoostUnitsFeet ();
172 #endif
173 
178  void TestBuilderFreeFunctions ();
184  void TestTryParseReturnsFalse ();
185 
189  void TestTryParseReturnsTrue ();
190 
191 
196  void TestCopyAssignment ();
197 
202  void TestMoveAssignment ();
203 
207  void TestQuantityAssignment ();
208 
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 ();
233 
238  void TestInputStreamOperator ();
239 
251  template<class T>
252  void TestLengthSerialization (const Length& l,
253  const T& unit,
254  const std::string& expectedOutput,
255  const std::string& context);
256 
260  void TestSerializeLengthWithUnit ();
261 
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 ();
315 };
316 
317 void
319 {
320  Length l;
321 
322  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), 0, "Default value of Length is not 0");
323 }
324 
325 void
327 {
328  const Length::Quantity VALUE (5.0, Unit::Meter);
329 
330  Length l (VALUE);
331 
332  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), VALUE.Value (),
333  "length constructed from meters has wrong value");
334 }
335 
336 void
338 {
339  using TestEntry = std::tuple<Length, std::string>;
340 
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")
349  };
350 
351  for (const TestEntry& entry : inputs )
352  {
353  const Length& l = std::get<0> (entry);
354  const std::string& context = std::get<1> (entry);
355 
356  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), expectedMeters,
357  context << ": constructed length from SI unit has wrong value");
358  }
359 }
360 
361 void
363 {
364  using TestEntry = std::tuple<Length, std::string>;
365 
366  const double expectedMeters = 0.3048;
367  const double tolerance = 0.0001;
368 
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"),
374  };
375 
376  for (const TestEntry& entry : inputs )
377  {
378  const Length& l = std::get<0> (entry);
379  const std::string& context = std::get<1> (entry);
380 
381  NS_TEST_ASSERT_MSG_EQ_TOL (l.GetDouble (), expectedMeters, tolerance,
382  "constructed length from US unit (" << context << ") has wrong value");
383  }
384 }
385 
386 void
388 {
389  const double value = 5;
390  Length original (value, Unit::Meter);
391 
392  Length copy (original);
393 
394  NS_TEST_ASSERT_MSG_EQ (copy.GetDouble (), original.GetDouble (),
395  "copy constructed length has wrong value");
396 }
397 
398 void
400 {
401  const double value = 5;
402  Length original (value, Unit::Meter);
403 
404  Length copy (std::move (original));
405 
406  NS_TEST_ASSERT_MSG_EQ (copy.GetDouble (), value,
407  "move constructed length has wrong value");
408 }
409 
410 void
412  double meterValue,
413  double tolerance,
414  const std::initializer_list<std::string>& symbols)
415 {
416  const std::array<std::string, 2> SEPARATORS {{"", " "}};
417 
418  for (const std::string& symbol : symbols)
419  {
420  for ( const std::string& separator : SEPARATORS )
421  {
422  std::ostringstream stream;
423 
424  stream << unitValue << separator << symbol;
425 
426  Length l (stream.str ());
427 
428  std::ostringstream msg;
429  msg << "string constructed length has wrong value: '" << stream.str () << "'";
430 
431  NS_TEST_ASSERT_MSG_EQ_TOL (l.GetDouble (), meterValue, tolerance, msg.str ());
432  }
433  }
434 }
435 
436 void
438 {
439  const double value = 5;
440 
441  TestConstructLengthFromString (value, value, 0,
442  {"m", "meter", "meters", "metre", "metres"});
443 }
444 
445 void
447 {
448  const double value = 5;
449  const double expectedValue = 5e-9;
450 
451  TestConstructLengthFromString (value, expectedValue, 0,
452  {"nm", "nanometer", "nanometers",
453  "nanometre", "nanometres"});
454 }
455 
456 void
458 {
459  const double value = 5;
460  const double expectedValue = 5e-6;
461  const double tolerance = 1e-7;
462 
463  TestConstructLengthFromString (value, expectedValue, tolerance,
464  {"um", "micrometer", "micrometers",
465  "micrometre", "micrometres"});
466 }
467 
468 void
470 {
471  const double value = 5;
472  const double expectedValue = 5e-3;
473  const double tolerance = 1e-4;
474 
475  TestConstructLengthFromString (value, expectedValue, tolerance,
476  {"mm", "millimeter", "millimeters",
477  "millimetre", "millimetres"});
478 }
479 
480 void
482 {
483  const double value = 5;
484  const double expectedValue = 5e-2;
485  const double tolerance = 1e-3;
486 
487  TestConstructLengthFromString (value, expectedValue, tolerance,
488  {"cm", "centimeter", "centimeters",
489  "centimetre", "centimetres"});
490 }
491 
492 void
494 {
495  const double value = 5;
496  const double expectedValue = 5e3;
497 
498  TestConstructLengthFromString (value, expectedValue, 0,
499  {"km", "kilometer", "kilometers",
500  "kilometre", "kilometres"});
501 }
502 
503 void
505 {
506  const double value = 5;
507  const double expectedValue = 9260;
508 
509  TestConstructLengthFromString (value, expectedValue, 0,
510  {"nmi", "nautical mile", "nautical miles"});
511 }
512 void
514 {
515  const double value = 5;
516  const double expectedValue = 0.127;
517  const double tolerance = 1e-4;
518 
519  TestConstructLengthFromString (value, expectedValue, tolerance,
520  {"in", "inch", "inches"});
521 }
522 
523 void
525 {
526  const double value = 5;
527  const double expectedValue = 1.524;
528  const double tolerance = 1e-4;
529 
530  TestConstructLengthFromString (value, expectedValue, tolerance,
531  {"ft", "foot", "feet"});
532 }
533 
534 void
536 {
537  const double value = 5;
538  const double expectedValue = 4.572;
539  const double tolerance = 1e-4;
540 
541  TestConstructLengthFromString (value, expectedValue, tolerance,
542  {"yd", "yard", "yards"});
543 }
544 
545 void
547 {
548  const double value = 5;
549  const double expectedValue = 8046.72;
550  const double tolerance = 1e-3;
551 
552  TestConstructLengthFromString (value, expectedValue, tolerance,
553  {"mi", "mile", "miles"});
554 }
555 
556 #ifdef HAVE_BOOST_UNITS
557 void
558 LengthTestCase::TestConstructLengthFromBoostUnits ()
559 {
560  TestConstructLengthFromBoostUnitsMeters ();
561  TestConstructLengthFromBoostUnitsKiloMeters ();
562  TestConstructLengthFromBoostUnitsFeet ();
563 }
564 
565 void
566 LengthTestCase::TestConstructLengthFromBoostUnitsMeters ()
567 {
568  namespace bu = boost::units;
569 
570  auto meters = 5 * bu::si::meter;
571 
572  Length l (meters);
573 
574  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), meters.value (),
575  "Construction from boost::units meters produced "
576  "incorrect value");
577 }
578 
579 void
580 LengthTestCase::TestConstructLengthFromBoostUnitsKiloMeters ()
581 {
582  namespace bu = boost::units;
583  auto kilometer = bu::si::kilo * bu::si::meter;
584 
585  const double expectedValue = 5000;
586  auto quantity = 5 * kilometer;
587 
588  Length l (quantity);
589 
590  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), expectedValue,
591  "Construction from boost::units kilometers produced "
592  "incorrect value");
593 }
594 
595 void
596 LengthTestCase::TestConstructLengthFromBoostUnitsFeet ()
597 {
598  namespace bu = boost::units;
599 
600  bu::us::foot_base_unit::unit_type Foot;
601 
602  const double expectedValue = 3.048;
603  auto feet = 10 * Foot;
604 
605  Length l (feet);
606 
607  NS_TEST_ASSERT_MSG_EQ_TOL (l.GetDouble (), expectedValue, 0.001,
608  "Construction from boost::units foot produced "
609  "incorrect value");
610 }
611 #endif
612 
613 void
615 {
616  using Builder = std::function<Length (double)>;
617 
618  double inputValue = 10;
619 
620  std::map<Unit, Builder> TESTDATA{
621  {Unit::Nanometer, NanoMeters},
622  {Unit::Micrometer, MicroMeters},
623  {Unit::Millimeter, MilliMeters},
624  {Unit::Centimeter, CentiMeters},
625  {Unit::Meter, Meters},
626  {Unit::Kilometer, KiloMeters},
627  {Unit::NauticalMile, NauticalMiles},
628  {Unit::Inch, Inches},
629  {Unit::Foot, Feet},
630  {Unit::Yard, Yards},
631  {Unit::Mile, Miles}
632  };
633 
634  for (auto& entry : TESTDATA)
635  {
636  Length expected (inputValue, entry.first);
637 
638  Length output = entry.second (inputValue);
639 
640  NS_TEST_ASSERT_MSG_EQ (output, expected,
641  "The builder free function for " << entry.first <<
642  " did not create a Length with the correct value");
643  }
644 }
645 
646 void
648 {
649  bool result;
650  Length l;
651 
652  std::tie (result, l) = Length::TryParse (1, "");
653 
654  AssertFalse (result, "TryParse returned true on bad input");
655 }
656 
657 void
659 {
660  using TestInput = std::pair<double, std::string>;
661  using TestArgs = std::pair<double, double>;
662  std::map<TestInput, TestArgs> tests{
663  {{5, "m"}, {5, 0}},
664  {{5, " m"}, {5, 0}},
665  {{5, "kilometer"}, {5e3, 0}},
666  {{5, " kilometer"}, {5e3, 0}}
667  };
668 
669  for (auto& entry : tests)
670  {
671  TestInput input = entry.first;
672  TestArgs args = entry.second;
673 
674  bool result;
675  Length l;
676 
677  std::tie (result, l) = Length::TryParse (input.first, input.second);
678 
679  AssertTrue (result, "TryParse returned false when expecting true");
680 
681  std::stringstream stream;
682  stream << "Parsing input (" << input.first << ", " << input.second
683  << ") returned the wrong value";
684 
685  NS_TEST_ASSERT_MSG_EQ_TOL (l.GetDouble (), args.first, args.second, stream.str ());
686  }
687 
688 }
689 
690 void
692 {
693  const double value = 5;
694 
695  Length original (value, Unit::Meter);
696 
697  Length copy;
698  copy = original;
699 
700  NS_TEST_ASSERT_MSG_EQ (copy.GetDouble (), original.GetDouble (),
701  "copy assignment failed");
702 }
703 
704 void
706 {
707  const double value = 5;
708 
709  Length original (value, Unit::Meter);
710 
711  Length copy;
712  copy = std::move (original);
713 
714  NS_TEST_ASSERT_MSG_EQ (copy.GetDouble (), value,
715  "move assignment failed");
716 }
717 
718 void
720 {
721  Length::Quantity input (5, Unit::Kilometer);
722 
723  Length l;
724  Length expected (input);
725 
726  l = input;
727 
728  NS_TEST_ASSERT_MSG_EQ (l, expected,
729  "quantity assignment failed");
730 }
731 
732 void
734 {
735  const double value = 5;
736  Length one (value, Unit::Meter);
737  Length two (one);
738 
739  AssertTrue (one.IsEqual (two), "IsEqual returned false for equal lengths");
740 }
741 
742 void
744 {
745  const double value = 5;
746  Length one (value, Unit::Meter);
747  Length two ( value, Unit::Foot );
748 
749  AssertFalse (one.IsEqual (two), "IsEqual returned true for unequal lengths");
750 }
751 
752 void
754 {
755  const double value = 5;
756  const double tolerance = 0.1;
757 
758  Length one (value, Unit::Meter);
759  Length two ( (value + 0.1), Unit::Meter);
760 
761  AssertTrue (one.IsEqual (two, tolerance),
762  "IsEqual returned false for almost equal lengths");
763 }
764 
765 void
767 {
768  const double value = 5;
769  const double tolerance = 0.01;
770 
771  Length one (value, Unit::Meter);
772  Length two ( (value + 0.1), Unit::Meter);
773 
774  AssertFalse (one.IsEqual (two, tolerance),
775  "IsEqual returned true for almost equal lengths");
776 }
777 
778 void
780 {
781  const double value = 5;
782 
783  Length one (value, Unit::Meter);
784  Length two ( (value + 0.1), Unit::Meter);
785 
786  AssertTrue (one.IsNotEqual (two),
787  "IsNotEqual returned false for not equal lengths");
788 }
789 
790 void
792 {
793  const double value = 5;
794 
795  Length one (value, Unit::Meter);
796  Length two ( one );
797 
798  AssertFalse (one.IsNotEqual (two),
799  "IsNotEqual returned true for equal lengths");
800 }
801 
802 void
804 {
805  const double tolerance = 0.001;
806 
807  Length one ( 5.01, Unit::Meter);
808  Length two ( 5.02, Unit::Meter);
809 
810  AssertTrue (one.IsNotEqual (two, tolerance),
811  "IsNotEqual with tolerance returned false for not equal lengths");
812 }
813 
814 void
816 {
817  const double tolerance = 0.01;
818 
819  Length one ( 5.01, Unit::Meter);
820  Length two ( 5.02, Unit::Meter);
821 
822  AssertFalse (one.IsNotEqual (two, tolerance),
823  "IsNotEqual with tolerance returned true for not equal lengths");
824 }
825 
826 void
828 {
829  const double value = 5;
830 
831  Length one (value, Unit::Meter);
832  Length two ( (value + 0.1), Unit::Meter);
833 
834  AssertTrue (one.IsLess (two),
835  "IsLess returned false for non equal lengths");
836 }
837 
838 void
840 {
841  const double value = 5;
842 
843  Length one (value, Unit::Meter);
844  Length two ( one );
845 
846  AssertFalse (one.IsLess (two),
847  "IsLess returned true for equal lengths");
848 }
849 
850 void
852 {
853  const double tolerance = 0.01;
854 
855  Length one ( 5.1234, Unit::Meter );
856  Length two ( 5.1278, Unit::Meter );
857 
858  AssertFalse (one.IsLess (two, tolerance),
859  "IsLess with tolerance returned true");
860 }
861 
862 void
864 {
865  Length one (2.0, Unit::Meter);
866  Length two (1.0, Unit::Meter);
867 
868  AssertTrue (one.IsGreater (two),
869  "IsGreater returned false");
870 }
871 
872 void
874 {
875  Length one (2.0, Unit::Meter);
876  Length two (1.0, Unit::Meter);
877 
878  AssertFalse (two.IsGreater (one),
879  "IsGreater returned true");
880 }
881 
882 void
884 {
885  const double tolerance = 0.01;
886 
887  Length one (5.1234, Unit::Meter);
888  Length two (5.1278, Unit::Meter);
889 
890  AssertFalse (two.IsGreater (one, tolerance),
891  "IsGreater returned true");
892 }
893 
894 void
896 {
897  Length l (1.0, Unit::Meter);
898 
899  std::stringstream stream;
900 
901  stream << l;
902 
903  NS_TEST_ASSERT_MSG_EQ (stream.str (), "1 m",
904  "unexpected output from operator<<");
905 }
906 
907 void
909 {
910  const double value = 5;
911 
912  Length l;
913 
914  std::stringstream stream;
915 
916  stream << value << "m";
917 
918  stream >> l;
919 
920  NS_TEST_ASSERT_MSG_EQ (l.GetDouble (), value,
921  "unexpected length from operator>>");
922 }
923 
924 template<class T>
925 void
927  const T& unit,
928  const std::string& expectedOutput,
929  const std::string& context)
930 {
931  const std::string msg = context + ": unexpected output when serializing length";
932 
933  std::ostringstream stream;
934 
935  stream << std::fixed
936  << std::setprecision (5)
937  << l.As (unit);
938 
939  NS_TEST_ASSERT_MSG_EQ (stream.str (), expectedOutput, msg);
940 }
941 
942 void
944 {
945  Length l (1.0, Unit::Meter);
946 
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");
958 }
959 
960 void
962 {
963  const double value = 5;
964 
965  Length one ( value, Unit::Meter );
966  Length two ( value, Unit::Meter );
967 
968  AssertTrue ( one == two,
969  "operator== returned false for equal lengths");
970 }
971 
972 void
974 {
975  const double value = 5;
976 
977  Length one ( value, Unit::Meter );
978  Length two ( value, Unit::Kilometer );
979 
980  AssertFalse ( one == two,
981  "operator== returned true for non equal lengths");
982 }
983 
984 void
986 {
987  const double value = 5;
988 
989  Length one ( value, Unit::Meter );
990  Length two ( value, Unit::Kilometer);
991 
992  AssertTrue ( one != two,
993  "operator!= returned false for non equal lengths");
994 
995 }
996 
997 void
999 {
1000  const double value = 5;
1001 
1002  Length one ( value, Unit::Meter );
1003  Length two ( value, Unit::Meter );
1004 
1005  AssertFalse ( one != two,
1006  "operator!= returned true for equal lengths");
1007 
1008 }
1009 
1010 void
1012 {
1013  const double value = 5;
1014 
1015  Length one ( value, Unit::Meter );
1016  Length two ( value, Unit::Kilometer);
1017 
1018  AssertTrue ( one < two,
1019  "operator< returned false for smaller length");
1020 }
1021 
1022 void
1024 {
1025  const double value = 5;
1026 
1027  Length one ( value, Unit::Meter );
1028  Length two ( value, Unit::Kilometer);
1029 
1030  AssertFalse ( two < one,
1031  "operator< returned true for larger length");
1032 }
1033 
1034 void
1036 {
1037  const double value = 5;
1038 
1039  Length one ( value, Unit::Meter );
1040  Length two ( value, Unit::Kilometer);
1041  Length three ( one );
1042 
1043  AssertTrue ( one <= two,
1044  "operator<= returned false for smaller length");
1045 
1046  AssertTrue ( one <= three,
1047  "operator<= returned false for equal lengths");
1048 }
1049 
1050 void
1052 {
1053  const double value = 5;
1054 
1055  Length one ( value, Unit::Meter );
1056  Length two ( value, Unit::Kilometer);
1057 
1058  AssertFalse ( two <= one,
1059  "operator<= returned true for larger length");
1060 }
1061 
1062 void
1064 {
1065  const double value = 5;
1066 
1067  Length one ( value, Unit::Meter );
1068  Length two ( value, Unit::Kilometer);
1069 
1070  AssertTrue ( two > one,
1071  "operator> returned false for larger length");
1072 }
1073 
1074 void
1076 {
1077  const double value = 5;
1078 
1079  Length one ( value, Unit::Meter );
1080  Length two ( value, Unit::Kilometer);
1081 
1082  AssertFalse ( one > two,
1083  "operator> returned true for smaller length");
1084 }
1085 
1086 void
1088 {
1089  const double value = 5;
1090 
1091  Length one ( value, Unit::Meter );
1092  Length two ( value, Unit::Kilometer);
1093  Length three ( one );
1094 
1095  AssertTrue ( two >= one,
1096  "operator>= returned false for larger length");
1097 
1098  AssertTrue ( one >= three,
1099  "operator>= returned false for equal lengths");
1100 }
1101 
1102 void
1104 {
1105  const double value = 5;
1106 
1107  Length one ( value, Unit::Meter );
1108  Length two ( value, Unit::Kilometer);
1109 
1110  AssertFalse ( one >= two,
1111  "operator>= returned true for smaller length");
1112 }
1113 
1114 void
1116 {
1117  const double value = 1;
1118  const double expectedOutput = 2;
1119 
1120  Length one ( value, Unit::Meter );
1121  Length two ( value, Unit::Meter );
1122 
1123  Length result = one + two;
1124 
1125  NS_TEST_ASSERT_MSG_EQ ( one.GetDouble (), value,
1126  "operator+ modified first operand");
1127  NS_TEST_ASSERT_MSG_EQ ( two.GetDouble (), value,
1128  "operator+ modified second operand");
1129  NS_TEST_ASSERT_MSG_EQ ( result.GetDouble (), expectedOutput,
1130  "operator+ returned incorrect value");
1131 }
1132 
1133 void
1135 {
1136  const double value = 1;
1137  const double expectedOutput = 2;
1138 
1139  Length one ( value, Unit::Meter );
1140 
1141  Length result = one + Length::Quantity (value, Unit::Meter);
1142 
1143  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1144  "operator+ modified first operand");
1145  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1146  "operator+ returned incorrect value");
1147 }
1148 
1149 void
1151 {
1152  const double value = 1;
1153  const double expectedOutput = 2;
1154 
1155  Length one ( value, Unit::Meter );
1156 
1157  Length result = Length::Quantity (value, Unit::Meter) + one;
1158 
1159  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1160  "operator+ modified first operand");
1161  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1162  "operator+ returned incorrect value");
1163 }
1164 
1165 void
1167 {
1168  const double value = 1;
1169  const double expectedOutput = 0;
1170 
1171  Length one ( value, Unit::Meter );
1172  Length two ( value, Unit::Meter );
1173 
1174  Length result = one - two;
1175 
1176  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1177  "operator- modified first operand");
1178  NS_TEST_ASSERT_MSG_EQ (two.GetDouble (), value,
1179  "operator- modified second operand");
1180  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1181  "operator- returned incorrect value");
1182 }
1183 
1184 void
1186 {
1187  const double value = 1;
1188  const double expectedOutput = 0;
1189 
1190  Length one ( value, Unit::Meter );
1191 
1192  Length result = one - Length::Quantity ( value, Unit::Meter);
1193 
1194  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1195  "operator- modified first operand");
1196  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1197  "operator- returned incorrect value");
1198 }
1199 
1200 void
1202 {
1203  const double value = 1;
1204  const double expectedOutput = 0;
1205 
1206  Length one ( value, Unit::Meter );
1207 
1208  Length result = Length::Quantity (value, Unit::Meter) - one;
1209 
1210  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1211  "operator- modified second operand");
1212  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1213  "operator- returned incorrect value");
1214 }
1215 
1216 void
1218 {
1219  const double value = 1;
1220  const double scalar = 5;
1221  const double expectedOutput = value * scalar;
1222 
1223  Length one ( value, Unit::Meter );
1224  Length result = one * scalar;
1225 
1226  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1227  "operator* modified first operand");
1228  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1229  "operator* returned incorrect value");
1230 }
1231 
1232 void
1234 {
1235  const double value = 1;
1236  const double scalar = 5;
1237  const double expectedOutput = value * scalar;
1238 
1239  Length one ( value, Unit::Meter );
1240  Length result = scalar * one;
1241 
1242  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1243  "operator* modified second operand");
1244  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1245  "operator* returned incorrect value");
1246 }
1247 
1248 void
1250 {
1251  const double value = 10;
1252  const double scalar = 5;
1253  const double expectedOutput = value / scalar;
1254 
1255  Length one ( value, Unit::Meter );
1256  Length result = one / scalar;
1257 
1258  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), value,
1259  "operator/ modified first operand");
1260  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedOutput,
1261  "operator/ returned incorrect value");
1262 }
1263 
1264 void
1266 {
1267  const double valueOne = 100;
1268  const double valueTwo = 2;
1269  const double expectedOutput = valueOne / valueTwo;
1270 
1271  Length one ( valueOne, Unit::Meter );
1272  Length two ( valueTwo, Unit::Meter );
1273 
1274  double result = one / two;
1275 
1276  NS_TEST_ASSERT_MSG_EQ (one.GetDouble (), valueOne,
1277  "operator/ modified first operand");
1278  NS_TEST_ASSERT_MSG_EQ (two.GetDouble (), valueTwo,
1279  "operator/ modified second operand");
1280  NS_TEST_ASSERT_MSG_EQ (result, expectedOutput,
1281  "operator/ returned incorrect value");
1282 
1283 }
1284 
1285 void
1287 {
1288  const double value = 1;
1289 
1290  Length one ( value, Unit::Meter );
1291  Length two;
1292 
1293  double result = one / two;
1294 
1295  AssertTrue ( std::isnan (result),
1296  "operator/ did not return NaN when dividing by zero");
1297 }
1298 
1299 void
1301 {
1302  const double topValue = 100;
1303  const double bottomValue = 20;
1304  const int64_t expectedOutput = 5;
1305 
1306  Length numerator (topValue, Unit::Meter);
1307  Length denominator (bottomValue, Unit::Meter);
1308 
1309  auto result = Div (numerator, denominator);
1310 
1311  NS_TEST_ASSERT_MSG_EQ (result, expectedOutput,
1312  "Div() returned an incorrect value");
1313 }
1314 
1315 void
1317 {
1318  const double topValue = 100;
1319  const double bottomValue = 20;
1320  const int64_t expectedOutput = 5;
1321  const int64_t expectedRemainder = 0;
1322 
1323  Length numerator (topValue, Unit::Meter);
1324  Length denominator (bottomValue, Unit::Meter);
1325  Length remainder;
1326 
1327  auto result = Div (numerator, denominator, &remainder);
1328 
1329  NS_TEST_ASSERT_MSG_EQ (result, expectedOutput,
1330  "Div() returned an incorrect value");
1331  NS_TEST_ASSERT_MSG_EQ (remainder.GetDouble (), expectedRemainder,
1332  "Div() returned an incorrect remainder");
1333 }
1334 
1335 void
1337 {
1338  const double topValue = 110;
1339  const double bottomValue = 20;
1340  const int64_t expectedOutput = 5;
1341  const int64_t expectedRemainder = 10;
1342 
1343  Length numerator (topValue, Unit::Meter);
1344  Length denominator (bottomValue, Unit::Meter);
1345  Length remainder;
1346 
1347  auto result = Div (numerator, denominator, &remainder);
1348 
1349  NS_TEST_ASSERT_MSG_EQ (result, expectedOutput,
1350  "Div() returned an incorrect value");
1351  NS_TEST_ASSERT_MSG_EQ (remainder.GetDouble (), expectedRemainder,
1352  "Div() returned an incorrect remainder");
1353 }
1354 
1355 void
1357 {
1358  Length numerator (10, Unit::Meter);
1359  Length denominator (2, Unit::Meter);
1360 
1361  auto result = Mod (numerator, denominator);
1362 
1363  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), 0,
1364  "Mod() returned a non zero value");
1365 }
1366 
1367 void
1369 {
1370  Length numerator (14, Unit::Meter);
1371  Length denominator (3, Unit::Meter);
1372  const double expectedValue = 2;
1373 
1374  auto result = Mod (numerator, denominator);
1375 
1376  NS_TEST_ASSERT_MSG_EQ (result.GetDouble (), expectedValue,
1377  "Mod() returned the wrong value");
1378 }
1379 
1380 void
1382 {
1383  TestDefaultLengthIsZero ();
1384 
1385  TestConstructLengthFromQuantity ();
1386 
1387  TestConstructLengthFromSIUnits ();
1388 
1389  TestConstructLengthFromUSUnits ();
1390 
1391  TestLengthCopyConstructor ();
1392 
1393  TestLengthMoveConstructor ();
1394 
1395  TestConstructLengthFromMeterString ();
1396  TestConstructLengthFromNanoMeterString ();
1397  TestConstructLengthFromMicroMeterString ();
1398  TestConstructLengthFromMilliMeterString ();
1399  TestConstructLengthFromCentiMeterString ();
1400  TestConstructLengthFromKiloMeterString ();
1401  TestConstructLengthFromNauticalMileString ();
1402  TestConstructLengthFromInchString ();
1403  TestConstructLengthFromFootString ();
1404  TestConstructLengthFromYardString ();
1405  TestConstructLengthFromMileString ();
1406 
1407 #ifdef HAVE_BOOST_UNITS
1408  TestConstructLengthFromBoostUnits ();
1409 #endif
1410 
1411  TestBuilderFreeFunctions ();
1412 
1413  TestTryParseReturnsFalse ();
1414  TestTryParseReturnsTrue ();
1415 
1416  TestCopyAssignment ();
1417  TestMoveAssignment ();
1418  TestQuantityAssignment ();
1419 
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 ();
1434 
1435  TestOutputStreamOperator ();
1436 
1437  TestSerializeLengthWithUnit ();
1438 
1439  TestOperatorEqualsReturnsTrue ();
1440  TestOperatorEqualsReturnsFalse ();
1441  TestOperatorNotEqualsReturnsTrue ();
1442  TestOperatorNotEqualsReturnsFalse ();
1443  TestOperatorLessThanReturnsTrue ();
1444  TestOperatorLessThanReturnsFalse ();
1445  TestOperatorLessOrEqualReturnsTrue ();
1446  TestOperatorLessOrEqualReturnsFalse ();
1447  TestOperatorGreaterThanReturnsTrue ();
1448  TestOperatorGreaterThanReturnsFalse ();
1449  TestOperatorGreaterOrEqualReturnsTrue ();
1450  TestOperatorGreaterOrEqualReturnsFalse ();
1451 
1452  TestAddingTwoLengths ();
1453  TestAddingLengthAndQuantity ();
1454  TestAddingQuantityAndLength ();
1455  TestSubtractingTwoLengths ();
1456  TestSubtractingLengthAndQuantity ();
1457  TestSubtractingQuantityAndLength ();
1458  TestMultiplyLengthByScalar ();
1459  TestMultiplyScalarByLength ();
1460  TestDivideLengthByScalar ();
1461  TestDivideLengthByLength ();
1462  TestDivideLengthByLengthReturnsNaN ();
1463 
1464  TestDivReturnsCorrectResult ();
1465  TestDivReturnsZeroRemainder ();
1466  TestDivReturnsCorrectRemainder ();
1467 
1468  TestModReturnsZero ();
1469  TestModReturnsNonZero ();
1470 }
1471 
1478 {
1479 public:
1484  : TestCase ("length-value-tests")
1485  {}
1486 
1491  {}
1492 
1493 private:
1494  //class with Length attribute
1495  class TestObject : public Object
1496  {
1497  public:
1498  static TypeId GetTypeId ();
1499 
1501  : m_length ()
1502  {}
1503 
1504  virtual ~TestObject ()
1505  {}
1506 
1507  private:
1509  };
1510 
1511 private:
1515  void TestAttributeConstructor ();
1516 
1520  void TestAttributeSerialization ();
1521 
1525  void TestAttributeDeserialization ();
1526 
1530  void TestObjectAttribute ();
1531 
1535  void TestSetAttributeUsingStringValue ();
1536 
1537  // Inherited function
1538  virtual void DoRun ();
1539 };
1540 
1541 TypeId
1543 {
1544  static TypeId tid = TypeId ("LengthValueTestCase::TestObject")
1545  .SetParent<Object> ()
1546  .SetGroupName ("Test")
1547  .AddConstructor<TestObject> ()
1548  .AddAttribute ("Length",
1549  "Length value",
1550  LengthValue (),
1551  MakeLengthAccessor (&TestObject::m_length),
1552  MakeLengthChecker ())
1553  ;
1554 
1555  return tid;
1556 }
1557 
1558 void
1560 {
1561  Length l = KiloMeters (2);
1562  LengthValue value (l);
1563 
1564  NS_TEST_ASSERT_MSG_EQ (value.Get (), l, "Length attribute has wrong value");
1565 }
1566 
1567 void
1569 {
1571 
1572  Length l = KiloMeters (2);
1573  LengthValue value (l);
1574 
1575  std::string output = value.SerializeToString (checker);
1576 
1577  NS_TEST_ASSERT_MSG_EQ (output, "2000 m",
1578  "Length attribute serialization has wrong output");
1579 }
1580 
1581 void
1583 {
1585 
1586  Length l = KiloMeters (2);
1587  std::ostringstream stream;
1588  stream << l;
1589 
1590  LengthValue value;
1591  bool result = value.DeserializeFromString (stream.str (), checker);
1592 
1593  NS_TEST_ASSERT_MSG_EQ (result, true,
1594  "Length attribute deserialization failed");
1595  NS_TEST_ASSERT_MSG_EQ (value.Get (), l,
1596  "Length attribute has wrong value after deserialization");
1597 }
1598 
1599 void
1601 {
1602  Length expected (5, Unit::Kilometer);
1603  Ptr<TestObject> obj = CreateObject<TestObject> ();
1604 
1605  obj->SetAttribute ("Length", LengthValue (expected));
1606 
1607  LengthValue val;
1608  obj->GetAttribute ("Length", val);
1609 
1610  NS_TEST_ASSERT_MSG_EQ (val.Get (), expected,
1611  "Length attribute does not have expected value");
1612 }
1613 
1614 void
1616 {
1617  Length expected (5, Unit::Kilometer);
1618  Ptr<TestObject> obj = CreateObject<TestObject> ();
1619 
1620  std::stringstream stream;
1621  stream << expected.As (Unit::Kilometer);
1622 
1623  obj->SetAttribute ("Length", StringValue (stream.str()));
1624 
1625  LengthValue val;
1626  obj->GetAttribute ("Length", val);
1627 
1628  NS_TEST_ASSERT_MSG_EQ (val.Get (), expected,
1629  "Length attribute does not have expected value");
1630 }
1631 
1632 void
1634 {
1635  TestAttributeConstructor ();
1636  TestAttributeSerialization ();
1637  TestAttributeDeserialization ();
1638  TestObjectAttribute ();
1639  TestSetAttributeUsingStringValue ();
1640 }
1641 
1647 {
1648 public:
1652  LengthTestSuite ();
1653 };
1654 
1656  : TestSuite ("length")
1657 {
1658  AddTestCase ( new LengthTestCase (), TestCase::QUICK );
1659  AddTestCase ( new LengthValueTestCase (), TestCase::QUICK );
1660 }
1661 
1666 
LengthTestCase::TestIsNotEqualWithToleranceReturnsFalse
void TestIsNotEqualWithToleranceReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:815
LengthTestCase::TestDivideLengthByScalar
void TestDivideLengthByScalar()
Test arithmetic operations.
Definition: length-test-suite.cc:1249
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
LengthTestCase::TestTryParseReturnsFalse
void TestTryParseReturnsFalse()
Test the TryParse function returns false on bad input.
Definition: length-test-suite.cc:647
LengthTestCase::TestDefaultLengthIsZero
void TestDefaultLengthIsZero()
Test that a default constructed Length object has a value of 0.
Definition: length-test-suite.cc:318
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::MakeLengthAccessor
Ptr< const AttributeAccessor > MakeLengthAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: length.h:617
LengthTestCase::TestLengthSerialization
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.
Definition: length-test-suite.cc:926
LengthTestCase::TestConstructLengthFromUSUnits
void TestConstructLengthFromUSUnits()
Test that a Length object constructed from various US units has the correct value in meters.
Definition: length-test-suite.cc:362
LengthTestCase::TestConstructLengthFromFootString
void TestConstructLengthFromFootString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:524
LengthTestCase::TestOperatorLessThanReturnsTrue
void TestOperatorLessThanReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:1011
ns3::Length::As
Quantity As(Unit unit) const
Create a Quantity in a specific unit from a Length.
Definition: length.cc:388
ns3::Mod
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...
Definition: length.cc:507
LengthTestCase::LengthTestCase
LengthTestCase()
Constructor.
Definition: length-test-suite.cc:73
LengthTestCase::TestSubtractingLengthAndQuantity
void TestSubtractingLengthAndQuantity()
Test arithmetic operations.
Definition: length-test-suite.cc:1185
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LengthValueTestCase::LengthValueTestCase
LengthValueTestCase()
Default Constructor.
Definition: length-test-suite.cc:1483
LengthTestCase::TestOperatorNotEqualsReturnsTrue
void TestOperatorNotEqualsReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:985
LengthTestCase::TestLengthCopyConstructor
void TestLengthCopyConstructor()
Test that the value from one length is copied to another using the copy constructor.
Definition: length-test-suite.cc:387
LengthTestCase::TestOperatorGreaterThanReturnsFalse
void TestOperatorGreaterThanReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:1075
LengthValueTestCase::TestObject::GetTypeId
static TypeId GetTypeId()
Definition: length-test-suite.cc:1542
ns3::MicroMeters
Length MicroMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:802
ns3::Length::Quantity
An immutable class which represents a value in a specific length unit.
Definition: length.h:267
LengthTestCase::TestAddingLengthAndQuantity
void TestAddingLengthAndQuantity()
Test arithmetic operations.
Definition: length-test-suite.cc:1134
LengthTestCase::TestIsNotEqualWithToleranceReturnsTrue
void TestIsNotEqualWithToleranceReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:803
LengthTestCase::TestOperatorGreaterOrEqualReturnsFalse
void TestOperatorGreaterOrEqualReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:1103
LengthTestCase::TestIsEqualReturnsFalse
void TestIsEqualReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:743
LengthTestCase::TestConstructLengthFromString
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.
Definition: length-test-suite.cc:411
LengthTestCase::TestTryParseReturnsTrue
void TestTryParseReturnsTrue()
Test the TryParse function returns true on success.
Definition: length-test-suite.cc:658
ns3::MakeLengthChecker
Ptr< const AttributeChecker > MakeLengthChecker(void)
Definition: length.cc:236
LengthTestCase::TestSubtractingQuantityAndLength
void TestSubtractingQuantityAndLength()
Test arithmetic operations.
Definition: length-test-suite.cc:1201
LengthTestCase::AssertTrue
void AssertTrue(bool condition, std::string msg)
Helper function to compare results with true.
Definition: length-test-suite.cc:100
LengthTestCase::TestCopyAssignment
void TestCopyAssignment()
Test that a length object can be updated by assignment from another length object.
Definition: length-test-suite.cc:691
ns3::Yards
Length Yards(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:850
LengthTestCase::TestConstructLengthFromMilliMeterString
void TestConstructLengthFromMilliMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:469
LengthTestCase::TestIsEqualWithToleranceReturnsTrue
void TestIsEqualWithToleranceReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:753
ns3::LengthValue::DeserializeFromString
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: length.cc:236
LengthTestCase::TestIsEqualWithToleranceReturnsFalse
void TestIsEqualWithToleranceReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:766
LengthValueTestCase::TestObjectAttribute
void TestObjectAttribute()
Test that a LengthValue works as an attribute.
Definition: length-test-suite.cc:1600
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
LengthTestCase::TestBuilderFreeFunctions
void TestBuilderFreeFunctions()
Test constructing length objects using the builder free functions.
Definition: length-test-suite.cc:614
ns3::Miles
Length Miles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:856
LengthTestCase::TestIsEqualReturnsTrue
void TestIsEqualReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:733
LengthTestCase::TestIsGreaterReturnsTrue
void TestIsGreaterReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:863
ns3::Length::TryParse
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.
Definition: length.cc:239
LengthTestCase::TestIsLessReturnsTrue
void TestIsLessReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:827
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::Length::Unit
Unit
Units of length in various measurement systems that are supported by the Length class.
Definition: length.h:246
LengthTestCase::TestAddingTwoLengths
void TestAddingTwoLengths()
Test arithmetic operations.
Definition: length-test-suite.cc:1115
ns3::Inches
Length Inches(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:838
LengthValueTestCase::TestSetAttributeUsingStringValue
void TestSetAttributeUsingStringValue()
Test that a StringValue is converted to LengthValue.
Definition: length-test-suite.cc:1615
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
LengthValueTestCase::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition: length-test-suite.cc:1633
ns3::Length::GetDouble
double GetDouble() const
Current length value.
Definition: length.cc:382
ns3::NanoMeters
Length NanoMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:796
LengthValueTestCase::~LengthValueTestCase
virtual ~LengthValueTestCase()
Destructor.
Definition: length-test-suite.cc:1490
LengthTestCase::TestConstructLengthFromQuantity
void TestConstructLengthFromQuantity()
Test that a Length object can be constructed from a Quantity object.
Definition: length-test-suite.cc:326
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
LengthTestCase::TestDivReturnsCorrectRemainder
void TestDivReturnsCorrectRemainder()
Test Div function.
Definition: length-test-suite.cc:1336
ns3::Length
Represents a length in meters.
Definition: length.h:239
ns3::Length::Quantity::Value
double Value() const
The value of the quantity.
Definition: length.h:310
LengthTestCase::TestMultiplyLengthByScalar
void TestMultiplyLengthByScalar()
Test arithmetic operations.
Definition: length-test-suite.cc:1217
NS_TEST_ASSERT_MSG_EQ_TOL
#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...
Definition: test.h:378
ns3::Feet
Length Feet(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:844
ns3::Length::IsNotEqual
bool IsNotEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is not equal in value to this instance.
Definition: length.cc:334
LengthTestCase::TestIsLessWithToleranceReturnsFalse
void TestIsLessWithToleranceReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:851
LengthValueTestCase::TestObject::~TestObject
virtual ~TestObject()
Definition: length-test-suite.cc:1504
LengthTestCase::TestMultiplyScalarByLength
void TestMultiplyScalarByLength()
Test arithmetic operations.
Definition: length-test-suite.cc:1233
LengthTestCase::TestConstructLengthFromKiloMeterString
void TestConstructLengthFromKiloMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:493
ns3::LengthValue::SerializeToString
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: length.cc:236
LengthValueTestCase::TestObject
Definition: length-test-suite.cc:1496
ns3::NauticalMiles
Length NauticalMiles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:832
LengthTestCase::TestOperatorGreaterOrEqualReturnsTrue
void TestOperatorGreaterOrEqualReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:1087
LengthTestCase::TestMoveAssignment
void TestMoveAssignment()
Test that a length object can be updated by assignment from a moved length object.
Definition: length-test-suite.cc:705
LengthTestCase::TestConstructLengthFromMileString
void TestConstructLengthFromMileString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:546
LengthTestCase::TestOperatorNotEqualsReturnsFalse
void TestOperatorNotEqualsReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:998
LengthValueTestCase
Test case for LengthValue attribute.
Definition: length-test-suite.cc:1478
LengthTestCase::TestDivReturnsZeroRemainder
void TestDivReturnsZeroRemainder()
Test Div function.
Definition: length-test-suite.cc:1316
ns3::Length::IsLess
bool IsLess(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is greater in value than this instance.
Definition: length.cc:342
LengthTestCase::TestConstructLengthFromInchString
void TestConstructLengthFromInchString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:513
ns3::LengthValue
Define LengthValue class to support using Length objects as attributes.
Definition: length.h:617
LengthTestSuite::LengthTestSuite
LengthTestSuite()
Default Constructor.
Definition: length-test-suite.cc:1655
LengthTestCase::TestConstructLengthFromMicroMeterString
void TestConstructLengthFromMicroMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:457
ns3::KiloMeters
Length KiloMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:826
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
LengthTestCase::TestModReturnsZero
void TestModReturnsZero()
Test Mod function.
Definition: length-test-suite.cc:1356
LengthTestCase::TestQuantityAssignment
void TestQuantityAssignment()
Test that a length object can be updated by assignment from a quantity.
Definition: length-test-suite.cc:719
LengthValueTestCase::TestAttributeDeserialization
void TestAttributeDeserialization()
Test that a LengthValue can be deserialized from a string.
Definition: length-test-suite.cc:1582
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::LengthValue::Get
Length Get(void) const
Definition: length.cc:236
LengthTestCase
Implements tests for the Length class.
Definition: length-test-suite.cc:68
LengthTestCase::TestDivideLengthByLengthReturnsNaN
void TestDivideLengthByLengthReturnsNaN()
Test arithmetic operations.
Definition: length-test-suite.cc:1286
LengthTestCase::TestIsGreaterReturnsFalse
void TestIsGreaterReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:873
NS_TEST_ASSERT_MSG_EQ
#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.
Definition: test.h:166
ns3::Meters
Length Meters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:820
LengthTestCase::TestDivideLengthByLength
void TestDivideLengthByLength()
Test arithmetic operations.
Definition: length-test-suite.cc:1265
LengthTestCase::AssertFalse
void AssertFalse(bool condition, std::string msg)
Helper function to compare results with false.
Definition: length-test-suite.cc:89
LengthTestCase::TestConstructLengthFromNanoMeterString
void TestConstructLengthFromNanoMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:446
LengthTestCase::TestSubtractingTwoLengths
void TestSubtractingTwoLengths()
Test arithmetic operations.
Definition: length-test-suite.cc:1166
ns3::Length::IsEqual
bool IsEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is equal in value to this instance.
Definition: length.cc:319
LengthTestSuite
The Test Suite that runs the test case.
Definition: length-test-suite.cc:1647
LengthTestCase::TestSerializeLengthWithUnit
void TestSerializeLengthWithUnit()
Test serializing a length object to all of the supported unit types.
Definition: length-test-suite.cc:943
ns3::MilliMeters
Length MilliMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:808
LengthValueTestCase::TestAttributeSerialization
void TestAttributeSerialization()
Test that a LengthValue can be serialized to a string.
Definition: length-test-suite.cc:1568
LengthTestCase::TestConstructLengthFromCentiMeterString
void TestConstructLengthFromCentiMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:481
LengthTestCase::TestOperatorEqualsReturnsTrue
void TestOperatorEqualsReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:961
LengthTestCase::TestLengthMoveConstructor
void TestLengthMoveConstructor()
Test that the value from one length is copied to another using the move constructor.
Definition: length-test-suite.cc:399
ns3::CentiMeters
Length CentiMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:814
LengthTestCase::TestAddingQuantityAndLength
void TestAddingQuantityAndLength()
Test arithmetic operations.
Definition: length-test-suite.cc:1150
LengthValueTestCase::TestAttributeConstructor
void TestAttributeConstructor()
Test that a LengthValue can be constructed from a Length instance.
Definition: length-test-suite.cc:1559
LengthTestCase::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition: length-test-suite.cc:1381
LengthTestCase::TestIsNotEqualReturnsFalse
void TestIsNotEqualReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:791
LengthTestCase::TestOperatorEqualsReturnsFalse
void TestOperatorEqualsReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:973
ns3::Div
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...
Definition: length.cc:488
LengthTestCase::TestOperatorLessOrEqualReturnsTrue
void TestOperatorLessOrEqualReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:1035
LengthTestCase::TestConstructLengthFromYardString
void TestConstructLengthFromYardString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:535
LengthTestCase::TestIsNotEqualReturnsTrue
void TestIsNotEqualReturnsTrue()
Test member comparison operators.
Definition: length-test-suite.cc:779
ns3::Length::IsGreater
bool IsGreater(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is less in value than this instance.
Definition: length.cc:358
LengthTestCase::TestIsLessReturnsFalse
void TestIsLessReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:839
LengthValueTestCase::TestObject::m_length
Length m_length
Definition: length-test-suite.cc:1508
LengthTestCase::TestModReturnsNonZero
void TestModReturnsNonZero()
Test Mod function.
Definition: length-test-suite.cc:1368
LengthTestCase::TestOperatorGreaterThanReturnsTrue
void TestOperatorGreaterThanReturnsTrue()
Test free function comparison operators.
Definition: length-test-suite.cc:1063
LengthTestCase::TestInputStreamOperator
void TestInputStreamOperator()
Test reading length object from a stream produces the expected length value.
Definition: length-test-suite.cc:908
LengthTestCase::TestDivReturnsCorrectResult
void TestDivReturnsCorrectResult()
Test Div function.
Definition: length-test-suite.cc:1300
LengthTestCase::TestOutputStreamOperator
void TestOutputStreamOperator()
Test writing length object to a stream produces the expected output.
Definition: length-test-suite.cc:895
LengthTestCase::TestConstructLengthFromMeterString
void TestConstructLengthFromMeterString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:437
gLengthTestSuite
static LengthTestSuite gLengthTestSuite
LengthTestSuite instance.
Definition: length-test-suite.cc:1665
LengthTestCase::TestConstructLengthFromNauticalMileString
void TestConstructLengthFromNauticalMileString()
Test that a length object can be constructed from a string.
Definition: length-test-suite.cc:504
LengthTestCase::TestOperatorLessThanReturnsFalse
void TestOperatorLessThanReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:1023
LengthValueTestCase::TestObject::TestObject
TestObject()
Definition: length-test-suite.cc:1500
LengthTestCase::TestIsGreaterWithToleranceReturnsFalse
void TestIsGreaterWithToleranceReturnsFalse()
Test member comparison operators.
Definition: length-test-suite.cc:883
LengthTestCase::~LengthTestCase
virtual ~LengthTestCase()=default
Destructor.
LengthTestCase::TestOperatorLessOrEqualReturnsFalse
void TestOperatorLessOrEqualReturnsFalse()
Test free function comparison operators.
Definition: length-test-suite.cc:1051
LengthTestCase::TestConstructLengthFromSIUnits
void TestConstructLengthFromSIUnits()
Test that a Length object constructed from various SI units has the correct value in meters.
Definition: length-test-suite.cc:337