code: выполнено задание для варианта №9

Этот коммит содержится в:
DevyatovaMY
2024-04-27 20:04:38 +03:00
родитель 906641a74f
Коммит 0b29726755
3 изменённых файлов: 35 добавлений и 1 удалений

18
svg.cpp
Просмотреть файл

@@ -5,6 +5,14 @@
using namespace std; using namespace std;
bool
check_width(double width) {
if (width >= 3 && width <= 30)
return true;
else
return false;
}
void void
svg_text(double left, double baseline, string text) { svg_text(double left, double baseline, string text) {
cout << "<text x='" << left cout << "<text x='" << left
@@ -47,8 +55,16 @@ show_histogram_svg(const vector<size_t>& bins) {
const auto TEXT_BASELINE = 20; const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50; const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10; double BLOCK_WIDTH = 0;
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH; 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; size_t max_count = 0;
for (size_t x : bins) { for (size_t x : bins) {
if (x > max_count) { if (x > max_count) {

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

Просмотреть файл

@@ -2,6 +2,7 @@
#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_internal.h"
TEST_CASE("distinct positive numbers") { TEST_CASE("distinct positive numbers") {
double min = 0; double min = 0;
@@ -52,3 +53,13 @@ TEST_CASE("empty vector") {
CHECK(min == 0); CHECK(min == 0);
CHECK(max == 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);
}