operator+() method from fcf::NTest::TimeDuration class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.5
Adds a duration or an arithmetic value to the current duration.
The
This operator is overloaded to support two types of addition:
- Adding another
fcf::NTest::TimeDuration object. - Adding an arithmetic type (e.g.,
int,double,unsigned long long) which is treated as nanoseconds.
Arguments
- The duration to add.
Result
- A new TimeDuration object representing the sum.
Example: Arithmetic addition
Demonstrating addition with both TimeDuration and raw numeric types.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE ("TimeDemo", "Basics", "Addition") {
fcf::NTest::TimeDuration d1(1000000000ULL); // 1s
fcf::NTest::TimeDuration d2(500000000ULL); // 0.5s
// 1. Add TimeDuration
fcf::NTest::TimeDuration res1 = d1 + d2;
// 2. Add arithmetic type (nanoseconds)
fcf::NTest::TimeDuration res2 = d1 + 250000000ULL;
FCF_TEST (res1.count() == 1500000000ULL, res1.count());
FCF_TEST (res2.count() == 1250000000ULL, res2.count());
std::cout << "Res1: " << res1.str(true) << std::endl;
std::cout << "Res2: " << res2.str(true) << std::endl;
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun (a_argc, a_argv, fcf::NTest::CRM_RUN , &error);
return error ? 1 : 0;
}
Output:
Performing the test: "TimeDemo" -> "Basics" -> "Addition" ...
Res1: 1.500`000`000
Res2: 1.250`000`000
[SUCCESS] Test completed successfully (0.000`000`000 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`000`000 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.