1bc321f8-04e6-42d0-9bdf-fccf5c18b5b8
This commit is contained in:
@@ -1,4 +1,125 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "nd-wfc/wfc.hpp"
|
||||
#include "nd-wfc/worlds.hpp"
|
||||
|
||||
// Test world for demonstration
|
||||
struct TestWorld {
|
||||
using ValueType = int;
|
||||
std::vector<int> data;
|
||||
|
||||
TestWorld(size_t size) : data(size, 0) {}
|
||||
size_t size() const { return data.size(); }
|
||||
void setValue(size_t id, int value) { data[id] = value; }
|
||||
int getValue(size_t id) const { return data[id]; }
|
||||
};
|
||||
|
||||
// Test random selectors
|
||||
TEST(RandomSelectorTest, DefaultRandomSelector) {
|
||||
using namespace WFC;
|
||||
|
||||
// Test default random selector with constexpr capabilities
|
||||
DefaultRandomSelector<int> selector(12345);
|
||||
|
||||
std::array<int, 3> testValues = {1, 2, 3};
|
||||
std::span<const int> span(testValues.data(), testValues.size());
|
||||
|
||||
// Test that selector returns valid indices
|
||||
size_t index1 = selector(span);
|
||||
size_t index2 = selector(span);
|
||||
|
||||
EXPECT_LT(index1, testValues.size());
|
||||
EXPECT_LT(index2, testValues.size());
|
||||
EXPECT_GE(index1, 0);
|
||||
EXPECT_GE(index2, 0);
|
||||
}
|
||||
|
||||
TEST(RandomSelectorTest, AdvancedRandomSelector) {
|
||||
using namespace WFC;
|
||||
|
||||
std::mt19937 rng(54321);
|
||||
AdvancedRandomSelector<int> selector(rng);
|
||||
|
||||
std::array<int, 4> testValues = {10, 20, 30, 40};
|
||||
std::span<const int> span(testValues.data(), testValues.size());
|
||||
|
||||
// Test that selector returns valid indices
|
||||
size_t index = selector(span);
|
||||
EXPECT_LT(index, testValues.size());
|
||||
EXPECT_GE(index, 0);
|
||||
|
||||
// Verify the selected value matches
|
||||
EXPECT_EQ(testValues[index], span[index]);
|
||||
}
|
||||
|
||||
TEST(RandomSelectorTest, CustomLambdaSelector) {
|
||||
using namespace WFC;
|
||||
|
||||
// Custom selector that always picks the first element
|
||||
auto firstSelector = [](std::span<const int> values) -> size_t {
|
||||
return 0;
|
||||
};
|
||||
|
||||
std::array<int, 3> testValues = {100, 200, 300};
|
||||
std::span<const int> span(testValues.data(), testValues.size());
|
||||
|
||||
size_t index = firstSelector(span);
|
||||
EXPECT_EQ(index, 0);
|
||||
EXPECT_EQ(span[index], 100);
|
||||
}
|
||||
|
||||
TEST(RandomSelectorTest, StatefulLambdaSelector) {
|
||||
using namespace WFC;
|
||||
|
||||
// Stateful selector that cycles through options
|
||||
uint32_t callCount = 0;
|
||||
auto cyclingSelector = [&callCount](std::span<const int> values) mutable -> size_t {
|
||||
return callCount++ % values.size();
|
||||
};
|
||||
|
||||
std::array<int, 3> testValues = {1, 2, 3};
|
||||
std::span<const int> span(testValues.data(), testValues.size());
|
||||
|
||||
// Test multiple calls
|
||||
EXPECT_EQ(cyclingSelector(span), 0);
|
||||
EXPECT_EQ(cyclingSelector(span), 1);
|
||||
EXPECT_EQ(cyclingSelector(span), 2);
|
||||
EXPECT_EQ(cyclingSelector(span), 0); // Should cycle back
|
||||
}
|
||||
|
||||
TEST(RandomSelectorTest, WFCIntegration) {
|
||||
using namespace WFC;
|
||||
|
||||
// Create a simple WFC setup with custom random selector
|
||||
using VariableMap = VariableIDMap<int, 0, 1, 2>;
|
||||
using CustomWFC = Builder<TestWorld, int, VariableMap>
|
||||
::SetRandomSelector<DefaultRandomSelector<int>>
|
||||
::Build;
|
||||
|
||||
TestWorld world(4);
|
||||
uint32_t seed = 12345;
|
||||
|
||||
// This should compile and run without errors
|
||||
// (Note: This is a basic integration test - full WFC solving would require proper constraints)
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(RandomSelectorTest, ConstexprDefaultSelector) {
|
||||
using namespace WFC;
|
||||
|
||||
// Test that default selector can be used in constexpr context
|
||||
constexpr DefaultRandomSelector<int> selector(0xDEADBEEF);
|
||||
|
||||
constexpr std::array<int, 2> testValues = {42, 84};
|
||||
constexpr auto span = std::span<const int>(testValues.data(), testValues.size());
|
||||
|
||||
// This should compile in constexpr context
|
||||
constexpr size_t index = selector(span);
|
||||
EXPECT_LT(index, testValues.size());
|
||||
EXPECT_GE(index, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user