| 419 | |
| 420 | #[test] |
| 421 | fn better_than_raw_on_structured() { |
| 422 | // Structured data after type-aware preprocessing (typical pipeline output). |
| 423 | let mut data = Vec::with_capacity(10_000); |
| 424 | for i in 0..10_000 { |
| 425 | data.push((i % 16) as u8); // Low entropy, 4 bits/byte → 2x compression. |
| 426 | } |
| 427 | let encoded = encode(&data); |
| 428 | let decoded = decode(&encoded).unwrap(); |
| 429 | assert_eq!(decoded, data); |
| 430 | |
| 431 | let ratio = data.len() as f64 / encoded.len() as f64; |
| 432 | assert!( |
| 433 | ratio > 1.5, |
| 434 | "low-entropy data should compress >1.5x, got {ratio:.1}x" |
| 435 | ); |
| 436 | } |
| 437 | |
| 438 | #[test] |
| 439 | fn truncated_input_errors() { |