Type:
class fcf::NTest::Friendly
Package: fcfTest
File:
test.hpp
( link_to_the_text_position_in_the_file )
Available from version: 1.2.5
A helper structure used to control the formatting of numeric output in streams, specifically for enabling human-readable time durations.
The fcf::NTest::Friendly structure is a lightweight utility designed to interact with std::ostream via operator overloading. Its primary purpose within the fcfTest framework is to act as a flag that toggles the visual representation of numeric values (such as fcf::NTest::TimeDuration) between a raw, high-precision format and a 'friendly', human-readable format (using separators like backticks).
Properties
- Flag that controls whether numeric values are displayed in a human-readable format.
Methods
[CONSTRUCTOR]
Friendly(
bool a_enable
= true)
- Initializes a new Friendly object to control numeric stream formatting.
Example: Controlling Numeric Formatting
Demonstrates how to use the Friendly structure to switch between raw nanosecond precision and a human-readable format in an output stream.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("Formatting", "Utility", "FriendlyTest"){
// Create a duration object
fcf::NTest::TimeDuration duration(1234567890);
// 1. Default output (raw format)
fcf::NTest::log() << "Raw duration: " << duration << std::endl;
// 2. Use Friendly structure to switch to human-readable format
// The operator<< overload sets a flag in the stream's iword
fcf::NTest::log() << fcf::NTest::Friendly(true) << duration << std::endl;
// 3. Switch back to raw format
fcf::NTest::log() << fcf::NTest::Friendly(false) << duration << 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: "Formatting" -> "Utility" -> "FriendlyTest" ...
> Raw duration: 1.234567890
> Raw duration: 1.234`567`890
> Raw duration: 1.234567890
[SUCCESS] Test completed successfully (0.000`001`234 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`001`234 sec