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

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

TItem median() const

Class: fcf::NTest::HistogramBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Calculates the estimated median value of the distribution.

The median method calculates the median of the data points currently stored in the histogram. Since the histogram uses bins, the median is an estimated value based on the distribution across those bins.

Result
TItem
- The estimated median value.

Example: Calculating Median

Finding the median of a simple distribution.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("HistogramDemo", "Stats", "MedianTest") { fcf::NTest::HistogramBasic<int> hist(10, 0, 100); // Add values: 10, 20, 30, 40, 50 hist.append(10); hist.append(20); hist.append(30); hist.append(40); hist.append(50); int med = hist.median(); fcf::NTest::log() << "Median: " << med << std::endl; FCF_TEST(med == 30); } 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" -> "Stats" -> "MedianTest" ... > Median: 30 [SUCCESS] Test completed successfully (0.000`019`005 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`019`005 sec