From 391e26d08a11ce8f0f999e3b18c5cefa960035fe Mon Sep 17 00:00:00 2001 From: EfimovaLA Date: Sun, 2 Jun 2024 17:12:41 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20unit=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unittest.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) 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); + } }