void
rangeByValue(
TItem a_value,
TItem a_min,
size_t a_size)
const
void
rangeByValue(
TItem a_value,
TItem a_min,
TItem a_max)
const
[STATIC] std::pair<
TItem,
TItem>
rangeByValue(
TItem a_value,
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 the bin containing the specified value.
The rangeByValue method allows you to determine exactly which interval (bin) a specific value belongs to within the current histogram structure.
This is essential when you need to map a raw data point back to its corresponding histogram bin for detailed analysis or visualization.
Arguments
TItem a_value
- The value to locate within the range.
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.
Thrown exceptions
std::out_of_range
- Thrown if the provided value is outside the specified [min, max] range.
Example: Finding Bin Boundaries
Calculating the range of a bin for a given value using the histogram's current state.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("HistogramDemo", "Basic", "RangeCheck") {
// Create a histogram with range [0, 100] and 10 bins
fcf::NTest::HistogramBasic<double> hist(10, 0.0, 100.0);
// 1. Find range for value 25.0 using current histogram state
std::pair<double, double> range = hist.rangeByValue(25.0);
fcf::NTest::log() << "Value 25.0 is in bin: [" << range.first << " : " << range.second << "]" << std::endl;
// 2. Verify the math (for 10 bins in 0-100, 25.0 should be in [20.0, 29.0] or similar depending on implementation)
FCF_TEST(range.first <= 25.0 && range.second >= 25.0);
}
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" -> "RangeCheck" ...
> Value 25.0 is in bin: [20 : 29]
[SUCCESS] Test completed successfully (0.000`023`531 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`023`531 sec
The rangeByValue method is essential for mapping raw data back to its statistical bin.