From 6b0a51458b41a24f7f9781ed0b2b945f23d96ceb Mon Sep 17 00:00:00 2001 From: StepanishchevVR Date: Wed, 8 May 2024 13:47:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D0=BD=D0=BA=D1=82=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LR3.cbp | 15 +++++++++++++++ histogram.cpp | 3 ++- main.cpp | 3 ++- svg.cpp | 9 +++++++++ unittest.cpp | 22 ++++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/LR3.cbp b/LR3.cbp index f86b34d..3b38ac4 100644 --- a/LR3.cbp +++ b/LR3.cbp @@ -32,7 +32,22 @@ + + + + + + + + + + + diff --git a/histogram.cpp b/histogram.cpp index 5bfcbfd..50d548b 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,9 +1,10 @@ #include "histogram.h" #include -static void find_minmax(const std::vector& numbers, double& min, double& max) +void find_minmax(const std::vector& numbers, double& min, double& max) { min = numbers[0]; + max = numbers[0]; for (double x : numbers) { if (x < min) diff --git a/main.cpp b/main.cpp index 4866c09..f2a6303 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; @@ -32,6 +33,6 @@ int main() { auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins); + show_histogram_svg(bins); return 0; } diff --git a/svg.cpp b/svg.cpp index 3e04594..8357f4c 100644 --- a/svg.cpp +++ b/svg.cpp @@ -31,6 +31,7 @@ void show_histogram_svg(const std::vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + const std::size_t MAX_STAR = IMAGE_WIDTH - TEXT_WIDTH; svg_begin(400, 300); double top = 0; @@ -41,5 +42,13 @@ void show_histogram_svg(const std::vector& bins) { top += BIN_HEIGHT; } + std::size_t max_star_search=bins[0]; + for (std::size_t i=0; i < bins.size(); i++){ + if (max_star_search < bins[i]){ + max_star_search=bins[i]; + } + } + + svg_end(); } diff --git a/unittest.cpp b/unittest.cpp index e69de29..4eea04a 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,22 @@ +#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("distinct negative numbers") { + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); +} + +