BushmanovAS 11 месяцев назад
Родитель 712f9245b7
Сommit b8a8ebdeba

@ -12,26 +12,27 @@ struct Input
size_t bin_count{}; size_t bin_count{};
}; };
Input Input input_data(istream& in, bool prompt = true)
input_data()
{ {
size_t number_count; size_t number_count;
cerr << "Enter number count: "; if (prompt)
cin >> number_count; cerr << "Enter number count: ";
Input in; in >> number_count;
in.numbers.resize(number_count); Input input;
input.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) for (size_t i = 0; i < number_count; i++)
{ {
cin >> in.numbers[i]; in >> input.numbers[i];
} }
cerr << "Enter bin count: "; if (prompt)
cin >> in.bin_count; cerr << "Enter bin count: ";
return in; in >> input.bin_count;
return input;
} }
int main() int main()
{ {
Input in = input_data(); Input in = input_data(cin);
vector<size_t> bins = make_histogram(in.numbers, in.bin_count); vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
} }

@ -32,7 +32,14 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename=".gitignore" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -1,6 +1,5 @@
#ifndef SVG_H_INCLUDED #ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED #define SVG_H_INCLUDED
#include <vector> #include <vector>
void void

@ -36,6 +36,8 @@
</Unit> </Unit>
<Unit filename="histogram.cpp" /> <Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" /> <Unit filename="histogram_internal.h" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="unittest.cpp" /> <Unit filename="unittest.cpp" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />

@ -3,6 +3,8 @@
#include <vector> #include <vector>
#include "doctest.h" #include "doctest.h"
#include "histogram_internal.h" #include "histogram_internal.h"
#include "svg.h"
#include <string>
TEST_CASE("distinct positive numbers") { TEST_CASE("distinct positive numbers") {
double min = 0; double min = 0;
@ -19,15 +21,6 @@ TEST_CASE("negative numbers") {
CHECK(min == -10); CHECK(min == -10);
CHECK(max == 10); CHECK(max == 10);
} }
TEST_CASE("empty numbers") {
double min = 0;
double max = 0;
find_minmax({ }, min, max);
CHECK(min != 0);
CHECK(max != 0);
}
TEST_CASE("one number") { TEST_CASE("one number") {
double min = 0; double min = 0;
double max = 0; double max = 0;
@ -36,9 +29,25 @@ TEST_CASE("one number") {
CHECK(max == 2); CHECK(max == 2);
} }
#include "doctest.h"
#include "svg.h"
#include <sstream>
#include <string>
TEST_CASE("show_histogram_svg") {
std::ostringstream oss;
std::streambuf* p_cout_streambuf = std::cout.rdbuf();
std::cout.rdbuf(oss.rdbuf());
show_histogram_svg({1, 2, 3, 4});
std::cout.rdbuf(p_cout_streambuf);
std::string result = oss.str();
std::string expected = "<?xml version='1.0' encoding='UTF-8'?>"
"<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>"
"<rect x='30' y='0' width='10' height='30' />"
"<text x='40' y='20'>1</text><rect x='20' y='30' width='20' height='30' />"
"<text x='40' y='50'>2</text><rect x='10' y='60' width='30' height='30' />"
"<text x='40' y='80'>3</text><rect x='0' y='90' width='40' height='30' />"
"<text x='40' y='110'>4</text></svg>";
CHECK(result == expected);
}

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