summaryrefslogtreecommitdiff
path: root/src/tests/test_procedural.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_procedural.cc')
-rw-r--r--src/tests/test_procedural.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/tests/test_procedural.cc b/src/tests/test_procedural.cc
new file mode 100644
index 0000000..3b82fa0
--- /dev/null
+++ b/src/tests/test_procedural.cc
@@ -0,0 +1,51 @@
+// This file is part of the 64k demo project.
+// It tests the procedural generation system.
+
+#include "procedural/generator.h"
+#include <cassert>
+#include <iostream>
+#include <vector>
+
+void test_noise() {
+ std::cout << "Testing Noise Generator..." << std::endl;
+ int w = 64, h = 64;
+ std::vector<uint8_t> 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<uint8_t> 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;
+}