#define DOCTEST_CONFIG_NO_MULTITHREADING
#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;
    double max = 0;
    find_minmax({1, 2}, min, max);
    CHECK(min == 1);
    CHECK(max == 2);
}
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);
    }
}