|
|
|
@ -2,6 +2,9 @@
|
|
|
|
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
#include "histogram_internal.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
|
|
|
|
|
TEST_CASE("distinct positive numbers") {
|
|
|
|
|
double min = 0;
|
|
|
|
@ -10,12 +13,45 @@ TEST_CASE("distinct positive numbers") {
|
|
|
|
|
CHECK(min == 1);
|
|
|
|
|
CHECK(max == 2);
|
|
|
|
|
}
|
|
|
|
|
TEST_CASE("empty vector"){
|
|
|
|
|
double min = 0;
|
|
|
|
|
double max = 0;
|
|
|
|
|
std::vector<double> numbers;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
CHECK(min == 0);
|
|
|
|
|
CHECK(max == 0);
|
|
|
|
|
TEST_CASE("show histogram vertical") {
|
|
|
|
|
SUBCASE("single bin") {
|
|
|
|
|
std::vector<std::size_t> bins = {5};
|
|
|
|
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("multiple bins") {
|
|
|
|
|
std::vector<std::size_t> bins = {3, 7, 2, 9, 5};
|
|
|
|
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("maxbin <= 76") {
|
|
|
|
|
std::vector<std::size_t> bins = {50, 30, 20, 10, 5};
|
|
|
|
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("maxbin > 76") {
|
|
|
|
|
std::vector<std::size_t> bins = {100, 200, 300, 400, 500};
|
|
|
|
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("make histogram") {
|
|
|
|
|
SUBCASE("single bin") {
|
|
|
|
|
std::vector<double> numbers = {1, 2, 3, 4, 5};
|
|
|
|
|
std::vector<std::size_t> res = {5};
|
|
|
|
|
CHECK(make_histogram(numbers, 1) == res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("multiple bins") {
|
|
|
|
|
std::vector<double> numbers = {1, 2, 3, 4, 5};
|
|
|
|
|
std::vector<std::size_t> res = {2, 1, 2};
|
|
|
|
|
CHECK(make_histogram(numbers, 3) == res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("min and max are the same") {
|
|
|
|
|
std::vector<double> numbers = {1, 1, 1, 1, 1};
|
|
|
|
|
std::vector<std::size_t> res = {5};
|
|
|
|
|
CHECK(make_histogram(numbers, 1) == res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|