Родитель
38e8c45bb5
Сommit
d4e6e73904
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void
|
||||||
|
find_minmax(const std::vector<double>& numbers, double& mini, double& maxi);
|
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="unittest" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
</Compiler>
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
@ -0,0 +1,60 @@
|
|||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
|
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({1, 2}, mini, maxi);
|
||||||
|
CHECK(mini == 1);
|
||||||
|
CHECK(maxi == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("empty vector") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({1, 2}, mini, maxi);
|
||||||
|
CHECK(mini == 1);
|
||||||
|
CHECK(maxi == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with one element") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({1}, mini, maxi);
|
||||||
|
CHECK(mini == 1);
|
||||||
|
CHECK(maxi == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with negative elements") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({-1, -2}, mini, maxi);
|
||||||
|
CHECK(mini == -2);
|
||||||
|
CHECK(maxi == -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with equivalent elements") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({2, 2}, mini, maxi);
|
||||||
|
CHECK(mini == 2);
|
||||||
|
CHECK(maxi == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with 0") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({0, 0}, mini, maxi);
|
||||||
|
CHECK(mini == 0);
|
||||||
|
CHECK(maxi == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with fractional numbers") {
|
||||||
|
double mini = 0;
|
||||||
|
double maxi = 0;
|
||||||
|
find_minmax({2.4, 2.2}, mini, maxi);
|
||||||
|
CHECK(mini == 2.2);
|
||||||
|
CHECK(maxi == 2.4);
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче