From c6251914a510d5e0477507ef5cb51f67c67b91b8 Mon Sep 17 00:00:00 2001 From: KnyazevSK <KnyazevSK@mpei.ru> Date: Mon, 22 May 2023 16:16:37 +0400 Subject: [PATCH] =?UTF-8?q?code:=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=BD=D1=83=D0=BB=D0=B5=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 12 +++++++++--- unittest.cpp | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 52c06d3..e3503d5 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -3,12 +3,18 @@ #include <vector> using namespace std; -void find_minmax( vector<double> numbers, double &min, double &max) +bool find_minmax( vector<double> numbers, double &min, double &max) { + if (numbers.empty()) + { + return false; + } + min = numbers[0]; max = numbers[0]; - for (double x : numbers) + for (double x : numbers) { + max = x; if (x < min) { min = x; @@ -18,7 +24,7 @@ void find_minmax( vector<double> numbers, double &min, double &max) max = x; } } - return; + return true; } vector<size_t> make_histogram (vector<double> numbers, size_t bin_count) diff --git a/unittest.cpp b/unittest.cpp index 62f954d..083153a 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -2,6 +2,7 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" #include "histogram_internal.h" +#include "sr.h" TEST_CASE("distinct positive numbers") { @@ -38,3 +39,11 @@ TEST_CASE("vector with same elements") { CHECK(min == 2); CHECK(max == 2); } +TEST_CASE("Empty vector"){ + double min = 0; + double max = 0; + std::vector<double> numbers {}; + CHECK(find_minmax(numbers, min, max) == false); + +} +