add AreaMap2D tests
This commit is contained in:
parent
6fdea11e2e
commit
ab110ab8bf
@ -104,9 +104,12 @@ namespace util {
|
||||
return false;
|
||||
}
|
||||
auto& element = firstBuffer[ly * sizeX + lx];
|
||||
if (!element) {
|
||||
if (value && !element) {
|
||||
valuesCount++;
|
||||
}
|
||||
if (element && !value) {
|
||||
valuesCount--;
|
||||
}
|
||||
element = std::move(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1,7 +1,78 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <atomic>
|
||||
|
||||
#include "util/AreaMap2D.hpp"
|
||||
|
||||
TEST(AreaMap2D, BaseTest) {
|
||||
util::AreaMap2D<int> window({6, 6});
|
||||
util::AreaMap2D<int> window({7, 5});
|
||||
window.setCenter(0, 0);
|
||||
{
|
||||
int i = 1;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -3; x <= 3; x++, i++) {
|
||||
window.set(x, y, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(window.count(), 7 * 5);
|
||||
{
|
||||
int i = 1;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -3; x <= 3; x++, i++) {
|
||||
EXPECT_EQ(window.require(x, y), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
window.set(0, 0, 0);
|
||||
EXPECT_EQ(window.count(), 7 * 5 - 1);
|
||||
}
|
||||
|
||||
|
||||
TEST(AreaMap2D, ResizeTest) {
|
||||
util::AreaMap2D<int> window({7, 5});
|
||||
window.setCenter(0, 0);
|
||||
{
|
||||
int i = 1;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -3; x <= 3; x++, i++) {
|
||||
window.set(x, y, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(window.count(), 7 * 5);
|
||||
window.resize(9, 7);
|
||||
window.setCenter(0, 0);
|
||||
EXPECT_EQ(window.count(), 7 * 5);
|
||||
window.resize(7, 5);
|
||||
|
||||
EXPECT_EQ(window.count(), 7 * 5);
|
||||
{
|
||||
int i = 1;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -3; x <= 3; x++, i++) {
|
||||
EXPECT_EQ(window.require(x, y), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AreaMap2D, TranslateWithOut) {
|
||||
util::AreaMap2D<int> window({7, 5});
|
||||
window.setCenter(0, 0);
|
||||
{
|
||||
int i = 1;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -3; x <= 3; x++, i++) {
|
||||
window.set(x, y, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::atomic_int outside = 0;
|
||||
window.setOutCallback([&outside](auto, auto, auto) {
|
||||
outside++;
|
||||
});
|
||||
window.setCenter(-2, -1);
|
||||
EXPECT_EQ(window.require(-3, -2), 1);
|
||||
EXPECT_EQ(outside, 15);
|
||||
EXPECT_EQ(window.count(), 20);
|
||||
}
|
||||
|
||||
@ -5,22 +5,28 @@
|
||||
|
||||
TEST(SurroundMap, InitTest) {
|
||||
int maxLevelZone = 50;
|
||||
int x = 20;
|
||||
int y = 30;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int8_t maxLevel = 5;
|
||||
std::atomic_int affected = 0;
|
||||
|
||||
SurroundMap map(maxLevelZone, maxLevel);
|
||||
std::atomic_int affected = 0;
|
||||
|
||||
map.setLevelCallback(1, [&affected](auto, auto) {
|
||||
affected++;
|
||||
});
|
||||
map.setCenter(0, 0);
|
||||
map.completeAt(x, y);
|
||||
EXPECT_EQ(affected, (maxLevel * 2 - 1)*(maxLevel * 2 - 1));
|
||||
EXPECT_EQ(affected, (maxLevel * 2 - 1) * (maxLevel * 2 - 1));
|
||||
|
||||
for (int ly = -maxLevel+1; ly < maxLevel; ly++) {
|
||||
for (int lx = -maxLevel+1; lx < maxLevel; lx++) {
|
||||
int levelExpected = maxLevel-std::max(std::abs(lx), std::abs(ly));
|
||||
EXPECT_EQ(map.at(x+lx, y+ly), levelExpected);
|
||||
for (int ly = -maxLevel + 1; ly < maxLevel; ly++) {
|
||||
for (int lx = -maxLevel + 1; lx < maxLevel; lx++) {
|
||||
int levelExpected = maxLevel - std::max(std::abs(lx), std::abs(ly));
|
||||
EXPECT_EQ(map.at(x + lx, y + ly), levelExpected);
|
||||
}
|
||||
}
|
||||
|
||||
affected = 0;
|
||||
map.completeAt(x - 1, y);
|
||||
EXPECT_EQ(affected, maxLevel * 2 - 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user