From 0b23e2dfc876ac68011d51f53ed0fa268cbb53fb Mon Sep 17 00:00:00 2001 From: Artyom Date: Sat, 18 May 2024 16:08:32 +0300 Subject: [PATCH] =?UTF-8?q?Build:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BC=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_internal.h | 5 +++++ unittest.cbp | 44 ++++++++++++++++++++++++++++++++++++++++ unittest.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 histogram_internal.h create mode 100644 unittest.cbp create mode 100644 unittest.cpp diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..bbe5577 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,5 @@ +#pragma once +#include + +void +find_minmax(const std::vector& numbers, double& min, double& max, bool& res); diff --git a/unittest.cbp b/unittest.cbp new file mode 100644 index 0000000..bffa065 --- /dev/null +++ b/unittest.cbp @@ -0,0 +1,44 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..6f2588a --- /dev/null +++ b/unittest.cpp @@ -0,0 +1,48 @@ +#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; + bool res = true; + find_minmax({1, 2}, min, max ,res); + CHECK(res == true); + CHECK(min == 1); + CHECK(max == 2); +} +TEST_CASE("only one number") { + double min = 0; + double max = 0; + bool res = true; + find_minmax({1}, min, max, res); + CHECK(res == true); + CHECK(min == 1); + CHECK(max == 1); +} +TEST_CASE("distinct negative elements") { + double min = 0; + double max = 0; + bool res = true; + find_minmax({-1, -5}, min, max, res); + CHECK(res == true); + CHECK(min == -5); + CHECK(max == -1); +} +TEST_CASE("equal numbers") { + double min = 0; + double max = 0; + bool res = true; + find_minmax({4, 4, 4}, min, max, res); + CHECK(res == true); + CHECK(min == 4); + CHECK(max == 4); +} +TEST_CASE("no elements in vector") { + double min = 0; + double max = 0; + bool res = true; + find_minmax({}, min, max, res); + CHECK(res == false); +}