code: выполнено задание для варианта №9
Этот коммит содержится в:
18
svg.cpp
18
svg.cpp
@@ -5,6 +5,14 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool
|
||||
check_width(double width) {
|
||||
if (width >= 3 && width <= 30)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left
|
||||
@@ -47,8 +55,16 @@ show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
double BLOCK_WIDTH = 0;
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
cerr << "Enter block width: ";
|
||||
cin >> BLOCK_WIDTH;
|
||||
bool check = check_width(BLOCK_WIDTH);
|
||||
while (!check) {
|
||||
cerr << "Incorrectly enter. The block width must be >= 3px and <= 30 px. Please try again." << endl;
|
||||
cin >> BLOCK_WIDTH;
|
||||
check = check_width(BLOCK_WIDTH);
|
||||
}
|
||||
size_t max_count = 0;
|
||||
for (size_t x : bins) {
|
||||
if (x > max_count) {
|
||||
|
||||
7
svg_internal.h
Обычный файл
7
svg_internal.h
Обычный файл
@@ -0,0 +1,7 @@
|
||||
#ifndef SVG_INTERNAL_H_INCLUDED
|
||||
#define SVG_INTERNAL_H_INCLUDED
|
||||
|
||||
bool
|
||||
check_width(double width);
|
||||
|
||||
#endif // SVG_INTERNAL_H_INCLUDED
|
||||
11
unittest.cpp
11
unittest.cpp
@@ -2,6 +2,7 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "svg_internal.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
@@ -52,3 +53,13 @@ TEST_CASE("empty vector") {
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("correct block width") {
|
||||
bool check = check_width(23.5);
|
||||
CHECK(check == true);
|
||||
}
|
||||
|
||||
TEST_CASE("incorrect block width") {
|
||||
bool check = check_width(59);
|
||||
CHECK(check == false);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user