From 5f9120a4128fe1e97fc68fab2aef51769e8df62c Mon Sep 17 00:00:00 2001 From: Danila Date: Sun, 23 Apr 2023 23:56:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=8F=D1=82=D1=8B=D0=B9=20=D1=8D=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD,=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=88=D0=B5=D0=BB=20=D0=B4=D0=BE6=D0=B3=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/.gitignore | 2 ++ project/histogram_internal.h | 8 +++---- unittest.cpp | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/project/.gitignore b/project/.gitignore index fba4e61..c20a886 100644 --- a/project/.gitignore +++ b/project/.gitignore @@ -1,2 +1,4 @@ /obj /bin +/pr3.depend +/pr3.layout diff --git a/project/histogram_internal.h b/project/histogram_internal.h index da65b3c..3b5a81b 100644 --- a/project/histogram_internal.h +++ b/project/histogram_internal.h @@ -1,7 +1,7 @@ -#ifndef FINDMINMAX_H_INCLUDED -#define FINDMINMAX_H_INCLUDED +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED #include -void find_minmax(vector numbers, double& min, double& max); +void find_minmax(std::vector numbers, double& min, double& max); -#endif // FINDMINMAX_H_INCLUDED +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/unittest.cpp b/unittest.cpp index e69de29..907123c 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,41 @@ +#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.h" +#include "project/histogram_internal.h" + +TEST_CASE("distinct positive numbers 1") +{ + double min = 0; + double max = 0; + find_minmax({1, 2}, min, max); + CHECK(min == 1); + CHECK(max == 2); +} + +TEST_CASE("distinct positive numbers 2") { + double min = 0; + double max = 0; + std::vectorv{2,1}; + CHECK(v.size() != 0); + CHECK(v.size() != 1); + find_minmax({1, 2}, min, max); + CHECK(min == 1); + CHECK(max == 2); + CHECK(min != max); +} + +TEST_CASE("vector with one element") { + double min = 0; + double max = 0; + find_minmax({1}, min, max); + CHECK(min == 1); + CHECK(max == 1); +} + +TEST_CASE("vector with same elements") { + double min = 0; + double max = 0; + find_minmax({2,2,2}, min, max); + CHECK(min == 2); + CHECK(max == 2); +}