oxigdal-wasm 0.1.4

WebAssembly bindings for OxiGDAL - Browser-based geospatial processing
Documentation
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

/// Performance and stress tests
#[cfg(test)]
mod stress_tests {
    use crate::*;
    /// Stress tests for cache
    mod cache_stress {
        use super::*;
        #[test]
        fn stress_many_tiles() {
            let mut cache = TileCache::new(1_000_000);
            for level in 0..10 {
                for x in 0..100 {
                    for y in 0..10 {
                        let coord = TileCoord::new(level, x, y);
                        let data = vec![0u8; 256 * 256 * 4];
                        let _ = cache.put(coord, data, (level * 1000 + x * 10 + y) as f64);
                    }
                }
            }
            let stats = cache.stats();
            assert!(stats.entry_count > 0);
        }
        #[test]
        fn stress_rapid_access() {
            let mut cache = TileCache::new(100000);
            let coord = TileCoord::new(0, 0, 0);
            cache.put(coord, vec![1u8; 1000], 0.0).expect("Put");
            for i in 0..1_000 {
                cache.get(&coord, i as f64);
            }
            let stats = cache.stats();
            assert_eq!(stats.hit_count, 1_000);
        }
        #[test]
        fn stress_eviction_thrashing() {
            let mut cache = TileCache::new(1000);
            for iteration in 0..100 {
                for i in 0..50 {
                    let coord = TileCoord::new(0, iteration * 50 + i, 0);
                    let _ = cache.put(coord, vec![0u8; 50], (iteration * 50 + i) as f64);
                }
            }
            let stats = cache.stats();
            assert!(stats.current_size <= 1000);
        }
    }
    /// Stress tests for pyramid
    mod pyramid_stress {
        use super::*;
        #[test]
        fn stress_large_pyramid() {
            let pyramid = TilePyramid::new(1_000_000, 1_000_000, 256, 256);
            let total = pyramid.total_tiles();
            assert!(total > 0);
            for level in 0..5 {
                for x in 0..100 {
                    for y in 0..100 {
                        let coord = TileCoord::new(level, x, y);
                        let _ = pyramid.is_valid_coord(&coord);
                    }
                }
            }
        }
        #[test]
        fn stress_deep_hierarchy() {
            let pyramid = TilePyramid::new(1_048_576, 1_048_576, 256, 256);
            // In this pyramid, level 0 = full resolution (4096x4096 tiles),
            // higher levels = progressively downsampled (fewer tiles).
            // parent() goes from level N to level N-1 (more tiles), dividing x,y by 2.
            // Start at a mid-level with a coordinate that is valid and whose
            // entire parent chain down to level 0 is also valid.
            //
            // Level 11 has 2x2 tiles, so (11, 1, 1) is valid.
            // parent chain: (10,0,0) -> (9,0,0) -> ... -> (0,0,0) -- all valid.
            let mut coord = TileCoord::new(11, 1, 1);
            assert!(pyramid.is_valid_coord(&coord));
            let mut depth = 0u32;
            while let Some(parent) = coord.parent() {
                assert!(pyramid.is_valid_coord(&parent));
                coord = parent;
                depth += 1;
            }
            // Verify we actually traversed 11 levels (level 11 down to level 0)
            assert_eq!(depth, 11);

            // Also stress-test the forward direction: walk from the root level
            // (highest index, fewest tiles) down to full resolution via children,
            // validating coordinates at each step.
            let max_level = pyramid.num_levels - 1;
            let mut coords = vec![TileCoord::new(max_level, 0, 0)];
            assert!(pyramid.is_valid_coord(&coords[0]));
            for level in (0..max_level).rev() {
                let mut next_coords = Vec::new();
                for c in &coords {
                    for child in c.children() {
                        if child.level == level && pyramid.is_valid_coord(&child) {
                            next_coords.push(child);
                        }
                    }
                }
                if next_coords.is_empty() {
                    break;
                }
                // Limit to avoid exponential blowup; just keep a bounded sample
                next_coords.truncate(16);
                coords = next_coords;
            }
        }
    }
    /// Stress tests for image processing
    mod image_processing_stress {
        use super::*;
        #[test]
        fn stress_large_image() {
            let size = 4096 * 4096 * 4;
            let mut data = vec![128u8; size];
            ImageProcessor::adjust_brightness(&mut data, 20);
            ImageProcessor::adjust_contrast(&mut data, 1.2);
            ImageProcessor::invert(&mut data);
        }
        #[test]
        fn stress_many_histograms() {
            let data = vec![128u8; 1024 * 1024 * 4];
            for _ in 0..1000 {
                let _ = Histogram::from_rgba(&data, 1024, 1024);
            }
        }
        #[test]
        fn stress_color_conversions() {
            for r in (0..=255).step_by(5) {
                for g in (0..=255).step_by(5) {
                    for b in (0..=255).step_by(5) {
                        let rgb = Rgb::new(r, g, b);
                        let hsv = rgb.to_hsv();
                        let ycbcr = rgb.to_ycbcr();
                        let _ = hsv.to_rgb();
                        let _ = ycbcr.to_rgb();
                    }
                }
            }
        }
    }
    /// Stress tests for profiler
    mod profiler_stress {
        use super::*;
        #[test]
        fn stress_many_counters() {
            let mut profiler = Profiler::new();
            for i in 0..10_000 {
                let name = format!("counter_{}", i);
                profiler.record(&name, i as f64);
            }
            let summary = profiler.summary();
            assert_eq!(summary.counters.len(), 10_000);
        }
        #[test]
        fn stress_many_records_per_counter() {
            let mut profiler = Profiler::new();
            for i in 0..1_000 {
                profiler.record("test", (i % 100) as f64);
            }
            let stats = profiler.counter_stats("test").expect("Stats");
            assert_eq!(stats.count, 1_000);
        }
        #[test]
        fn stress_timer_operations() {
            let mut profiler = Profiler::new();
            for i in 0..10_000 {
                let name = format!("timer_{}", i);
                profiler.start_timer(&name, i as f64);
                profiler.stop_timer(&name, (i + 1) as f64);
            }
            let summary = profiler.summary();
            assert_eq!(summary.counters.len(), 10_000);
        }
    }
    /// Stress tests for viewport
    mod viewport_stress {
        use super::*;
        #[test]
        fn stress_many_transforms() {
            let mut state = ViewportState::new(1920, 1080);
            for i in 0..10_000 {
                if i % 2 == 0 {
                    state.pan((i % 100) as f64, (i % 50) as f64);
                } else {
                    state.zoom(1.0 + (i % 10) as f64 / 10.0, 960.0, 540.0);
                }
            }
            assert!(state.transform.sx > 0.0);
        }
        #[test]
        fn stress_history_operations() {
            let mut history = ViewportHistory::new(1000);
            for i in 0..10_000 {
                let mut state = ViewportState::new(800, 600);
                state.pan(i as f64, 0.0);
                history.push(state);
            }
            assert!(history.current_index() <= 1000);
            for _ in 0..500 {
                if history.can_undo() {
                    history.undo();
                }
            }
            for _ in 0..250 {
                if history.can_redo() {
                    history.redo();
                }
            }
        }
    }
    /// Stress tests for compression
    mod compression_stress {
        use super::*;
        #[test]
        fn stress_large_data_compression() {
            let data = vec![42u8; 1_000_000];
            let compressed = RleCompressor::compress(&data);
            let decompressed = RleCompressor::decompress(&compressed).expect("Decompress");
            assert_eq!(data, decompressed);
        }
        #[test]
        fn stress_many_compressions() {
            let data = vec![1, 2, 3, 4, 5];
            for _ in 0..10_000 {
                let _ = RleCompressor::compress(&data);
                let _ = DeltaCompressor::compress(&data);
            }
        }
        #[test]
        fn stress_random_like_data() {
            let data: Vec<u8> = (0..10_000).map(|i| ((i * 7919) % 256) as u8).collect();
            let rle = RleCompressor::compress(&data);
            let delta = DeltaCompressor::compress(&data);
            let huffman = HuffmanCompressor::compress(&data);
            assert!(!rle.is_empty());
            assert!(!delta.is_empty());
            assert!(!huffman.is_empty());
        }
    }
    /// Stress tests for streaming
    mod streaming_stress {
        use super::*;
        #[test]
        fn stress_bandwidth_estimation() {
            let mut estimator = BandwidthEstimator::new();
            for i in 0..1_000 {
                let size = 1000 + (i % 10000);
                let duration = 0.1 + (i % 100) as f64 / 1000.0;
                estimator.record_download(size, duration);
            }
            let bandwidth = estimator.estimate();
            assert!(bandwidth > 0.0);
        }
        #[test]
        fn stress_quality_adaptation() {
            let mut adapter = QualityAdapter::new();
            for i in 0..1_000 {
                let bw = 100_000.0 + (i % 10_000_000) as f64;
                adapter.update_bandwidth(bw, i as f64);
                let _ = adapter.current_quality();
            }
        }
        #[test]
        fn stress_prefetch_scheduling() {
            let scheduler = PrefetchScheduler::new(100);
            for i in 0..1000 {
                let viewport = Viewport::new(i as f64 * 100.0, i as f64 * 100.0, 0, 1000, 1000);
                let _ = scheduler.schedule_prefetch(&viewport, i % 10);
            }
        }
    }
    /// Stress tests for buffer operations
    mod buffer_stress {
        use super::*;
        #[test]
        fn stress_many_composites() {
            let mut buffer = CanvasBuffer::new(1024, 1024).expect("Buffer");
            let tile = vec![128u8; 256 * 256 * 4];
            for i in 0..10 {
                for j in 0..10 {
                    let _ = buffer.composite_tile(&tile, 256, 256, i * 80, j * 80, 0.5);
                }
            }
        }
        #[test]
        fn stress_many_resizes() {
            let mut buffer = CanvasBuffer::new(256, 256).expect("Buffer");
            for i in 0..1000 {
                let size = 256 + (i % 512);
                let _ = buffer.resize(size, size);
            }
        }
        #[test]
        fn stress_clear_operations() {
            let mut buffer = CanvasBuffer::new(1024, 1024).expect("Buffer");
            for i in 0..10_000 {
                let color = (i % 256) as u8;
                buffer.clear_with_color(color, color, color, 255);
            }
        }
    }
}