KorneevMA 7 месяцев назад
Родитель b6ce7a6162
Сommit 8ad65815a0

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -4,19 +4,19 @@ using namespace std;
void find_minmax(const vector<double> &numbers, double &min, double &max) void find_minmax(const vector<double> &numbers, double &min, double &max)
{ {
max = 0;
if (numbers.size() != 0) {
min = numbers[0]; min = numbers[0];
max = numbers[0]; max = numbers[0];
for (auto el : numbers) for (auto el : numbers) {
{ if (el > max) {
if (el > max)
{
max = el; max = el;
} }
if (el < min) if (el < min) {
{
min = el; min = el;
} }
} }
} else {min = 0;}
} }
vector<size_t> make_histogram(const vector<double> &numbers, const size_t bin_count){ vector<size_t> make_histogram(const vector<double> &numbers, const size_t bin_count){

@ -0,0 +1,4 @@
#pragma once
#include <vector>
void find_minmax(const std::vector<double> &numbers, double &min, double &max);

@ -0,0 +1,36 @@
#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("empty vector") {
double min = 0;
double max = 0;
find_minmax({ }, min, max);
CHECK(min == 0);
CHECK(max == 0);
}
TEST_CASE("one element") {
double min = 0;
double max = 0;
find_minmax({ 1 }, min, max);
CHECK(min == 1);
CHECK(max == 1);
}
TEST_CASE("negative elements") {
double min = 0;
double max = 0;
find_minmax({ -81, 2 }, min, max);
CHECK(min == -81);
CHECK(max == 2);
}
Загрузка…
Отмена
Сохранить