From d8a083e5541faed7578906c9cca4f1d73526f4a8 Mon Sep 17 00:00:00 2001 From: LykovaYA Date: Fri, 22 Nov 2024 13:42:04 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=8E=D0=BD=D0=B8=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unittest.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 unittest.cpp diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..4ff35e2 --- /dev/null +++ b/unittest.cpp @@ -0,0 +1,49 @@ +#define DOCTEST_CINFIG_NO_MULTITHREADING +#define DOCTEST_CINFIG_IMOLEMENT_WITH_MAIN +#include "doctest.h" +#include "histogram_internal.h" +#include "svg.h" +#include +#include + +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("check if vector is only one in length") { + double min = 3; + double max = 3; + find_minmax({ 3 }, min, max); + CHECK(min == 3); + CHECK(max == 3); +} +TEST_CASE("all numbers are the same") { + double min = 1; + double max = 1; + find_minmax({ 1, 1, 1, 1, 1, 1, 1, }, min, max); + CHECK(min == 1); + CHECK(max == 1); +} +TEST_CASE("all numbers are the same") { + double min = 0; + double max = 0; + CHECK(!find_minmax({}, min, max)); +} + +TEST_CASE("histogram for 10 variant is correct") { + std::fstream in, compare; + std::string line, compline; + bool flag = 0; + in.open("result.txt"); + compare.open("compare.txt"); + while (std::getline(in, line) && std::getline(compare, compline) && !flag) { + if (line != compline) { + flag = 1; + } + } + CHECK(flag == 0); +} \ No newline at end of file