6 (7): create addition and test for my 9th var

main
DobrovolskaY 1 год назад
Родитель 5c687ccecd
Сommit cf09d57bbd

@ -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(){ int main(){

@ -26,16 +26,36 @@ void svg_rect(double x, double y, double width, double height){
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='#561A75' fill='#EDB1DB' ></rect>"; std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='#561A75' fill='#EDB1DB' ></rect>";
} }
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 void
show_histogram_svg(const std::vector<std::size_t>& bins) { show_histogram_svg(const std::vector<std::size_t>& bins) {
const auto IMAGE_WIDTH = 400; const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20; const auto TEXT_LEFT = 20;
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 = get_block_width();
const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0; double top = 0;

@ -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 mini = 0; double mini = 0;
@ -58,3 +59,21 @@ TEST_CASE("vector with fractional numbers") {
CHECK(mini == 2.2); CHECK(mini == 2.2);
CHECK(maxi == 2.4); 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);
}

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