Сравнить коммиты
	
		
			2 Коммитов 
		
	
	
		
			0d3fb9ea6a
			...
			6eb46fd053
		
	
	| Автор | SHA1 | Дата | 
|---|---|---|
| 
							
							
								
								 | 
						6eb46fd053 | 6 месяцев назад | 
| 
							
							
								
								 | 
						e93efef297 | 6 месяцев назад | 
@ -1 +1 @@
 | 
				
			|||||||
void find_minmax(std::vector<double> vec, double& min, double& max);
 | 
					bool find_minmax(const std::vector<double> vec, double& min, double& max);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,83 +1,44 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
#include "text.h"
 | 
					#include "text.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void show_histogram(std::vector<size_t> bins) {
 | 
					using namespace std;
 | 
				
			||||||
    bool gigant = false;
 | 
					 | 
				
			||||||
    auto spaces = 0;
 | 
					 | 
				
			||||||
    size_t mx_count = 0;
 | 
					 | 
				
			||||||
    for (auto x : bins) {
 | 
					 | 
				
			||||||
        if (x > 76) {
 | 
					 | 
				
			||||||
            gigant = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (x > mx_count) {
 | 
					 | 
				
			||||||
            mx_count = x;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        auto len = 0;
 | 
					 | 
				
			||||||
        while (x > 0) {
 | 
					 | 
				
			||||||
            x /= 10;
 | 
					 | 
				
			||||||
            len++;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (len > spaces) {
 | 
					 | 
				
			||||||
            spaces = len;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					void show_histogram_text(vector<size_t> bins, size_t bin_count){
 | 
				
			||||||
    if (spaces == 1) {
 | 
					    const size_t SCREEN_WIDTH = 80;
 | 
				
			||||||
        for (size_t i = 0; i < bins.size(); i++) {
 | 
					    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
 | 
				
			||||||
            std::cout << "  " << bins[i] << "|";
 | 
					
 | 
				
			||||||
            if (gigant) {
 | 
					    size_t max_bin = bins[0];
 | 
				
			||||||
                if (bins[i] == mx_count) {
 | 
					    for(size_t i = 0; i < bin_count; i++)
 | 
				
			||||||
                    for (size_t j = 0; j < 76; j++) {
 | 
					 | 
				
			||||||
                        std::cout << "*";
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
                    for (size_t j = 0; j < 76 * static_cast<double>(bins[i]) / mx_count; j++) {
 | 
					        if(bins[i] > max_bin)
 | 
				
			||||||
                        std::cout << "*";
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
                for (size_t j = 0; j < bins[i]; j++) {
 | 
					            max_bin = bins[i];
 | 
				
			||||||
                    std::cout << "*";
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                std::cout << std::endl;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
    else
 | 
					    for (size_t bin: bins)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for (size_t i = 0; i < bins.size(); i++) {
 | 
					        size_t height = bin;
 | 
				
			||||||
            int len = 1;
 | 
					
 | 
				
			||||||
            int k = bins[i];
 | 
					        if (max_bin > MAX_ASTERISK)
 | 
				
			||||||
            for (; k /= 10; ++len);
 | 
					 | 
				
			||||||
            while (len < spaces) {
 | 
					 | 
				
			||||||
                std::cout << " ";
 | 
					 | 
				
			||||||
                len++;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            std::cout << bins[i];
 | 
					 | 
				
			||||||
            std::cout << "|";
 | 
					 | 
				
			||||||
            if (gigant) {
 | 
					 | 
				
			||||||
                if (bins[i] == mx_count) {
 | 
					 | 
				
			||||||
                    for (size_t j = 0; j < 76; j++) {
 | 
					 | 
				
			||||||
                        std::cout << "*";
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
                    for (size_t j = 0; j < (76 * static_cast<double>(bins[i]) / mx_count - 1); j++) {
 | 
					          height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
 | 
				
			||||||
                        std::cout << "*";
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
                }
 | 
					
 | 
				
			||||||
            }
 | 
					        if (bin < 100)
 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
                for (size_t j = 0; j < bins[i]; j++) {
 | 
					            cout << ' ';
 | 
				
			||||||
                    std::cout << "*";
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (bin < 10)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            cout << ' ';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
            std::cout << std::endl;
 | 
					        cout << bin << "|";
 | 
				
			||||||
 | 
					        for(size_t i = 0; i < height; i++)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            cout << "*";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        cout << endl;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,3 @@
 | 
				
			|||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
void show_histogram(std::vector<size_t> bins);
 | 
					void show_histogram_text(std::vector<size_t> bins);
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					#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("distinct negative numbers"){
 | 
				
			||||||
 | 
					    double min = 0;
 | 
				
			||||||
 | 
					    double max = 0;
 | 
				
			||||||
 | 
					    find_minmax({-1, -2}, min, max);
 | 
				
			||||||
 | 
					    CHECK(min == -2);
 | 
				
			||||||
 | 
					    CHECK(max == -1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("vector of the same elements"){
 | 
				
			||||||
 | 
					    double min = 0;
 | 
				
			||||||
 | 
					    double max = 0;
 | 
				
			||||||
 | 
					    find_minmax({3,3,3}, min, max);
 | 
				
			||||||
 | 
					    CHECK(min == 3);
 | 
				
			||||||
 | 
					    CHECK(max == 3);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("empty vector"){
 | 
				
			||||||
 | 
					    double min = 0;
 | 
				
			||||||
 | 
					    double max = 0;
 | 
				
			||||||
 | 
					    CHECK(!find_minmax({}, min, max));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("vector of one elements"){
 | 
				
			||||||
 | 
					    double min = 0;
 | 
				
			||||||
 | 
					    double max = 0;
 | 
				
			||||||
 | 
					    find_minmax({3}, min, max);
 | 
				
			||||||
 | 
					    CHECK(min == max);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче