From f81098f25915a4589a95b73e85c74c94c8f1d318 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 7 May 2023 10:05:43 +0200 Subject: [PATCH] u02/tests: Use const where possible --- u02/src/tests.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/u02/src/tests.cpp b/u02/src/tests.cpp index bf39f68..a2611dd 100644 --- a/u02/src/tests.cpp +++ b/u02/src/tests.cpp @@ -62,8 +62,8 @@ TEST_CASE("Transform Rotate + Mirror") { } TEST_CASE("Transform = Inverse Transform ○ Transform") { - int x = GENERATE(take(10, random(-100, 100))); - int y = GENERATE(take(10, random(-100, 100))); + const int x = GENERATE(take(10, random(-100, 100))); + const int y = GENERATE(take(10, random(-100, 100))); // this iterates over all possible transformations, // even bogus ones (like rotating cw and ccw) for (Transformation transformation = 0; transformation < 0b10000; @@ -99,7 +99,7 @@ TEST_CASE("Transformation to standard case (prop)") { int x1 = GENERATE(take(10, random(-100, 100))); int y1 = GENERATE(take(10, random(-100, 100))); - Transformation transformation = + const Transformation transformation = transformation_to_standard_case(x0, y0, x1, y1); transform_mut(transformation, x0, y0); @@ -118,7 +118,7 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel " dda_line_tool *tool_dda = new dda_line_tool(*canvas); tool_base *tool; - int tool_idx = GENERATE(0, 1); + const int tool_idx = GENERATE(0, 1); switch (tool_idx) { case 0: tool = tool_bresenham; @@ -128,17 +128,17 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel " break; } - int x0 = GENERATE(take(10, random(0, size - 1))); - int y0 = GENERATE(take(10, random(0, size - 1))); - int x1 = GENERATE(take(10, random(0, size - 1))); - int y1 = GENERATE(take(10, random(0, size - 1))); + const int x0 = GENERATE(take(10, random(0, size - 1))); + const int y0 = GENERATE(take(10, random(0, size - 1))); + const int x1 = GENERATE(take(10, random(0, size - 1))); + const int y1 = GENERATE(take(10, random(0, size - 1))); tool->draw(x0, y0, x1, y1); - int x_min = std::min(x0, x1); - int x_max = std::max(x0, x1); - int y_min = std::min(y0, y1); - int y_max = std::max(y0, y1); + 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); // Depending on what the direction of the line (rounded to the next 90°) is, // either every row or column has only one pixel set. @@ -191,7 +191,7 @@ TEST_CASE("Fill (recursive and non recursive) test shape") { new non_recursive_fill_tool(*canvas); tool_base *tool_fill; - int tool_fill_idx = GENERATE(0, 1); + const int tool_fill_idx = GENERATE(0, 1); switch (tool_fill_idx) { case 0: tool_fill = tool_fill_recursive; @@ -241,16 +241,16 @@ TEST_CASE("Fill recursive == Fill non recursive (prop, 5 random lines)") { 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))); + const int x0 = GENERATE(take(1, random(0, size - 1))); + const int y0 = GENERATE(take(1, random(0, size - 1))); + const int x1 = GENERATE(take(1, random(0, size - 1))); + const 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))); + const int x = GENERATE(take(3, random(0, size - 1))); + const int y = GENERATE(take(3, random(0, size - 1))); tool_fill_recursive->draw(x, y); tool_fill_non_recursive->draw(x, y);