code: добавлены unit тесты
Этот коммит содержится в:
50
unittest.cpp
50
unittest.cpp
@@ -2,6 +2,9 @@
|
|||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
#include "doctest.h"
|
#include "doctest.h"
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
|
#include "svg.h"
|
||||||
|
#include <vector>
|
||||||
|
#include "histogram.h"
|
||||||
|
|
||||||
TEST_CASE("distinct positive numbers") {
|
TEST_CASE("distinct positive numbers") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
@@ -10,12 +13,45 @@ TEST_CASE("distinct positive numbers") {
|
|||||||
CHECK(min == 1);
|
CHECK(min == 1);
|
||||||
CHECK(max == 2);
|
CHECK(max == 2);
|
||||||
}
|
}
|
||||||
TEST_CASE("empty vector"){
|
TEST_CASE("show histogram vertical") {
|
||||||
double min = 0;
|
SUBCASE("single bin") {
|
||||||
double max = 0;
|
std::vector<std::size_t> bins = {5};
|
||||||
std::vector<double> numbers;
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
||||||
find_minmax(numbers, min, max);
|
}
|
||||||
CHECK(min == 0);
|
|
||||||
CHECK(max == 0);
|
SUBCASE("multiple bins") {
|
||||||
|
std::vector<std::size_t> bins = {3, 7, 2, 9, 5};
|
||||||
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("maxbin <= 76") {
|
||||||
|
std::vector<std::size_t> bins = {50, 30, 20, 10, 5};
|
||||||
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("maxbin > 76") {
|
||||||
|
std::vector<std::size_t> bins = {100, 200, 300, 400, 500};
|
||||||
|
CHECK_NOTHROW(show_histogram_svg_vertical(bins));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("make histogram") {
|
||||||
|
SUBCASE("single bin") {
|
||||||
|
std::vector<double> numbers = {1, 2, 3, 4, 5};
|
||||||
|
std::vector<std::size_t> res = {5};
|
||||||
|
CHECK(make_histogram(numbers, 1) == res);
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("multiple bins") {
|
||||||
|
std::vector<double> numbers = {1, 2, 3, 4, 5};
|
||||||
|
std::vector<std::size_t> res = {2, 1, 2};
|
||||||
|
CHECK(make_histogram(numbers, 3) == res);
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("min and max are the same") {
|
||||||
|
std::vector<double> numbers = {1, 1, 1, 1, 1};
|
||||||
|
std::vector<std::size_t> res = {5};
|
||||||
|
CHECK(make_histogram(numbers, 1) == res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user