code: проверка на нулевой массив

Этот коммит содержится в:
2023-05-22 16:16:37 +04:00
родитель 3661762f5a
Коммит c6251914a5
2 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@@ -3,12 +3,18 @@
#include <vector>
using namespace std;
void find_minmax( vector<double> numbers, double &min, double &max)
bool find_minmax( vector<double> numbers, double &min, double &max)
{
if (numbers.empty())
{
return false;
}
min = numbers[0];
max = numbers[0];
for (double x : numbers)
for (double x : numbers)
{
max = x;
if (x < min)
{
min = x;
@@ -18,7 +24,7 @@ void find_minmax( vector<double> numbers, double &min, double &max)
max = x;
}
}
return;
return true;
}
vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)

Просмотреть файл

@@ -2,6 +2,7 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
#include "sr.h"
TEST_CASE("distinct positive numbers") {
@@ -38,3 +39,11 @@ TEST_CASE("vector with same elements") {
CHECK(min == 2);
CHECK(max == 2);
}
TEST_CASE("Empty vector"){
double min = 0;
double max = 0;
std::vector<double> numbers {};
CHECK(find_minmax(numbers, min, max) == false);
}