From 772868d3d1c03c7f155e443c3e1104d9d9a61e7f Mon Sep 17 00:00:00 2001 From: darcy Date: Thu, 5 Dec 2024 19:50:47 +1100 Subject: [PATCH] Add test case for `HeightMap` const iterator --- test/minecraft_tests.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/minecraft_tests.cpp b/test/minecraft_tests.cpp index 15b250e..e70b328 100644 --- a/test/minecraft_tests.cpp +++ b/test/minecraft_tests.cpp @@ -343,6 +343,32 @@ TEST_CASE("HeightMap functionality") { CHECK_EQ(heights, expected_heights); } + SUBCASE("Const iterator") { + mc.setBlocks(Coordinate{-200, 300, -200}, Coordinate{-210, 319, -210}, + Blocks::AIR); + mc.setBlocks(Coordinate{-200, 300, -200}, Coordinate{-210, 300, -210}, + Blocks::STONE); + mc.setBlock(Coordinate{-200, 301, -200}, Blocks::STONE); + mc.setBlock(Coordinate{-210, 301, -210}, Blocks::STONE); + mc.setBlock(Coordinate{-201, 301, -202}, Blocks::STONE); + + const HeightMap data = + mc.getHeights(Coordinate{-200, 0, -200}, Coordinate{-210, 0, -210}); + + std::vector expected_heights; + for (int i = 0; i < data.x_len(); i++) { + for (int j = 0; j < data.z_len(); j++) { + expected_heights.push_back(data.get(i, j)); + } + } + + std::vector heights; + for (int height : data) { + heights.push_back(height); + } + CHECK_EQ(heights, expected_heights); + } + // Clean up mc.setBlocks(Coordinate{200, 300, 200}, Coordinate{210, 301, 210}, Blocks::AIR);