From 9e6c5d3142c0d20a1ae7cd6734c64676182485dc Mon Sep 17 00:00:00 2001 From: VolodinDV Date: Wed, 8 May 2024 14:51:44 +0300 Subject: [PATCH] code: my var --- histogram.cpp | 1 + lab1.cbp | 5 +++++ main.cpp | 3 +-- svg.cpp | 17 +++++++++++++---- unittest.cbp | 3 +++ unittest.cpp | 14 ++++++++++++++ 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 319e9d5..06d6351 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -42,3 +42,4 @@ std::vector make_histogram( const std::vector &numbers, st } return bins; } + diff --git a/lab1.cbp b/lab1.cbp index 6b42d83..6ac74c5 100644 --- a/lab1.cbp +++ b/lab1.cbp @@ -17,6 +17,7 @@ + @@ -36,6 +37,10 @@ + + + diff --git a/main.cpp b/main.cpp index 7ae72b6..5186de0 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include "histogram.h" #include "text.h" #include "svg.h" +#include "aver.h" using namespace std; @@ -40,8 +41,6 @@ Input input_data() { int main(){ - bool res = false; - Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); diff --git a/svg.cpp b/svg.cpp index 6c8689b..b335f36 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,6 +1,9 @@ #include #include #include "svg.h" +#include "aver.h" + + void svg_begin(double width, double height) { @@ -22,10 +25,15 @@ svg_text(double left, double baseline, std::string text) { std::cout << " " << text << " "; } -void svg_rect(double x, double y, double width, double height){ - std::cout << ""; +void svg_rect(double x, double y, double width, double height,int res){ + if(res == 1){ + std::cout << ""; + }if(res==2){ + std::cout << ""; + } } + void show_histogram_svg(const std::vector &bins) { @@ -47,11 +55,12 @@ show_histogram_svg(const std::vector &bins) { } } + if (maxbin<=76){ for (std::size_t i=0; i < bins.size(); i++) { double bin_width = BLOCK_WIDTH * bins[i]; svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,compareHeightToAverage(bins,i)); top += BIN_HEIGHT; } svg_end(); @@ -59,7 +68,7 @@ show_histogram_svg(const std::vector &bins) { for (std::size_t i=0; i < bins.size(); i++) { double bin_width= MAX_ASTERISK * (static_cast(bins[i]) / maxbin); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,compareHeightToAverage(bins,i)); top += BIN_HEIGHT; } svg_end(); diff --git a/unittest.cbp b/unittest.cbp index 8c1e1a9..ffa3d86 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,9 +31,12 @@ + + + diff --git a/unittest.cpp b/unittest.cpp index 25fe0e0..727332b 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -3,6 +3,7 @@ #include "doctest.h" #include #include "histogram_internal.h" +#include "aver.h" TEST_CASE("distinct positive numbers") { double min = 0; @@ -47,3 +48,16 @@ TEST_CASE("empty array") { CHECK(min == 0); CHECK(max == 0); } +TEST_CASE("my var 1") { + int a=compareHeightToAverage({1,1,2},1); + CHECK(a == 1); +} +TEST_CASE("my var 2") { + int a=compareHeightToAverage({1,1,2},2); + CHECK(a == 2); +} +TEST_CASE("my var 3") { + int a=compareHeightToAverage({2,1,1},3); + CHECK(a == 2); +} +