HistogramBasic() method from fcf::NTest::HistogramBasic class
[CONSTRUCTOR]
HistogramBasic ()
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.5
Constructs a new histogram with specified capacity and range.
The
- Default Constructor: Creates an empty histogram with a default capacity of 10 bins.
- Capacity Constructor: Creates a histogram with a specified initial number of bins.
- Range Constructor: Creates a histogram with a fixed range defined by a_min and a_max, and a specified capacity.
Arguments
- The initial number of bins in the histogram.
- The minimum boundary of the histogram range.
- The maximum boundary of the histogram range.
Example: Initializing different types of Histograms
Demonstrating how to create histograms with default settings, specific capacity, and fixed ranges.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE ("HistogramDemo", "Basic", "ConstructorTest") {
// 1. Default constructor (10 bins, auto-range)
fcf::NTest::HistogramBasic <double> hist1 = fcf::NTest::HistogramBasic <double>();
// 2. Constructor with capacity (50 bins, auto-range)
fcf::NTest::HistogramBasic <double> hist2(50);
// Append some data to verify
hist2.append (10.5);
hist2.append (50.0);
hist2.append (99.9);
fcf::NTest::log () << "Hist2 size: " << hist2.size () << std::endl;
fcf::NTest::log () << "Hist2 min: " << hist2.min () << std::endl;
fcf::NTest::log () << "Hist2 max: " << hist2.max () << std::endl;
// 3. Constructor with capacity and fixed range [0.0, 100.0]
fcf::NTest::HistogramBasic <double> hist3(50, 0.0, 100.0);
// Append some data to verify
hist3.append (10.5);
hist3.append (50.0);
hist3.append (99.9);
fcf::NTest::log () << "Hist3 size: " << hist3.size () << std::endl;
fcf::NTest::log () << "Hist3 min: " << hist3.min () << std::endl;
fcf::NTest::log () << "Hist3 max: " << hist3.max () << std::endl;
FCF_TEST (true);
}
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" -> "Basic" -> "ConstructorTest" ...
> Hist2 size: 50
> Hist2 min: 10.5
> Hist2 max: 99.9
> Hist3 size: 50
> Hist3 min: 0
> Hist3 max: 100
[SUCCESS] Test completed successfully (0.000`077`770 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`077`770 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.