devilutionX/test/lighting_test.cpp
Gleb Mazovetskiy 076b0c0c05 Overhaul tests
1. Adds a `libdevilution_so` target when tests are enabled.
2. Each test file is now a separate binary target linked against `libdevilutionx_so` (can now run tests in parallel).
3. Tests are now defined in a separate `test/CMakeLists.txt` file.
4. Building the tests is now controlled by the standard `BUILD_TESTING` option (defined by CTest).
5. Tests are now built by default.
6. On CI, test errors are now reported.

Also:

* `.clang-format`: Enable SortIncludes in tests
* `path_test.cpp`: Fix -Wsign-compare
2021-12-16 20:26:51 +00:00

34 lines
916 B
C++

#include <gtest/gtest.h>
#include "control.h"
#include "lighting.h"
using namespace devilution;
TEST(Lighting, CrawlTables)
{
bool added[40][40];
memset(added, 0, sizeof(added));
for (int j = 0; j < 19; j++) {
int x = 20;
int y = 20;
int cr = CrawlNum[j] + 1;
for (unsigned i = (uint8_t)CrawlTable[cr - 1]; i > 0; i--, cr += 2) {
int dx = x + CrawlTable[cr];
int dy = y + CrawlTable[cr + 1];
EXPECT_EQ(added[dx][dy], false) << "location " << i << ":" << j << " added twice";
added[dx][dy] = true;
}
}
for (int i = -18; i <= 18; i++) {
for (int j = -18; j <= 18; j++) {
if (added[i + 20][j + 20])
continue;
if ((i == -18 && j == -18) || (i == -18 && j == 18) || (i == 18 && j == -18) || (i == 18 && j == 18))
continue; // Limit of the crawl table rage
EXPECT_EQ(false, true) << "while checking location " << i << ":" << j;
}
}
}