From 69b3377d1a2a341ba68ddc82b95537ddd97d0a8c Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 7 May 2023 10:03:41 +0200 Subject: [PATCH] u02: Implement rectangle tool --- u02/src/tests.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/u02/src/tests.cpp b/u02/src/tests.cpp index 75064fe..bf39f68 100644 --- a/u02/src/tests.cpp +++ b/u02/src/tests.cpp @@ -9,6 +9,7 @@ #include "canvas_buffer.h" #include "dda_line_tool.h" #include "non_recursive_fill_tool.h" +#include "rectangle_tool.h" #include "recursive_fill_tool.h" #include "util.h" @@ -263,3 +264,37 @@ TEST_CASE("Fill recursive == Fill non recursive (prop, 5 random lines)") { } REQUIRE(equal); } + +TEST_CASE("Rectangle (prop)") { + const int size = 100; + + const int x0 = GENERATE(take(5, random(0, size - 1))); + const int y0 = GENERATE(take(5, random(0, size - 1))); + const int x1 = GENERATE(take(5, random(0, size - 1))); + const int y1 = GENERATE(take(5, random(0, size - 1))); + + const int x_min = std::min(x0, x1); + const int x_max = std::max(x0, x1); + const int y_min = std::min(y0, y1); + const int y_max = std::max(y0, y1); + + canvas_buffer *canvas = new canvas_buffer(size, size); + rectangle_tool *tool = new rectangle_tool(*canvas); + + tool->draw(x0, y0, x1, y1); + + bool pass = true; + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + if (((x == x0 || x == x1) && (y >= y_min && y <= y_max)) || + ((y == y0 || y == y1) && (x >= x_min && x <= x_max))) { + if (!canvas->get_pixel(x, y)) + pass = false; + } else { + if (canvas->get_pixel(x, y)) + pass = false; + } + } + } + REQUIRE(pass); +}