11#include "ns3/int64x64.h"
12#include "ns3/nstime.h"
45 void DoRun()
override;
105 :
TestCase(
"Sanity check of common time operations")
118 constexpr long long oneSec = 1000000000;
124 std::cout <<
"Testing Time Subtraction \n";
129 std::cout <<
"Testing Time Multiplication \n";
135 std::cout <<
"Testing Time Division \n";
140 std::cout <<
"Testing modulo division \n";
155 "is 10 really 10 ?");
162 "is 10 really 10 ?");
170 "is 10 really 10 ?");
173 TimeStep(1).GetSeconds(),
177 TimeStep(1).GetSeconds(),
178 "is 10 really 10 ?");
188 "is 1ns really 1ns ?");
190 "is 1ps really 1ps ?");
192 "is 1fs really 1fs ?");
212 using TestEntry = std::tuple<Time, std::string>;
213 std::array<TestEntry, 2>
TESTS{std::make_tuple(
t *
val,
"Test Time * value: "),
214 std::make_tuple(
val *
t,
"Test Time * value: ")};
236 static_cast<unsigned char>(
scale),
237 "Multiplication by unsigned char");
241 static_cast<unsigned short>(
scale),
242 "Multiplication by unsigned short");
246 static_cast<unsigned int>(
scale),
247 "Multiplication by unsigned int");
251 static_cast<unsigned long>(
scale),
252 "Multiplication by unsigned long");
256 static_cast<unsigned long long>(
scale),
257 "Multiplication by unsigned long long");
306 static_cast<unsigned long long>(
scale),
307 "Division by unsigned long long");
348 void DoRun()
override;
357 :
TestCase(
"Checks times that have plus or minus signs")
378 "Positive time not parsed correctly.");
383 "Positive time with units not parsed correctly.");
388 "Negative time not parsed correctly.");
393 "Negative time with units not parsed correctly.");
417 void DoRun()
override;
422 void Check(
const std::string& str);
433 :
TestCase(
"Input,output from,to strings")
440 std::stringstream
ss(str);
444 bool pass = (str ==
ss.str());
450 std::cout <<
", got " <<
ss.str();
452 std::cout << std::endl;
459 std::stringstream
ss;
460 ss << std::fixed << std::setprecision(6) <<
t.As();
465 std::cout <<
GetParent()->
GetName() <<
" InputOutput:As: " << (
pass ?
"pass " :
"FAIL ") <<
"\""
469 std::cout <<
", got " << str;
471 std::cout << std::endl;
478 std::cout << std::endl;
490 Time t(3.141592654e9);
493 <<
"example: raw: " <<
t << std::endl;
495 std::cout <<
GetParent()->
GetName() <<
" InputOutput: " << std::fixed << std::setprecision(9)
496 <<
"example: in s: " <<
t.As(
Time::S) << std::endl;
498 std::cout <<
GetParent()->
GetName() <<
" InputOutput: " << std::setprecision(6)
499 <<
"example: in ms: " <<
t.As(
Time::MS) << std::endl;
502 <<
"example: Get ns: " <<
t.GetNanoSeconds() << std::endl;
505 <<
"example: auto scale: \n";
time simple test case, Checks the basic operations on time
void DoTeardown() override
Does the tear down for TimeSimpleTestCase.
virtual void DoTimeOperations()
Tests the Time Operations.
void DoSetup() override
setup function for TimeSimpleTestCase.
void TestMultiplicationByDecimalTypes()
Test multiplying a Time instance by various decimal types.
void TestMultiplicationByIntegerTypes()
Test multiplying a Time instance by various integer types.
TimeSimpleTestCase()
constructor for TimeSimpleTestCase.
void DoRun() override
Runs the Simple Time test case.
void TestDivisionByIntegerTypes()
Test dividing a Time instance by various integer types.
void TestDivision(Time t, Time expected, T val, const std::string &msg)
Helper function to handle boilerplate code for division tests.
void TestDivisionByDecimalTypes()
Test dividing a Time instance by various decimal types.
void TestMultiplication(Time t, Time expected, T val, const std::string &msg)
Helper function to handle boilerplate code for multiplication tests.
time-tests Time with Sign test case
void DoTeardown() override
DoTeardown for TimeWithSignTestCase.
void DoSetup() override
DoSetup for TimeWithSignTestCase.
void DoRun() override
DoRun for TimeWithSignTestCase.
TimeWithSignTestCase()
constructor for TimeWithSignTestCase.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase * GetParent() const
Get the parent of this TestCase.
std::string GetName() const
static constexpr auto UNIT
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static void SetResolution(Unit resolution)
High precision numerical type, implementing Q64.64 fixed precision.
TimeTestSuite g_timeTestSuite
Member variable for time test suite.
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
Calculate how many times numerator can be split into denominator sized pieces.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report 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...
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time Days(double value)
Construct a Time in the indicated unit.
Time Hours(double value)
Construct a Time in the indicated unit.
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Minutes(double value)
Construct a Time in the indicated unit.
Time Years(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
-ns3 Test suite for the ns3 wrapper script