From 4351ee1abe62284ea10aeebd22751fe3f6ff790c Mon Sep 17 00:00:00 2001 From: MrDarkLast Date: Mon, 10 Apr 2023 16:26:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 18 ++++++++++++++---- histogram_internal.h | 2 +- unittest.cpp | 19 +++++++++++++++++++ unittest.vcxproj | 41 ++++++++++++++++++++-------------------- unittest.vcxproj.filters | 13 +++++++++++++ 5 files changed, 68 insertions(+), 25 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 4af7bee..a166b3c 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,7 +1,8 @@ #include -#include "histogram.h" +#include "histogram_internal.h" using namespace std; +/* vector make_histogram(const vector& numbers, size_t bin_count) { vector bins(bin_count); @@ -42,9 +43,18 @@ vector make_histogram(const vector& numbers, size_t bin_count) { } } return bins; -} +} */ + +bool find_minmax(const vector& numbers, double& min, double& max) { + if (numbers.size() == 0) { + return false; + } + for (auto i = 0; i < numbers.size(); i++) { + if ( + numbers[i] < 0 + ) return false; + } -void find_minmax(const vector& numbers, double& min, double& max) { min = numbers[0]; for (auto i = 0; i < numbers.size(); i++) { if (numbers[i] < min) { @@ -58,5 +68,5 @@ void find_minmax(const vector& numbers, double& min, double& max) { max = numbers[i]; } } - + return true; } \ No newline at end of file diff --git a/histogram_internal.h b/histogram_internal.h index f4cc286..5bb2d62 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,4 +1,4 @@ #pragma once #include -void find_minmax(const std::vector& numbers, double& min, double& max); \ No newline at end of file +bool find_minmax(const std::vector& numbers, double& min, double& max); \ No newline at end of file diff --git a/unittest.cpp b/unittest.cpp index e69de29..3b3f030 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,19 @@ +#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#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); + + find_minmax({ 1 }, min, max); + CHECK(min == max); + CHECK(find_minmax({ -1 }, min, max) == false); + find_minmax({ 2, 2, 2, 2 }, min, max); + CHECK(min == max); + +} diff --git a/unittest.vcxproj b/unittest.vcxproj index f72affe..7da7e01 100644 --- a/unittest.vcxproj +++ b/unittest.vcxproj @@ -17,7 +17,6 @@ Release x64 - 16.0 @@ -53,27 +52,24 @@ true Unicode - - + + + + + + + + + + + + + - - - - - - - - - - - - - - Level3 @@ -130,9 +126,14 @@ true - - + + + + + + + - + \ No newline at end of file diff --git a/unittest.vcxproj.filters b/unittest.vcxproj.filters index 153170c..7e13cc7 100644 --- a/unittest.vcxproj.filters +++ b/unittest.vcxproj.filters @@ -14,4 +14,17 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + \ No newline at end of file