median() method from fcf::NTest::HistogramBasic class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.5
Calculates the estimated median value of the distribution.
The
Result
- 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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.