void
rangeByIndex(
size_t a_index,
TItem a_min,
size_t a_size)
const
void
rangeByIndex(
size_t a_index,
TItem a_min,
TItem a_max)
const
[STATIC] std::pair<
TItem,
TItem>
rangeByIndex(
size_t a_index,
TItem a_min,
TItem a_max,
size_t a_size)
Class: fcf::NTest::HistogramBasic
Package: fcfTest
File:
test.hpp
Available from version: 1.2.5
Calculates the lower and upper boundaries of a specific bin index.
The rangeByIndex method provides the mathematical boundaries for a specific bin index within the histogram.
This is useful when you are iterating through the histogram bins (e.g., for drawing a bar chart or generating a table) and need to know the actual value range that each bin represents.
Arguments
size_t a_index
- The zero-based index of the bin.
Result
std::pair<TItem, TItem>
- A pair where the first element is the lower bound and the second element is the upper bound of the bin index.
Thrown exceptions
std::out_of_range
- Thrown if the provided index is greater than or equal to the current number of bins.
Example: Iterating Through Bins
Using bin indices to determine the value ranges for all bins in the histogram.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("HistogramDemo", "Basic", "IndexRangeCheck") {
// Create a histogram with 5 bins in range [0, 50]
fcf::NTest::HistogramBasic<int> hist(5, 0, 50);
// 1. Get range for the 3rd bin (index 2)
std::pair<int, int> range = hist.rangeByIndex(2);
fcf::NTest::log() << "Bin 2 range: [" << range.first << " : " << range.second << "]" << std::endl;
// 2. Verify the range for index 2 in a 5-bin [0, 50] setup (should be [20, 29])
FCF_TEST(range.first == 20 && range.second == 29);
}
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" -> "IndexRangeCheck" ...
> Bin 2 range: [20 : 29]
[SUCCESS] Test completed successfully (0.000`010`382 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`010`382 sec
The rangeByIndex method is essential for generating visual representations like tables or charts.