diff --git a/unittest.cpp b/unittest.cpp index 6a316f1..3fd0ebd 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -2,6 +2,9 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" #include "histogram_internal.h" +#include "svg.h" +#include +#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 numbers; - find_minmax(numbers, min, max); - CHECK(min == 0); - CHECK(max == 0); +TEST_CASE("show histogram vertical") { + SUBCASE("single bin") { + std::vector bins = {5}; + CHECK_NOTHROW(show_histogram_svg_vertical(bins)); + } + + SUBCASE("multiple bins") { + std::vector bins = {3, 7, 2, 9, 5}; + CHECK_NOTHROW(show_histogram_svg_vertical(bins)); + } + + SUBCASE("maxbin <= 76") { + std::vector bins = {50, 30, 20, 10, 5}; + CHECK_NOTHROW(show_histogram_svg_vertical(bins)); + } + + SUBCASE("maxbin > 76") { + std::vector bins = {100, 200, 300, 400, 500}; + CHECK_NOTHROW(show_histogram_svg_vertical(bins)); + } +} + +TEST_CASE("make histogram") { + SUBCASE("single bin") { + std::vector numbers = {1, 2, 3, 4, 5}; + std::vector res = {5}; + CHECK(make_histogram(numbers, 1) == res); + } + + SUBCASE("multiple bins") { + std::vector numbers = {1, 2, 3, 4, 5}; + std::vector res = {2, 1, 2}; + CHECK(make_histogram(numbers, 3) == res); + } + + SUBCASE("min and max are the same") { + std::vector numbers = {1, 1, 1, 1, 1}; + std::vector res = {5}; + CHECK(make_histogram(numbers, 1) == res); + } }