From 8d848025e379f2884fd7631835171e9f08dc8081 Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 24 Apr 2023 15:50:09 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0=20=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B9=20=D0=B2=D0=B5=D0=BA=D1=82=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/histogram.cpp | 25 ++++++++++++++++--------- unittest.cpp | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/project/histogram.cpp b/project/histogram.cpp index 8913643..8432327 100644 --- a/project/histogram.cpp +++ b/project/histogram.cpp @@ -6,17 +6,24 @@ using namespace std; void find_minmax(vector numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) + if (numbers.empty()) { - if (x < min) - { - min = x; - } - else if (x > max) + min = max = 0; + } + else + { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { - max = x; + if (x < min) + { + min = x; + } + else if (x > max) + { + max = x; + } } } return; diff --git a/unittest.cpp b/unittest.cpp index 9646fb8..09b46e0 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -34,7 +34,8 @@ TEST_CASE("vector with same elements") { TEST_CASE("void vector") { double min = 0; double max = 0; - find_minmax({0}, min, max); + std::vector numbers {}; + find_minmax( numbers, min, max); CHECK(min == 0); CHECK(max == 0); }