From 2adb5dba8548adca412a25cb42d5fa4e6fb4f5bc Mon Sep 17 00:00:00 2001 From: "Mikhail (NefedovMA)" Date: Sun, 4 May 2025 21:04:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 2 +- histogram_internal.h | 9 +++++++++ unittest.cbp | 38 ++++++++++++++++++++++++++++++++++++++ unittest.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 histogram_internal.h create mode 100644 unittest.cbp create mode 100644 unittest.cpp diff --git a/histogram.cpp b/histogram.cpp index 9deefeb..0b5f9d1 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -3,7 +3,7 @@ #include using namespace std; -static void find_minmax(const vector& numbers, double& minN, double& maxN) +void find_minmax(const vector& numbers, double& minN, double& maxN) { minN = numbers[0]; maxN = numbers[0]; diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..54abeff --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,9 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED + +#include + +std::vector +find_minmax( const std::vector& numbers, double& minN, double& maxN); + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/unittest.cbp b/unittest.cbp new file mode 100644 index 0000000..7f9621b --- /dev/null +++ b/unittest.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..f0883f5 --- /dev/null +++ b/unittest.cpp @@ -0,0 +1,29 @@ +#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("distinct negative numbers") +{ + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); +} +TEST_CASE("vector 1 element") +{ + double min = 0; + double max = 0; + find_minmax({1}, min, max); + CHECK(min == 1); + CHECK(max == 1); +}