diff options
Diffstat (limited to 'src/tests/test_procedural.cc')
| -rw-r--r-- | src/tests/test_procedural.cc | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/tests/test_procedural.cc b/src/tests/test_procedural.cc index 0373402..e9f9a02 100644 --- a/src/tests/test_procedural.cc +++ b/src/tests/test_procedural.cc @@ -3,9 +3,9 @@ #include "procedural/generator.h" #include <cassert> +#include <cmath> #include <iostream> #include <vector> -#include <cmath> void test_noise() { std::cout << "Testing Noise Generator..." << std::endl; @@ -17,7 +17,7 @@ void test_noise() { bool res = procedural::gen_noise(buffer.data(), w, h, params, 2); assert(res); assert(buffer[3] == 255); - + // Check that not all pixels are black bool nonzero = false; for (size_t i = 0; i < buffer.size(); i += 4) { @@ -39,7 +39,7 @@ void test_perlin() { std::cout << "Testing Perlin Generator..." << std::endl; int w = 64, h = 64; std::vector<uint8_t> buffer(w * h * 4); - + // Test with explicit params // Params: Seed, Freq, Amp, Decay, Octaves float params[] = {12345, 4.0f, 1.0f, 0.5f, 4.0f}; @@ -63,8 +63,8 @@ void test_perlin() { assert(buffer[3] == 255); // Test memory allocation failure simulation (large dimensions) - // This is hard to robustly test without mocking, but we can try an excessively large allocation if desired. - // For now, we trust the logic path. + // This is hard to robustly test without mocking, but we can try an + // excessively large allocation if desired. For now, we trust the logic path. } void test_grid() { @@ -98,19 +98,19 @@ void test_periodic() { std::vector<uint8_t> buffer(w * h * 4); // Fill with horizontal gradient: left=0, right=255 - for(int y=0; y<h; ++y) { - for(int x=0; x<w; ++x) { - int idx = (y*w + x) * 4; - buffer[idx] = (uint8_t)(x * 255 / (w-1)); - buffer[idx+1] = 0; - buffer[idx+2] = 0; - buffer[idx+3] = 255; + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + int idx = (y * w + x) * 4; + buffer[idx] = (uint8_t)(x * 255 / (w - 1)); + buffer[idx + 1] = 0; + buffer[idx + 2] = 0; + buffer[idx + 3] = 255; } } // Pre-check: edges are different assert(buffer[0] == 0); - assert(buffer[(w-1)*4] == 255); + assert(buffer[(w - 1) * 4] == 255); float params[] = {0.1f}; // Blend ratio 10% bool res = procedural::make_periodic(buffer.data(), w, h, params, 1); @@ -119,10 +119,10 @@ void test_periodic() { // Post-check: Left edge (x=0) should now be blended with right edge. // Logic: blend right edge INTO left edge. At x=0, we copy from right side. // So buffer[0] should be close to 255 (value from right). - assert(buffer[0] > 200); + assert(buffer[0] > 200); // Check invalid ratio - float invalid_params[] = { -1.0f }; + float invalid_params[] = {-1.0f}; res = procedural::make_periodic(buffer.data(), w, h, invalid_params, 1); assert(res); // Should return true but do nothing } |
