Сравнить коммиты
	
		
			Ничего общего в коммитах. '538508ef981039629ca55f920e89c62f31dc12c7' и 'cf465317f2f720d0913c7bb6c306c12fef445629' имеют совершенно разные истории. 
		
	
	
		
			538508ef98
			...
			cf465317f2
		
	
		
	| 
		 До Ширина: | Высота: | Размер: 448 B  | 
@ -1,3 +0,0 @@
 | 
				
			|||||||
10
 | 
					 | 
				
			||||||
3 3 4 4 4 4 4 5 5 5
 | 
					 | 
				
			||||||
3
 | 
					 | 
				
			||||||
											
												
													Разница между файлами не показана из-за своего большого размера
													Загрузить разницу
												
											
										
									
								@ -1,32 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "histogram.h"
 | 
					 | 
				
			||||||
#include "histogram_internal.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace std;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
vector <size_t> make_histogram(const vector<double>& numbers, const size_t bin_count) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	vector <size_t> bins(bin_count);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	double min_in_numbers, max_in_numbers;
 | 
					 | 
				
			||||||
	find_minmax(numbers, min_in_numbers, max_in_numbers);
 | 
					 | 
				
			||||||
	double bin_size = (max_in_numbers - min_in_numbers) / bin_count;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (size_t i = 0; i < numbers.size(); i++) {
 | 
					 | 
				
			||||||
		int to_bin = int((numbers[i]) - min_in_numbers) / bin_size;
 | 
					 | 
				
			||||||
		if (to_bin >= bin_count) {
 | 
					 | 
				
			||||||
			bins[to_bin - 1]++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			bins[to_bin]++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return bins;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,12 +0,0 @@
 | 
				
			|||||||
#ifndef HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
#define HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
std::vector<size_t>
 | 
					 | 
				
			||||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
@ -1,13 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "histogram_internal.h"
 | 
					 | 
				
			||||||
using namespace std;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void find_minmax(const vector<double>& numbers, double& min_in_numbers, double& max_in_numbers) {
 | 
					 | 
				
			||||||
	min_in_numbers = numbers[0];
 | 
					 | 
				
			||||||
	max_in_numbers = *(max_element(begin(numbers), end(numbers)));
 | 
					 | 
				
			||||||
	min_in_numbers = *(min_element(begin(numbers), end(numbers)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,8 +0,0 @@
 | 
				
			|||||||
#ifndef INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
#define INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void find_minmax(const std::vector<double>& numbers, double& min_in_numbers, double& max_in_numbers);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif //INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
@ -1,96 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include <string>
 | 
					 | 
				
			||||||
#include <random>
 | 
					 | 
				
			||||||
#include <sstream>
 | 
					 | 
				
			||||||
#include <iomanip>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "text.h"
 | 
					 | 
				
			||||||
#include "histogram.h"
 | 
					 | 
				
			||||||
#include "histogram_internal.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace std;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
std::string getRandomHexColor() {
 | 
					 | 
				
			||||||
	random_device rd;  // Èñòî÷íèê ñëó÷àéíûõ ÷èñåë
 | 
					 | 
				
			||||||
	mt19937 gen(rd()); // Ãåíåðàòîð Mersenne Twister
 | 
					 | 
				
			||||||
	std::uniform_int_distribution<> dis(0, 255); // Ðàâíîìåðíîå ðàñïðåäåëåíèå [0, 255]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	int r = dis(gen); // Êðàñíûé
 | 
					 | 
				
			||||||
	int g = dis(gen); // Çåëåíûé
 | 
					 | 
				
			||||||
	int b = dis(gen); // Ñèíèé
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Ôîðìèðóåì HEX-ñòðîêó
 | 
					 | 
				
			||||||
	std::stringstream hexStream;
 | 
					 | 
				
			||||||
	hexStream << "#"
 | 
					 | 
				
			||||||
		<< std::hex << std::setw(2) << std::setfill('0') << r
 | 
					 | 
				
			||||||
		<< std::hex << std::setw(2) << std::setfill('0') << g
 | 
					 | 
				
			||||||
		<< std::hex << std::setw(2) << std::setfill('0') << b;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return hexStream.str();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
svg_begin(double width, double height) {
 | 
					 | 
				
			||||||
	cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
 | 
					 | 
				
			||||||
	cout << "<svg ";
 | 
					 | 
				
			||||||
	cout << "width='" << width << "' ";
 | 
					 | 
				
			||||||
	cout << "height='" << height << "' ";
 | 
					 | 
				
			||||||
	cout << "viewBox='0 0 " << width << " " << height << "' ";
 | 
					 | 
				
			||||||
	cout << "xmlns='http://www.w3.org/2000/svg'>\n";
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
svg_end() {
 | 
					 | 
				
			||||||
	cout << "</svg>\n";
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
svg_text(double left, double baseline, string text) {
 | 
					 | 
				
			||||||
	cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>" << endl;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") {
 | 
					 | 
				
			||||||
	cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />" << endl;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
show_histogram_svg(const vector<size_t> bins) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	auto mm = *(max_element(bins.begin(), bins.end()));
 | 
					 | 
				
			||||||
	const auto IMAGE_WIDTH = 400;
 | 
					 | 
				
			||||||
	const auto IMAGE_HEIGHT = 300;
 | 
					 | 
				
			||||||
	const auto TEXT_LEFT = 20;
 | 
					 | 
				
			||||||
	const auto TEXT_BASELINE = 20;
 | 
					 | 
				
			||||||
	const auto TEXT_WIDTH = 50;
 | 
					 | 
				
			||||||
	const auto BIN_HEIGHT = 30;
 | 
					 | 
				
			||||||
	auto BLOCK_WIDTH = 10;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / mm;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	svg_begin(400, 300);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	double top = 0;
 | 
					 | 
				
			||||||
	for (size_t bin : bins) {
 | 
					 | 
				
			||||||
		const double bin_width = BLOCK_WIDTH * bin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "grey", getRandomHexColor());
 | 
					 | 
				
			||||||
		top += BIN_HEIGHT;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	//svg_begin(400, 300);
 | 
					 | 
				
			||||||
	//svg_text(20, 35, to_string(bins[0]));
 | 
					 | 
				
			||||||
	//svg_rect(50, 0, bins[0] * 10, 30, "purple", "red");
 | 
					 | 
				
			||||||
	svg_end();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,12 +0,0 @@
 | 
				
			|||||||
#ifndef TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
#define TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void show_histogram_text(std::vector <size_t> bins, size_t bin_count);
 | 
					 | 
				
			||||||
void show_histogram_svg(const std::vector<size_t> bins);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
@ -1,42 +0,0 @@
 | 
				
			|||||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
 | 
					 | 
				
			||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
 | 
					 | 
				
			||||||
#include "doctest.h"
 | 
					 | 
				
			||||||
#include "histogram_internal.h"
 | 
					 | 
				
			||||||
#include "histogram_internal.cpp"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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("empty vector") {
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({}, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 1);
 | 
					 | 
				
			||||||
    CHECK(max == 2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("you fill so lonly") {
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({ 1 }, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 1);
 | 
					 | 
				
			||||||
    CHECK(max == 2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("negative numbers") {
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({ -1, -2 }, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 1);
 | 
					 | 
				
			||||||
    CHECK(max == 2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("twins") {
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({ 1, 1 }, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 1);
 | 
					 | 
				
			||||||
    CHECK(max == 2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче