From 80f2e0c04a59823a412716c49d935de48a6eef6d Mon Sep 17 00:00:00 2001 From: "Yaroslav (PivovarovYV)" Date: Tue, 6 Jun 2023 17:53:00 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=BE=D1=82=D0=BA=D0=B0=D1=82=20=D0=BA?= =?UTF-8?q?=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=D1=83?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 32 ++++++++++------- histogram_internal.h | 2 +- main.cpp | 1 + project3.depend | 20 ++++++----- project3.layout | 27 ++++++++------ svg.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++-- text.cpp | 1 - unitest.cpp | 49 ++++++++++++++++++++++---- unitest.depend | 12 ++++--- 9 files changed, 181 insertions(+), 46 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 7f0841e..1695f6e 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -4,24 +4,31 @@ #include "histogram.h" #include "histogram_internal.h" #include + using namespace std; -void find_minmax(const vector numbers, double& min, double& max) { - min = numbers[0]; - for (auto i = 0; i < numbers.size(); i++) { - if (numbers[i] < min) { - min = numbers[i]; - } +bool find_minmax(vector numbers, double& min, double& max) { + if (numbers.empty()) + { + return true; } + else + { + min = numbers[0]; + for (auto i = 0; i < numbers.size(); i++) { + if (numbers[i] < min) { + min = numbers[i]; + } + } - max = numbers[0]; - for (auto i = 0; i < numbers.size(); i++) { - if (numbers[i] > max) { - max = numbers[i]; + max = numbers[0]; + for (auto i = 0; i < numbers.size(); i++) { + if (numbers[i] > max) { + max = numbers[i]; + } } } - + return false; } - vector make_histogram(const vector& numbers, size_t bin_count) { vector bins(bin_count); @@ -63,3 +70,4 @@ vector make_histogram(const vector& numbers, size_t bin_count) { } return bins; } + diff --git a/histogram_internal.h b/histogram_internal.h index 18abf25..aee9646 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,6 +1,6 @@ #ifndef HISTOGRAM_INTERNAL_H_INCLUDED #define HISTOGRAM_INTERNAL_H_INCLUDED #include -void find_minmax(std::vector numbers, double& min, double& max); +bool find_minmax(std::vector numbers, double& min, double& max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/main.cpp b/main.cpp index 19c5a82..6c5d263 100644 --- a/main.cpp +++ b/main.cpp @@ -42,3 +42,4 @@ int main() show_histogram_svg(bins); return 0; } + diff --git a/project3.depend b/project3.depend index 8b28acb..2e15fff 100644 --- a/project3.depend +++ b/project3.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1685882979 source:c:\users\hp\desktop\lab-03\project3\main.cpp +1685964158 source:c:\users\hp\desktop\lab-03\project3\main.cpp @@ -9,10 +9,10 @@ -1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h +1685965388 c:\users\hp\desktop\lab-03\project3\histogram.h -1685882979 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp +1685969843 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp @@ -20,7 +20,7 @@ "histogram_internal.h" -1685882979 source:c:\users\hp\desktop\lab-03\project3\text.cpp +1685964158 source:c:\users\hp\desktop\lab-03\project3\text.cpp @@ -30,15 +30,17 @@ 1682273446 c:\users\hp\desktop\lab-03\project3\text.h -1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h +1685969642 c:\users\hp\desktop\lab-03\project3\histogram_internal.h -1685883368 source:c:\users\hp\desktop\lab-03\project3\svg.cpp - - "svg.h" +1685943355 source:c:\users\hp\desktop\lab-03\project3\svg.cpp + + + + "svg.h" -1685882979 c:\users\hp\desktop\lab-03\project3\svg.h +1685964255 c:\users\hp\desktop\lab-03\project3\svg.h diff --git a/project3.layout b/project3.layout index b463bd3..4ab3d9c 100644 --- a/project3.layout +++ b/project3.layout @@ -2,34 +2,39 @@ - + - + - + + + + + + - + - + - + - + - + - + - + - + diff --git a/svg.cpp b/svg.cpp index 0ab956d..727dc33 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,7 +1,9 @@ +/*#include #include -#include "svg.h" -#include +#include +#include #include +#include "svg.h" using namespace std; @@ -61,3 +63,80 @@ void show_histogram_svg(const vector& bins) { } svg_end(); } +*/ +#include +#include +#include +#include +#include +#include "svg.h" +using namespace std; + +void +svg_begin(double width, double height) +{ + cout << "\n"; + cout << "\n"; +} + +void +svg_end() +{ + cout << "\n"; +} + +void +svg_text(double left, double baseline, string text) +{ + cout << "" << text << ""; +} + +void +svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") +{ + cout << ""; + +} + + +void +show_histogram_svg(const vector& bins) +{ + const auto IMAGE_WIDTH = 400; + const auto IMAGE_HEIGHT = 300; + const auto TEXT_LEFT = 20; + const auto TEXT_BASELINE = 20; + const auto TEXT_WIDTH = 50; + const auto BIN_HEIGHT = 30; + const auto BLOCK_WIDTH = 10; + const auto BLACK = "black"; + const auto RED = "red"; + const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH; + + + svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); + + double top = 0; + double max_count = bins[0]; + for (size_t i = 0; i < bins.size(); i++) + { + if (max_count bins, size_t bin_count ) { cout << "\n"; } } - diff --git a/unitest.cpp b/unitest.cpp index 28c1f8d..6f750e5 100644 --- a/unitest.cpp +++ b/unitest.cpp @@ -3,14 +3,51 @@ #include "doctest.h" #include "histogram_internal.h" #include -TEST_CASE("distinct positive numbers") { +#include +#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("vector with one element") +{ double min = 0; double max = 0; - std::vectormas{1,2}; - CHECK(mas.size() != 0); - CHECK(mas.size() != 1); - find_minmax(mas, min, max); + 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); - CHECK(min != max); +} + +TEST_CASE("void vector") +{ + double min = 3; + double max = 2; + std::vector numbers {}; + bool check = find_minmax(numbers, min, max); + CHECK(check == true); +} +TEST_CASE("distinct negative numbers") { + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); } diff --git a/unitest.depend b/unitest.depend index 3246a93..5865a80 100644 --- a/unitest.depend +++ b/unitest.depend @@ -1,21 +1,25 @@ # depslib dependency file v1.0 -1682275493 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp +1685969843 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp "histogram.h" "histogram_internal.h" + -1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h +1685965388 c:\users\hp\desktop\lab-03\project3\histogram.h -1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h +1685969642 c:\users\hp\desktop\lab-03\project3\histogram_internal.h -1682275379 source:c:\users\hp\desktop\lab-03\project3\unitest.cpp +1685970405 source:c:\users\hp\desktop\lab-03\project3\unitest.cpp "doctest.h" "histogram_internal.h" + + "doctest.h" + "histogram_internal.h" 1682274805 c:\users\hp\desktop\lab-03\project3\doctest.h