Daniil (FilippovDY) 12 месяцев назад
Родитель fe6d5c62ec
Сommit d022b0a95b

@ -1,11 +1,10 @@
#include "histogram.h" #include "histogram.h"
#include <vector> #include <vector>
#include "histogram_internal.h" #include "histogram_internal.h"
void find_minmax(const std::vector <double> &numbers, double &min, double &max, bool &res) void find_minmax(const std::vector <double> &numbers, double &min, double &max)
{ {
if (numbers.size()==0) if (numbers.size()==0)
{ {
res = true;
return; return;
} }
min = numbers[0]; min = numbers[0];
@ -26,7 +25,7 @@ std::vector<std::size_t> make_histogram(const std::vector<double> &numbers, std:
{ {
double min, max; double min, max;
bool res = false; bool res = false;
find_minmax(numbers, min, max, res); find_minmax(numbers, min, max);
double bin_size = (max - min) / bin_count; double bin_size = (max - min) / bin_count;
std::vector <std::size_t> bins (bin_count); std::vector <std::size_t> bins (bin_count);

@ -3,6 +3,6 @@
#include <vector> #include <vector>
void find_minmax(const std::vector <double> &numbers, double &min, double &max, bool &res); void find_minmax(const std::vector <double> &numbers, double &min, double &max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED #endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -30,7 +30,6 @@ input_data()
int int
main() main()
{ {
bool res = false;
Input in = input_data(); Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);

@ -6,52 +6,35 @@
TEST_CASE("distinct positive numbers") { TEST_CASE("distinct positive numbers") {
bool res = false;
double min = 0; double min = 0;
double max = 0; double max = 0;
find_minmax({1, 2}, min, max, res); find_minmax({1, 2}, min, max);
CHECK(min == 1); CHECK(min == 1);
CHECK(max == 2); CHECK(max == 2);
CHECK(res==0);
} }
TEST_CASE("negative numbers") { TEST_CASE("negative numbers") {
bool res = false;
double min = 0; double min = 0;
double max = 0; double max = 0;
find_minmax({-1, -2}, min, max, res); find_minmax({-1, -2}, min, max);
CHECK(min == -2); CHECK(min == -2);
CHECK(max == -1); CHECK(max == -1);
CHECK(res==0);
} }
TEST_CASE("empty array") { TEST_CASE("empty vector") {
bool res = false;
double min = 0; double min = 0;
double max = 0; double max = 0;
std::vector<double> numbers; std::vector<double> numbers;
find_minmax(numbers, min, max, res); find_minmax(numbers, min, max);
CHECK(min == 0); CHECK(min == 0);
CHECK(max == 0); CHECK(max == 0);
CHECK(res==1);
} }
TEST_CASE("1 number") { TEST_CASE("1 number") {
bool res = false;
double min = 0; double min = 0;
double max = 0; double max = 0;
find_minmax({-1}, min, max, res); find_minmax({-1}, min, max);
CHECK(min == -1); CHECK(min == -1);
CHECK(max == -1); CHECK(max == -1);
CHECK(res==0);
} }
TEST_CASE("same number") {
bool res = false;
double min = 0;
double max = 0;
find_minmax({1,1,1,1}, min, max, res);
CHECK(min == 1);
CHECK(max == 1);
CHECK(res==0);
}

Загрузка…
Отмена
Сохранить