From 3f5042566b35626eb39e9966a5101d6946e0ab18 Mon Sep 17 00:00:00 2001 From: MakhnovGA Date: Sat, 22 Apr 2023 21:55:48 +0300 Subject: [PATCH] =?UTF-8?q?build:=20=D0=BA=D0=BE=D0=B4=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=20=D0=BF=D0=BE=D0=B4=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=2015?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 6 ++++ histogram.h | 2 +- histogram_internal.h | 2 +- lab_01.depend | 12 ++++---- lab_01.layout | 31 ++++++++++++--------- main.cpp | 10 ++++++- svg.cpp | 13 ++++++++- svg.h | 2 +- unittest.cpp | 24 +++++++++++++++- unittest.depend | 65 ++++++++++++++++++++++++++++++++++++++++++-- unittest.layout | 16 +++++------ 11 files changed, 148 insertions(+), 35 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index ad6bb59..009e348 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -50,3 +50,9 @@ vector make_histogramm(vectornumbers, size_t bin_count){ }*/ return bins; } + +void check_interval(size_t &interval){ + if (interval > 9 || interval < 2) + interval = 0; + return; +} diff --git a/histogram.h b/histogram.h index a857690..05a9838 100644 --- a/histogram.h +++ b/histogram.h @@ -5,6 +5,6 @@ std::vector make_histogramm(std::vector numbers, size_t bin_count); - +void check_interval(size_t &interval); #endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h index f6af6df..224cd54 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -3,5 +3,5 @@ #include void find_minmax(std::vector numbers, double &min, double &max); - +void check_interval(size_t &interval); #endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/lab_01.depend b/lab_01.depend index 929ad9e..e85aaef 100644 --- a/lab_01.depend +++ b/lab_01.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1682156265 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.cpp +1682183565 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.cpp @@ -7,10 +7,10 @@ "histogram.h" "histogram_internal.h" -1681931103 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.h +1682184342 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.h -1682152541 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\main.cpp +1682184846 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\main.cpp @@ -29,12 +29,12 @@ "text.h" -1682091658 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram_internal.h +1682183685 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram_internal.h -1682108195 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\svg.h +1682183926 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\svg.h -1682156695 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\svg.cpp +1682189679 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\svg.cpp diff --git a/lab_01.layout b/lab_01.layout index 0f5fd1a..c3984ee 100644 --- a/lab_01.layout +++ b/lab_01.layout @@ -2,39 +2,44 @@ - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/main.cpp b/main.cpp index b7b096e..32df211 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ using namespace std; struct Input { vector numbers; size_t bin_count{}; + size_t interval; }; Input @@ -32,6 +33,13 @@ input_data(){ int main() { Input in = input_data(); auto bins = make_histogramm(in.numbers, in.bin_count); - show_histogram_svg(bins); + size_t interval; + cerr << "Input interval: "; cin >> interval; + check_interval(interval); + if (interval == 0){ + cerr << "ERROR"; + return 0; + } + show_histogram_svg(bins, interval); return 0; } diff --git a/svg.cpp b/svg.cpp index f81e0c2..31604f3 100644 --- a/svg.cpp +++ b/svg.cpp @@ -31,7 +31,7 @@ void svg_rect(double x, double y, double width, double height, string colour = " } void -show_histogram_svg(const vector& bins) { +show_histogram_svg(const vector& bins, size_t interval) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; const auto TEXT_LEFT = 20; @@ -52,5 +52,16 @@ show_histogram_svg(const vector& bins) { svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF"); top += BIN_HEIGHT; } + top+=BIN_HEIGHT; + const size_t SPACE = 2; + double max_width = (IMAGE_WIDTH - TEXT_WIDTH); + const double block = max_width/max_count; + for (size_t i = 0; i& bins); +show_histogram_svg(const std::vector& bins, size_t interval); #endif // SVG_H_INCLUDED diff --git a/unittest.cpp b/unittest.cpp index 23cd218..69871fd 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -4,7 +4,7 @@ #include "histogram_internal.h" #include #include -TEST_CASE("distinct positive numbers") { +/*TEST_CASE("distinct positive numbers") { double min = 0; double max = 0; std::vectorv{1}; @@ -14,4 +14,26 @@ TEST_CASE("distinct positive numbers") { CHECK(min == 1); CHECK(max == 2); CHECK(min != max); +}*/ + +TEST_CASE("interval check"){ + size_t interval = 3; + check_interval(interval); + CHECK(interval != 0); + interval = 10; + check_interval(interval); + CHECK(interval == 0); } + +/*#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.h" +#include "histogram_internal.h" +#include +#include +TEST_CASE("interval check"){ + size_t interval = 3; + bool flag = check_interval(interval); + CHECK(flag == true); +} +*/ diff --git a/unittest.depend b/unittest.depend index 2df752c..0420178 100644 --- a/unittest.depend +++ b/unittest.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1682090965 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.cpp +1682183565 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.cpp @@ -10,6 +10,67 @@ 1681931103 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram.h -1682091658 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram_internal.h +1682183685 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\histogram_internal.h +1682182932 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\unittest_15.cpp + "doctest.h" + "histogram_internal.h" + + + +1682183802 source:c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\unittest.cpp + "doctest.h" + "histogram_internal.h" + + + "doctest.h" + "histogram_internal.h" + + + +1682092158 c:\users\gmack\onedrive\рабочий стол\lab01\lab_01\doctest.h + + + + + + + "doctest_fwd.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unittest.layout b/unittest.layout index bee8e3b..59d0a06 100644 --- a/unittest.layout +++ b/unittest.layout @@ -2,24 +2,24 @@ - + - + - + - + - + - + - + - +