Сравнить коммиты
	
		
			6 Коммитов 
		
	
	
		
			e9aceb1d0c
			...
			d4e6e73904
		
	
	| Автор | SHA1 | Дата | 
|---|---|---|
| 
							
							
								
								 | 
						d4e6e73904 | 2 лет назад | 
| 
							
							
								
								 | 
						38e8c45bb5 | 2 лет назад | 
| 
							
							
								
								 | 
						af03b35e5e | 2 лет назад | 
| 
							
							
								
								 | 
						6a087bcc34 | 2 лет назад | 
| 
							
							
								
								 | 
						efadf5adc7 | 2 лет назад | 
| 
							
							
								
								 | 
						17909b49ef | 2 лет назад | 
											
												
													Разница между файлами не показана из-за своего большого размера
													Загрузить разницу
												
											
										
									
								
											
												
													Разница между файлами не показана из-за своего большого размера
													Загрузить разницу
												
											
										
									
								@ -0,0 +1,45 @@
 | 
				
			||||
#include <iostream>
 | 
				
			||||
#include <vector>
 | 
				
			||||
#include <cmath>
 | 
				
			||||
#include "histogram.h"
 | 
				
			||||
using namespace std;
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
void find_minmax(const vector<double>& numbers, double& mini, double& maxi) {
 | 
				
			||||
 | 
				
			||||
    mini = numbers[0];
 | 
				
			||||
    maxi = numbers[0];
 | 
				
			||||
    for (double x : numbers) {
 | 
				
			||||
        if (x < mini) {
 | 
				
			||||
            mini = x;
 | 
				
			||||
        }
 | 
				
			||||
        else if (x > maxi) {
 | 
				
			||||
            maxi = x;
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
vector<size_t>
 | 
				
			||||
make_histogram(const vector<double>& numbers, size_t bin_count) {
 | 
				
			||||
    double mini, maxi;
 | 
				
			||||
    find_minmax(numbers, mini, maxi);
 | 
				
			||||
 | 
				
			||||
    vector<size_t> bins(bin_count);
 | 
				
			||||
 | 
				
			||||
    double bin_size = (maxi - mini) / bin_count;
 | 
				
			||||
    for (double num : numbers) {
 | 
				
			||||
        bool found = false;
 | 
				
			||||
        for (size_t j = 0; (j < bin_count - 1) && !found; j++){
 | 
				
			||||
            auto lo = mini + j * bin_size;
 | 
				
			||||
            auto hi = mini + (j + 1) * bin_size;
 | 
				
			||||
            if ((lo <= num) && (num < hi)) {
 | 
				
			||||
                bins[j]++;
 | 
				
			||||
                found = true;
 | 
				
			||||
            }
 | 
				
			||||
        }
 | 
				
			||||
        if (!found) {
 | 
				
			||||
            bins[bin_count - 1]++;
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    return bins;
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,5 @@
 | 
				
			||||
#pragma once
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
std::vector<size_t>
 | 
				
			||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
 | 
				
			||||
@ -0,0 +1,5 @@
 | 
				
			||||
#pragma once
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
void
 | 
				
			||||
find_minmax(const std::vector<double>& numbers, double& mini, double& maxi);
 | 
				
			||||
@ -0,0 +1,38 @@
 | 
				
			||||
#include <iostream>
 | 
				
			||||
#include <vector>
 | 
				
			||||
#include <cmath>
 | 
				
			||||
#include "text.h"
 | 
				
			||||
using namespace std;
 | 
				
			||||
 | 
				
			||||
void
 | 
				
			||||
show_histogram_text(const vector<size_t>& bins, size_t bin_count) {
 | 
				
			||||
    size_t max_count = bins[0];
 | 
				
			||||
    for (size_t i = 0; i < bin_count; i++) {
 | 
				
			||||
        if (bins[i] > max_count) {
 | 
				
			||||
            max_count = bins[i];
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    vector<size_t> height(bin_count);
 | 
				
			||||
    for (size_t i = 0; i < bin_count; i++) {
 | 
				
			||||
        if (max_count > MAX_ASTERISK) {
 | 
				
			||||
            height[i] = round(MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count));
 | 
				
			||||
        } else {
 | 
				
			||||
            height[i] = bins[i];
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    for (size_t i = 0; i < bin_count; i++) {
 | 
				
			||||
        if (bins[i] < 10) {
 | 
				
			||||
            cout << "  ";
 | 
				
			||||
        } else if (bins[i] < 100) {
 | 
				
			||||
            cout << " ";
 | 
				
			||||
        }
 | 
				
			||||
        cout << bins[i] << "| ";
 | 
				
			||||
 | 
				
			||||
        for (size_t j = 0; j < height[i]; j++) {
 | 
				
			||||
            cout << " * ";
 | 
				
			||||
        }
 | 
				
			||||
        cout << endl;
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,5 @@
 | 
				
			||||
#pragma once
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
void
 | 
				
			||||
show_histogram_text(const vector<size_t>& bins, size_t bin_count);
 | 
				
			||||
@ -0,0 +1,38 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||
<CodeBlocks_project_file>
 | 
				
			||||
	<FileVersion major="1" minor="6" />
 | 
				
			||||
	<Project>
 | 
				
			||||
		<Option title="unittest" />
 | 
				
			||||
		<Option pch_mode="2" />
 | 
				
			||||
		<Option compiler="gcc" />
 | 
				
			||||
		<Build>
 | 
				
			||||
			<Target title="Debug">
 | 
				
			||||
				<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
 | 
				
			||||
				<Option object_output="obj/Debug/" />
 | 
				
			||||
				<Option type="1" />
 | 
				
			||||
				<Option compiler="gcc" />
 | 
				
			||||
				<Compiler>
 | 
				
			||||
					<Add option="-g" />
 | 
				
			||||
				</Compiler>
 | 
				
			||||
			</Target>
 | 
				
			||||
			<Target title="Release">
 | 
				
			||||
				<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
 | 
				
			||||
				<Option object_output="obj/Release/" />
 | 
				
			||||
				<Option type="1" />
 | 
				
			||||
				<Option compiler="gcc" />
 | 
				
			||||
				<Compiler>
 | 
				
			||||
					<Add option="-O2" />
 | 
				
			||||
				</Compiler>
 | 
				
			||||
				<Linker>
 | 
				
			||||
					<Add option="-s" />
 | 
				
			||||
				</Linker>
 | 
				
			||||
			</Target>
 | 
				
			||||
		</Build>
 | 
				
			||||
		<Compiler>
 | 
				
			||||
			<Add option="-Wall" />
 | 
				
			||||
		</Compiler>
 | 
				
			||||
		<Extensions>
 | 
				
			||||
			<lib_finder disable_auto="1" />
 | 
				
			||||
		</Extensions>
 | 
				
			||||
	</Project>
 | 
				
			||||
</CodeBlocks_project_file>
 | 
				
			||||
@ -0,0 +1,60 @@
 | 
				
			||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
 | 
				
			||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
 | 
				
			||||
#include "doctest.h"
 | 
				
			||||
#include "histogram_internal.h"
 | 
				
			||||
 | 
				
			||||
TEST_CASE("distinct positive numbers") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({1, 2}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 1);
 | 
				
			||||
    CHECK(maxi == 2);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("empty vector") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({1, 2}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 1);
 | 
				
			||||
    CHECK(maxi == 2);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("vector with one element") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({1}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 1);
 | 
				
			||||
    CHECK(maxi == 1);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("vector with negative elements") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({-1, -2}, mini, maxi);
 | 
				
			||||
    CHECK(mini == -2);
 | 
				
			||||
    CHECK(maxi == -1);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("vector with equivalent elements") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({2, 2}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 2);
 | 
				
			||||
    CHECK(maxi == 2);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("vector with 0") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({0, 0}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 0);
 | 
				
			||||
    CHECK(maxi == 0);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
TEST_CASE("vector with fractional numbers") {
 | 
				
			||||
    double mini = 0;
 | 
				
			||||
    double maxi = 0;
 | 
				
			||||
    find_minmax({2.4, 2.2}, mini, maxi);
 | 
				
			||||
    CHECK(mini == 2.2);
 | 
				
			||||
    CHECK(maxi == 2.4);
 | 
				
			||||
}
 | 
				
			||||
					Загрузка…
					
					
				
		Ссылка в новой задаче