| 5 | using namespace Star; |
| 6 | |
| 7 | TEST(TileSectorArrayTest, All) { |
| 8 | typedef TileSectorArray<int, 32> TileArray; |
| 9 | TileArray tileSectorArray({100, 100}, -1); |
| 10 | |
| 11 | EXPECT_TRUE(tileSectorArray.sectorValid(TileArray::Sector(1, 1))); |
| 12 | EXPECT_TRUE(tileSectorArray.sectorValid(TileArray::Sector(3, 3))); |
| 13 | EXPECT_FALSE(tileSectorArray.sectorValid(TileArray::Sector(4, 4))); |
| 14 | |
| 15 | EXPECT_TRUE(List<TileArray::Sector>({{0, 0}, {1, 0}}) == tileSectorArray.validSectorsFor(RectI(0, -32, 64, 32))); |
| 16 | |
| 17 | EXPECT_TRUE(TileArray::Sector(0, 0) == tileSectorArray.sectorFor({0, 0})); |
| 18 | EXPECT_TRUE(TileArray::Sector(3, 1) == tileSectorArray.sectorFor({-1, 33})); |
| 19 | EXPECT_TRUE(-1 == tileSectorArray.tile({-1, -1})); |
| 20 | EXPECT_TRUE(nullptr == tileSectorArray.modifyTile({-1, -1})); |
| 21 | EXPECT_TRUE(RectI(32, 32, 64, 64) == tileSectorArray.sectorRegion({1, 1})); |
| 22 | EXPECT_TRUE(TileArray::Sector(0, 3) == tileSectorArray.adjacentSector({3, 3}, {1, 0})); |
| 23 | |
| 24 | tileSectorArray.loadSector({0, 0}, make_unique<TileArray::Array>(1)); |
| 25 | tileSectorArray.loadSector({1, 0}, make_unique<TileArray::Array>(1)); |
| 26 | tileSectorArray.loadSector({2, 0}, make_unique<TileArray::Array>(1)); |
| 27 | tileSectorArray.loadSector({3, 0}, make_unique<TileArray::Array>(1)); |
| 28 | tileSectorArray.loadSector({0, 1}, make_unique<TileArray::Array>(2)); |
| 29 | tileSectorArray.loadSector({1, 1}, make_unique<TileArray::Array>(2)); |
| 30 | tileSectorArray.loadSector({2, 1}, make_unique<TileArray::Array>(2)); |
| 31 | tileSectorArray.loadSector({3, 1}, make_unique<TileArray::Array>(2)); |
| 32 | |
| 33 | Set<Vec2I> found; |
| 34 | tileSectorArray.tileEach(RectI(-2, 0, 3, 1), |
| 35 | [&found](Vec2I const& pos, int tile) { |
| 36 | found.add(pos); |
| 37 | EXPECT_TRUE(pos[0] >= -2 && pos[0] < 3); |
| 38 | EXPECT_TRUE(pos[1] == 0); |
| 39 | EXPECT_EQ(1, tile); |
| 40 | }); |
| 41 | EXPECT_TRUE(found.contains(Vec2I(0, 0))); |
| 42 | EXPECT_TRUE(found.contains(Vec2I(-1, 0))); |
| 43 | EXPECT_TRUE(found.contains(Vec2I(-2, 0))); |
| 44 | EXPECT_TRUE(found.contains(Vec2I(1, 0))); |
| 45 | |
| 46 | tileSectorArray.tileEach(RectI(-10, 0, -1, 1), |
| 47 | [](Vec2I const& pos, int tile) { |
| 48 | EXPECT_TRUE(pos[0] >= -10 && pos[0] < -1); |
| 49 | EXPECT_EQ(1, tile); |
| 50 | }); |
| 51 | |
| 52 | tileSectorArray.tileEach(RectI(-10, -1, -1, 0), |
| 53 | [](Vec2I const& pos, int tile) { |
| 54 | EXPECT_TRUE(pos[0] >= -10 && pos[0] < -1); |
| 55 | EXPECT_TRUE(pos[1] == -1); |
| 56 | EXPECT_EQ(-1, tile); |
| 57 | }); |
| 58 | |
| 59 | found.clear(); |
| 60 | tileSectorArray.tileEach(RectI(110, 101, 120, 102), |
| 61 | [&found](Vec2I const& pos, int tile) { |
| 62 | found.add(pos); |
| 63 | EXPECT_TRUE(pos[0] >= 110 && pos[0] < 120); |
| 64 | EXPECT_TRUE(pos[1] == 101); |
nothing calls this directly
no test coverage detected