Родитель
8d45096bef
Сommit
c2d6094820
@ -0,0 +1,6 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#include <vector>
|
||||
void find_minmax( const std::vector<double>& numbers, double& minN, double& maxN);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
@ -0,0 +1,41 @@
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
void show_histogram_text(const vector <size_t>& bins,size_t bin_count, size_t max_count){
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1;
|
||||
|
||||
bool scaling = false;
|
||||
|
||||
if (max_count > MAX_ASTERISK){
|
||||
scaling = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++){
|
||||
cout << " ";
|
||||
if (bins[i] < 100){
|
||||
cout << ' ';
|
||||
}
|
||||
if (bins[i] < 10){
|
||||
cout << ' ';
|
||||
}
|
||||
cout << bins[i] << '|';
|
||||
|
||||
size_t number_of_stars = bins[i];
|
||||
|
||||
if (scaling){
|
||||
if (bins[i] == max_count){
|
||||
number_of_stars = MAX_ASTERISK * 1.0;
|
||||
}
|
||||
else {
|
||||
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < number_of_stars; j++){
|
||||
cout << '*';
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
#include <vector>
|
||||
void show_histogram_text(const std::vector <size_t>& bins,size_t bin_count, size_t max_count);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
@ -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,13 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "histogram.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double minN = 0;
|
||||
double maxN = 0;
|
||||
find_minmax({1, 2}, minN, maxN);
|
||||
CHECK(minN == 1);
|
||||
CHECK(maxN == 2);
|
||||
}
|
||||
Загрузка…
Ссылка в новой задаче