From afd2464d20bbb70a6d1bf2f278e989442fed69d0 Mon Sep 17 00:00:00 2001 From: "Nikita (PodolskyNK)" Date: Wed, 8 May 2024 10:29:06 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B8=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=81=D0=B2=D0=BE=D1=8E?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 1 + histogram.h | 2 +- histogram_internal.h | 2 +- unittest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 745693c..db976ec 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,3 +1,4 @@ +#include #include "histogram.h" using namespace std; void find_minmax(const vector& numbers, double& min, double& max) diff --git a/histogram.h b/histogram.h index a521200..f9dc097 100644 --- a/histogram.h +++ b/histogram.h @@ -5,6 +5,6 @@ std::vector -make_histogram(const std::vector& numbers, size_t bin_count); +make_histogram(const std::vector& numbers, size_t& bin_count); #endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h index 34592d8..3a2e060 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -4,6 +4,6 @@ #include void -find_minmax(const std::vector& numbers, double& min, double& max) +find_minmax(const std::vector& numbers, double& min, double& max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/unittest.cpp b/unittest.cpp index e69de29..e87aafe 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,39 @@ +#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include +#include "doctest.h" +#include "histogram_internal.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("negative numbers") { + double min = 0; + double max = 0; + find_minmax({ -10, 10 }, min, max); + CHECK(min == -10); + CHECK(max == 10); +} + +TEST_CASE("empty numbers") { + double min = 0; + double max = 0; + find_minmax({ }, min, max); + CHECK(min != 0); + CHECK(max != 0); +} + +TEST_CASE("one number") { + double min = 0; + double max = 0; + find_minmax({ 2 }, min, max); + CHECK(min == 2); + CHECK(max == 2); +} + +