diff --git a/main.cpp b/main.cpp index e9799ef..492acbd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,11 @@ + #include <iostream> #include <cmath> #include <vector> #include "histogram.h" #include "text.h" #include "svg.h" +#include <curl/curl.h> using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; @@ -44,6 +46,7 @@ input_data(istream& in, bool prompt) { int main() { + curl_global_init(CURL_GLOBAL_ALL); auto in = input_data(cin, true); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); diff --git a/project.cbp b/project.cbp index 99bb702..bb977d0 100644 --- a/project.cbp +++ b/project.cbp @@ -31,8 +31,25 @@ <Compiler> <Add option="-Wall" /> <Add option="-fexceptions" /> + <Add directory="curl/include" /> </Compiler> + <Linker> + <Add library="libcurl.dll.a" /> + <Add directory="curl/lib" /> + </Linker> + <Unit filename="histogram.cpp" /> + <Unit filename="histogram.h"> + <Option target="<{~None~}>" /> + </Unit> <Unit filename="main.cpp" /> + <Unit filename="svg.cpp" /> + <Unit filename="svg.h"> + <Option target="<{~None~}>" /> + </Unit> + <Unit filename="text.cpp" /> + <Unit filename="text.h"> + <Option target="<{~None~}>" /> + </Unit> <Extensions> <lib_finder disable_auto="1" /> </Extensions> diff --git a/svg.cpp b/svg.cpp index ab008d2..991a57d 100644 --- a/svg.cpp +++ b/svg.cpp @@ -22,14 +22,14 @@ svg_end() { } void -svg_text(double TEXT_LEFT, double BASELINE, string text) { - cout << "<text x='" << TEXT_LEFT << "' y='"<< BASELINE <<"'> " << text << "</text>"; +svg_text(double TEXT_LEFT, double BASELINE, string text, size_t bukva_scale) { + cout << "<text x='" << TEXT_LEFT << "' font-size = '" << bukva_scale << "' y='"<< BASELINE <<"'> " << text << "</text>"; } -void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT){ - cout << "<rect x='"<<TEXT_WIDTH<<"' y='"<<top<<"' width='"<<bin_width<<"' height='"<<BIN_HEIGHT<<"' stroke ='cyan' fill='#fce166' />\n"; +void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT, string grad){ + cout << "<rect x='"<<TEXT_WIDTH<<"' y='"<<top<<"' width='"<<bin_width<<"' height='"<<BIN_HEIGHT<<"' stroke ='cyan' fill='#"<<grad<<grad<<grad<<"' />\n"; } void @@ -43,8 +43,11 @@ show_histogram_svg(const vector<size_t>& bins) { const auto BLOCK_WIDTH = 10; const double SCALE = IMAGE_WIDTH - TEXT_WIDTH; + size_t grad = 0; double max_count = 0; + size_t bukva_scale = 12; + cin >> bukva_scale; for (double x: bins) { if (x > max_count) { max_count = x; @@ -56,8 +59,9 @@ show_histogram_svg(const vector<size_t>& bins) { double top = 0; for (size_t i = 0; i < bins.size(); i++) { const double bin_width = SCALE * ( bins[i] / max_count); - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + grad = (11 - (bins[i] * 9) / max_count); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]), bukva_scale); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, to_string(grad)); top += BIN_HEIGHT; cout << endl; cout << bin_width; diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..e720704 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,12 @@ <Compiler> <Add option="-Wall" /> </Compiler> + <Unit filename="doctest.h" /> + <Unit filename="histogram.cpp" /> + <Unit filename="histogram_internal.h"> + <Option target="<{~None~}>" /> + </Unit> + <Unit filename="unittest.cpp" /> <Extensions> <lib_finder disable_auto="1" /> </Extensions> diff --git a/unittest.cpp b/unittest.cpp index 99ba89b..3192ce9 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -6,17 +6,19 @@ TEST_CASE("distinct positive numbers") { double min = 0; double max = 0; - std::vector<double>test = {0}; - bool flag; - 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, -3, -4, -5}, min, max); CHECK(min == -5); CHECK(max == -1); - +} +TEST_CASE("distinct null vector") { + double min = 0; + double max = 0; CHECK(!find_minmax({}, min, max)); - CHECK(true); - } +}