// This file is part of the 64k demo project. // It tests the procedural generation system. #include "procedural/generator.h" #include #include #include void test_noise() { std::cout << "Testing Noise Generator..." << std::endl; int w = 64, h = 64; std::vector buffer(w * h * 4); float params[] = {12345, 1.0f}; // Seed, Intensity procedural::gen_noise(buffer.data(), w, h, params, 2); // Check simple properties: alpha should be 255 assert(buffer[3] == 255); // Check that not all pixels are black (very unlikely with noise) bool nonzero = false; for (size_t i = 0; i < buffer.size(); i += 4) { if (buffer[i] > 0) { nonzero = true; break; } } assert(nonzero); } void test_grid() { std::cout << "Testing Grid Generator..." << std::endl; int w = 100, h = 100; std::vector buffer(w * h * 4); float params[] = {10, 1}; // Size 10, Thickness 1 procedural::gen_grid(buffer.data(), w, h, params, 2); // Pixel (0,0) should be white (on line) assert(buffer[0] == 255); // Pixel (5,5) should be black (off line, since size=10) assert(buffer[(5 * w + 5) * 4] == 0); // Pixel (10,0) should be white (on vertical line) assert(buffer[(0 * w + 10) * 4] == 255); } int main() { test_noise(); test_grid(); std::cout << "--- PROCEDURAL TESTS PASSED ---" << std::endl; return 0; }