[CONSTRUCTOR]
Friendly(
bool a_enable
= true)
Class: fcf::NTest::Friendly
Package: fcfTest
File:
test.hpp
Available from version: 1.2.5
Initializes a new Friendly object to control numeric stream formatting.
The Friendly constructor initializes the fcf::NTest::Friendly structure with a specific state.
This state is used as a flag when passed to an output stream via the std::ostream operator <<. It determines whether numeric values (like durations) should be printed in a human-readable format (using backticks as separators) or in a standard high-precision format.
Arguments
bool a_enable = true
- If true, the stream will use a human-readable format. If false, the stream will use the standard high-precision format.
Example: Toggling Human-Readable Output
Demonstrates how to use the Friendly constructor to switch between human-readable and raw numeric formats in a stream.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("Formatting", "Utility", "FriendlyConstructorTest"){
// Create a duration object with a specific value
fcf::NTest::TimeDuration duration(1234567890);
// 1. Use the default constructor (which is equivalent to Friendly(true))
// This will output in human-readable format: 1.234`567`890
fcf::NTest::log() << "Default (Friendly): " << duration << std::endl;
// 2. Explicitly use the constructor with true to enable friendly mode
fcf::NTest::Friendly friendlyTrue(true);
fcf::NTest::log() << "Explicit Friendly: " << friendlyTrue << duration << std::endl;
// 3. Use the constructor with false to disable friendly mode
// This will output in raw format: 1.234567890
fcf::NTest::Friendly friendlyFalse(false);
fcf::NTest::log() << "Raw Format: " << friendlyFalse << 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" -> "FriendlyConstructorTest" ...
> Default (Friendly): 1.234`567`890
> Explicit Friendly: 1.234`567`890
> Raw Format: 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