toBarChart() method from fcf::NTest::HistogramBasic class
[STATIC] std::string
toBarChart (const std::vector <TCounter >& a_vector, TItem a_min, TItem a_max, size_t a_width, size_t a_height)
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.5
Generates an ASCII bar chart representing the histogram distribution.
The
Arguments
- The minimum boundary for the chart.
- The maximum boundary for the chart.
- The width of the chart in characters.
- The height of the chart in characters.
Result
- A string containing the ASCII bar chart.
Example: Generating an ASCII Bar Chart
Demonstrating how to generate a visual bar chart of the histogram.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE ("HistogramDemo", "Chart", "GenerateChart") {
fcf::NTest::HistogramBasic <int> hist(10, 0, 100);
hist.append (10, 2);
hist.append (20, 5);
hist.append (30, 8);
hist.append (40, 3);
hist.append (50, 1);
// 1. Generate chart with default height (4)
std::string chart = hist.toBarChart (20, 4);
fcf::NTest::log () << chart << 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:
rm-red>/g"
Performing the test: "HistogramDemo" -> "Chart" -> "GenerateChart" ...
> ||
> |||
> |||||
> |||||||||
> ════════════════════
> OX (value): [0 : 100]; Step: 5.00
> OY (count): [0 : 4]; Step: 1.00
>
[SUCCESS] Test completed successfully (0.000`071`342 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`071`342 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.