FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

size() method from fcf::NTest::HistogramBasic class

size_t size() const
void size(size_t a_newSize)

Class: fcf::NTest::HistogramBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Returns the number of bins (size of the internal vector) or resizes the histogram.

The size method has two distinct behaviors depending on whether it is used for reading or writing:

  • Read Mode: When called without arguments, it returns the current number of bins in the histogram.
  • Write Mode: When called with a size_t argument, it resizes the histogram to the specified number of bins, rebuilding the internal data distribution.

Arguments

size_t a_newSize
- The desired new number of bins. Must be greater than 1.
Result
size_t
- The current number of bins.

Example: Checking and Resizing Histogram

Demonstrating how to get the current size and then resize the histogram.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("HistogramDemo", "SizeTest", "Resize") { fcf::NTest::HistogramBasic<int> hist(10); // 1. Get current size size_t currentSize = hist.size(); fcf::NTest::log() << "Current size: " << currentSize << std::endl; // 2. Resize the histogram hist.size(50); fcf::NTest::log() << "New size: " << hist.size() << std::endl; FCF_TEST(currentSize == 10 && hist.size() == 50); } 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: "HistogramDemo" -> "SizeTest" -> "Resize" ... > Current size: 10 > New size: 50 [SUCCESS] Test completed successfully (0.000`027`863 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`027`863 sec