1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}
|