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); +}