Input data
Этот коммит содержится в:
19
main.cpp
19
main.cpp
@@ -12,26 +12,27 @@ struct Input
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
Input
|
||||
input_data()
|
||||
Input input_data(istream& in, bool prompt = true)
|
||||
{
|
||||
size_t number_count;
|
||||
if (prompt)
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
in >> number_count;
|
||||
Input input;
|
||||
input.numbers.resize(number_count);
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
cin >> in.numbers[i];
|
||||
in >> input.numbers[i];
|
||||
}
|
||||
if (prompt)
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
in >> input.bin_count;
|
||||
return input;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Input in = input_data();
|
||||
Input in = input_data(cin);
|
||||
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,14 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename=".gitignore" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
1
svg.h
1
svg.h
@@ -1,6 +1,5 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
</Unit>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
|
||||
35
unittest.cpp
35
unittest.cpp
@@ -3,6 +3,8 @@
|
||||
#include <vector>
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "svg.h"
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
@@ -19,15 +21,6 @@ TEST_CASE("negative numbers") {
|
||||
CHECK(min == -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") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
@@ -36,9 +29,25 @@ TEST_CASE("one number") {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user