u02: Add property test for equality of fill tools

This commit is contained in:
Simon Bruder 2023-05-06 22:47:04 +02:00
parent 625c257f3f
commit dfeb329a52

View file

@ -214,3 +214,44 @@ TEST_CASE("Fill (recursive and non recursive) simple") {
REQUIRE_FALSE(canvas->get_pixel(30, 9));
REQUIRE_FALSE(canvas->get_pixel(19, 30));
}
TEST_CASE("Fill recursive == Fill non recursive (prop, 5 random lines)") {
const int size = 100;
canvas_buffer *canvas_recursive = new canvas_buffer(size, size);
canvas_buffer *canvas_non_recursive = new canvas_buffer(size, size);
bresenham_line_tool *tool_line_recursive =
new bresenham_line_tool(*canvas_recursive);
bresenham_line_tool *tool_line_non_recursive =
new bresenham_line_tool(*canvas_non_recursive);
recursive_fill_tool *tool_fill_recursive =
new recursive_fill_tool(*canvas_recursive);
non_recursive_fill_tool *tool_fill_non_recursive =
new non_recursive_fill_tool(*canvas_non_recursive);
for (int i = 0; i < 5; i++) {
int x0 = GENERATE(take(1, random(0, size - 1)));
int y0 = GENERATE(take(1, random(0, size - 1)));
int x1 = GENERATE(take(1, random(0, size - 1)));
int y1 = GENERATE(take(1, random(0, size - 1)));
tool_line_recursive->draw(x0, y0, x1, y1);
tool_line_non_recursive->draw(x0, y0, x1, y1);
}
int x = GENERATE(take(3, random(0, size - 1)));
int y = GENERATE(take(3, random(0, size - 1)));
tool_fill_recursive->draw(x, y);
tool_fill_non_recursive->draw(x, y);
bool equal = true;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
if (canvas_recursive->get_pixel(x, y) !=
canvas_non_recursive->get_pixel(x, y))
equal = false;
}
}
REQUIRE(equal);
}