diff --git a/main.cpp b/main.cpp
index a32c127..6ec2d12 100644
--- a/main.cpp
+++ b/main.cpp
@@ -33,14 +33,6 @@ input_data() {
}
-//int main (){
- // auto in = input_data();
- //auto bins = make_histogram(in.numbers, in.bin_count);
- // svg_rect(50, 0, bins[0] * 10, 30);
- // show_histogram_svg(bins);
-
- // return 0;
-//}
int main(){
diff --git a/svg.cpp b/svg.cpp
index a78fbf3..8b695c4 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -26,16 +26,36 @@ void svg_rect(double x, double y, double width, double height){
std::cout << "";
}
+double
+get_block_width() {
+ double BLOCK_WIDTH;
+ do {
+ std::cerr << "Enter width of one historgamm block (from 3 to 30): ";
+ std::cin >> BLOCK_WIDTH;
+ if (BLOCK_WIDTH < 3) {
+ std::cerr << "The block width cannot be less than 3px. Enter the value again.\n";
+ }
+ else if (BLOCK_WIDTH > 30) {
+ std::cerr << "The block width cannot be more than 30px. Enter the value again.\n";
+ }
+
+ } while (BLOCK_WIDTH < 3 || BLOCK_WIDTH > 30);
+ return BLOCK_WIDTH;
+}
+
void
show_histogram_svg(const std::vector& bins) {
+
+
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
- const auto BLOCK_WIDTH = 10;
+ double BLOCK_WIDTH = get_block_width();
+
const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
diff --git a/unittest.cpp b/unittest.cpp
index 047dda5..60ef89f 100644
--- a/unittest.cpp
+++ b/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 mini = 0;
@@ -58,3 +59,21 @@ TEST_CASE("vector with fractional numbers") {
CHECK(mini == 2.2);
CHECK(maxi == 2.4);
}
+
+TEST_CASE("20") {
+ double BLOCK_WIDTH = 0;
+ BLOCK_WIDTH = get_block_width();
+ CHECK(BLOCK_WIDTH == 20);
+}
+
+TEST_CASE("4.5") {
+ double BLOCK_WIDTH = 0;
+ BLOCK_WIDTH = get_block_width();
+ CHECK(BLOCK_WIDTH == 4.5);
+}
+
+TEST_CASE("-1") {
+ double BLOCK_WIDTH = 0;
+ BLOCK_WIDTH = get_block_width();
+ CHECK(BLOCK_WIDTH == -1);
+}