Сравнить коммиты
	
		
			Ничего общего в коммитах. 'aee4e114a95095b33c93f8ea5d945e9b8221744f' и 'eb168cef7df9f7637c06d6d2fa8f4163a3c9ba7a' имеют совершенно разные истории. 
		
	
	
		
			aee4e114a9
			...
			eb168cef7d
		
	
		
	@ -1,52 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include "histogram.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//std::vector<size_t>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
find_minmax(const std::vector<double> numbers, double& min, double& max)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
/*/double/*/ min = numbers[0];//ïîèñê ìèí è ìàêñ
 | 
					 | 
				
			||||||
/*/ double/*/ max = numbers[0];
 | 
					 | 
				
			||||||
for (double x : numbers)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
if (x < min)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
min = x;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
else if (x > max)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
max = x;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
std::vector<size_t>
 | 
					 | 
				
			||||||
make_histogram(const std::vector<double> numbers, size_t bin_count)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
std::vector <size_t> bins(bin_count);
 | 
					 | 
				
			||||||
double min, max;
 | 
					 | 
				
			||||||
find_minmax(numbers, min, max);
 | 
					 | 
				
			||||||
double bin_size = (max-min)/bin_count;//ðàçìåð êîðçèíû
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for (size_t i = 0; i < numbers.size(); i++)//çàïîëíåíèå
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
bool found = false;
 | 
					 | 
				
			||||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
auto lo = min + j * bin_size;
 | 
					 | 
				
			||||||
auto hi = min + (j + 1) * bin_size;
 | 
					 | 
				
			||||||
if ((lo <= numbers[i]) && (numbers[i] < hi))
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
bins[j]++;
 | 
					 | 
				
			||||||
found = true;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if (!found)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
bins[bin_count - 1]++;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
return bins;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,9 +0,0 @@
 | 
				
			|||||||
#ifndef HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
#define HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // HISTOGRAM_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,7 +0,0 @@
 | 
				
			|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void find_minmax(const std::vector<double> numbers, double& min, double& max);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,25 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include "svg.h"
 | 
					 | 
				
			||||||
using namespace std;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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
 | 
					 | 
				
			||||||
show_histogram_svg(const vector<size_t> &bins) {
 | 
					 | 
				
			||||||
    svg_begin(400, 300);
 | 
					 | 
				
			||||||
    svg_end();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,7 +0,0 @@
 | 
				
			|||||||
#ifndef SVG_H_INCLUDED
 | 
					 | 
				
			||||||
#define SVG_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
svg_begin(double width, double height)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // SVG_H_INCLUDED
 | 
					 | 
				
			||||||
@ -1,67 +0,0 @@
 | 
				
			|||||||
#include <iostream>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include "text.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace std;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
show_histogram_text(vector<size_t> bins, size_t bin_count)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    size_t max_count=0;
 | 
					 | 
				
			||||||
    for (size_t i =0; i<bin_count; i++)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if (max_count <bins[i])
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            max_count=bins[i];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    float procent;
 | 
					 | 
				
			||||||
    for(size_t i=0; i<bin_count; i++)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int procent =(float)bins[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (procent<10)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            cout<<"  "<<procent<<" | ";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if ((procent<100)&&(procent>=10))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            cout<<" "<<procent<<" | ";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        size_t height = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (max_count>76)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
 | 
					 | 
				
			||||||
            for(size_t j=0; j<=height; j++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                cout<<"*";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            for(size_t j=0; j<=bins[i]-1; j++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                cout<<"*";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cout<<endl;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
return;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,8 +0,0 @@
 | 
				
			|||||||
#ifndef TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
#define TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
std::vector<size_t>
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
show_histogram_text(std::vector<size_t> bins, size_t bin_count);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // TEXT_H_INCLUDED
 | 
					 | 
				
			||||||
@ -1,39 +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);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("vector 1 element")
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({1}, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 1);
 | 
					 | 
				
			||||||
    CHECK(max == 1);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("distinct negativ numbers")
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({-1, -2}, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == -2);
 | 
					 | 
				
			||||||
    CHECK(max == -1);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
TEST_CASE("distinct positive numbers")
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    double min = 0;
 | 
					 | 
				
			||||||
    double max = 0;
 | 
					 | 
				
			||||||
    find_minmax({2, 2}, min, max);
 | 
					 | 
				
			||||||
    CHECK(min == 2);
 | 
					 | 
				
			||||||
    CHECK(max == 2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче