test: 1 проверка
Этот коммит содержится в:
@@ -2,29 +2,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static void
|
|
||||||
find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
|
||||||
Min = numbers[0];
|
|
||||||
Max = numbers[0];
|
|
||||||
for(size_t x : numbers)
|
|
||||||
{
|
|
||||||
if(x < Min)
|
|
||||||
{
|
|
||||||
Min = x;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
if(x > Max)
|
|
||||||
{
|
|
||||||
Max = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count)
|
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count)
|
||||||
{
|
{
|
||||||
std::vector<size_t> bins(bin_count);
|
std::vector<size_t> bins(bin_count);
|
||||||
double Min, Max;
|
double Min, Max;
|
||||||
find_minmax(numbers, Min, Max);
|
// find_minmax(numbers, Min, Max);
|
||||||
double bin_size = (Max - Min) / bin_count;
|
double bin_size = (Max - Min) / bin_count;
|
||||||
for (double x : numbers)
|
for (double x : numbers)
|
||||||
{
|
{
|
||||||
|
|||||||
23
histogram_internal.h
Обычный файл
23
histogram_internal.h
Обычный файл
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
|
void
|
||||||
|
find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
||||||
|
Min = numbers[0];
|
||||||
|
Max = numbers[0];
|
||||||
|
for(size_t x : numbers)
|
||||||
|
{
|
||||||
|
if(x < Min)
|
||||||
|
{
|
||||||
|
Min = x;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
if(x > Max)
|
||||||
|
{
|
||||||
|
Max = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
12
unittest.cpp
Обычный файл
12
unittest.cpp
Обычный файл
@@ -0,0 +1,12 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user