From 38a8c90e0dc915140eb067f1deac243988b9b256 Mon Sep 17 00:00:00 2001 From: MamakinYR Date: Sun, 21 Apr 2024 23:04:40 +0300 Subject: [PATCH] =?UTF-8?q?testing:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 21 ++++++++++++--------- unittest.cpp | 27 +++++++++++++++++++++++++++ unittest.vcxproj | 42 ++++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 9eec184..eb2de5e 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -5,17 +5,20 @@ using namespace std; void find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) + if (numbers.size() == 2) { - if (x < min) + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { - min = x; - } - if (x > max) - { - max = x; + if (x < min) + { + min = x; + } + if (x > max) + { + max = x; + } } } } diff --git a/unittest.cpp b/unittest.cpp index e69de29..485d693 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,27 @@ +#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); +} + +TEST_CASE("empty vector") { + double min = 0; + double max = 0; + find_minmax({}, min, max); + CHECK(min == 0); + CHECK(max == 0); +} +TEST_CASE("negative values") { + double min = 0; + double max = 0; + find_minmax({-2, -4}, min, max); + CHECK(min == -4); + CHECK(max == -2); +} \ No newline at end of file diff --git a/unittest.vcxproj b/unittest.vcxproj index aee391f..3e22914 100644 --- a/unittest.vcxproj +++ b/unittest.vcxproj @@ -17,7 +17,6 @@ Release x64 - 17.0 @@ -53,27 +52,24 @@ true Unicode - - + + + + + + + + + + + + + - - - - - - - - - - - - - - Level3 @@ -130,9 +126,15 @@ true - - + + + + + + + + - + \ No newline at end of file