code: Модульные тесты
Этот коммит содержится в:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static 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];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
|
|||||||
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);
|
||||||
45
unittest.cpp
Обычный файл
45
unittest.cpp
Обычный файл
@@ -0,0 +1,45 @@
|
|||||||
|
#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("negative numbers")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, -2}, min, max);
|
||||||
|
CHECK(min == -2);
|
||||||
|
CHECK(max == -1);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of the same elements")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3,3,3}, min, max);
|
||||||
|
CHECK(min == 3);
|
||||||
|
CHECK(max == 3);
|
||||||
|
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of the one elements")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3}, min, max);
|
||||||
|
CHECK(min == max);
|
||||||
|
}
|
||||||
|
TEST_CASE("positive and negative numbers")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, 2, 0, -3, 5}, min, max);
|
||||||
|
CHECK(min == -3);
|
||||||
|
CHECK(max == 5);
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user