Сравнить коммиты
Ничего общего в коммитах. '8c17279d7f02f7630ee6de7c9ba2774247f8d6ed' и 'c5702a13921206ad174f59d3e95f779c42a8ada5' имеют совершенно разные истории.
8c17279d7f
...
c5702a1392
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,9 +1,8 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "svg.h"
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto in = input_data();
|
auto in = input_data();
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_text(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
10
|
|
||||||
3 3 4 4 4 4 4 5 5 5
|
|
||||||
3
|
|
@ -1,51 +0,0 @@
|
|||||||
#include "svg.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void svg_begin(double width, double height) {
|
|
||||||
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
|
||||||
std::cout << "<svg width='" << width << "' height='" << height << "' "
|
|
||||||
<< "viewBox='0 0 " << width << " " << height << "' "
|
|
||||||
<< "xmlns='http://www.w3.org/2000/svg'>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void svg_end() {
|
|
||||||
std::cout << "</svg>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void svg_text(double left, double baseline, const std::string& text) {
|
|
||||||
std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void svg_rect(double x, double y, double width, double height,
|
|
||||||
const std::string& stroke, const std::string& fill) {
|
|
||||||
std::cout << "<rect x='" << x << "' y='" << y << "' "
|
|
||||||
<< "width='" << width << "' height='" << height << "' "
|
|
||||||
<< "stroke='" << stroke << "' fill='" << fill << "' />\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins) {
|
|
||||||
const size_t IMAGE_WIDTH = 400;
|
|
||||||
const size_t IMAGE_HEIGHT = 300;
|
|
||||||
const size_t TEXT_LEFT = 20;
|
|
||||||
const size_t TEXT_BASELINE = 20;
|
|
||||||
const size_t TEXT_WIDTH = 50;
|
|
||||||
const size_t BIN_HEIGHT = 30;
|
|
||||||
const size_t BLOCK_WIDTH = 10;
|
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
||||||
|
|
||||||
double top = 0;
|
|
||||||
size_t max_count = 0;
|
|
||||||
for (size_t count : bins) {
|
|
||||||
if (count > max_count) max_count = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t bin : bins) {
|
|
||||||
const double bin_width = static_cast<double>(bin) / max_count * (IMAGE_WIDTH - TEXT_WIDTH);
|
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#aaffaa");
|
|
||||||
top += BIN_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg_end();
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
void svg_begin(double width, double height);
|
|
||||||
void svg_end();
|
|
||||||
void svg_text(double left, double baseline, const std::string& text);
|
|
||||||
void svg_rect(double x, double y, double width, double height,
|
|
||||||
const std::string& stroke = "black", const std::string& fill = "black");
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
|
@ -1,12 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче