added tests
Этот коммит содержится в:
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -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)
|
||||||
{
|
{
|
||||||
min = numbers[0];
|
max = 0;
|
||||||
max = numbers[0];
|
if (numbers.size() != 0) {
|
||||||
for (auto el : numbers)
|
min = numbers[0];
|
||||||
{
|
max = numbers[0];
|
||||||
if (el > max)
|
for (auto el : numbers) {
|
||||||
{
|
if (el > max) {
|
||||||
max = el;
|
max = el;
|
||||||
|
}
|
||||||
|
if (el < min) {
|
||||||
|
min = el;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (el < min)
|
} else {min = 0;}
|
||||||
{
|
|
||||||
min = el;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
|
|||||||
4
histogram_internal.h
Обычный файл
4
histogram_internal.h
Обычный файл
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void find_minmax(const std::vector<double> &numbers, double &min, double &max);
|
||||||
36
unittest.cpp
Обычный файл
36
unittest.cpp
Обычный файл
@@ -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);
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user