| 287 | |
| 288 | #[test] |
| 289 | fn compression_ratio() { |
| 290 | let values: Vec<f64> = (1..10_000) |
| 291 | .map(|i| std::f64::consts::E * i as f64 + (i as f64).sqrt()) |
| 292 | .collect(); |
| 293 | let encoded = encode(&values).unwrap(); |
| 294 | let raw_size = values.len() * 8; |
| 295 | let ratio = raw_size as f64 / encoded.len() as f64; |
| 296 | // ALP-RD saves depend on front-bit dictionary size. |
| 297 | // For data with many unique exponents, savings may be minimal. |
| 298 | // The key test is lossless roundtrip, not compression ratio. |
| 299 | assert!( |
| 300 | ratio >= 0.95, |
| 301 | "ALP-RD should not expand >5%, got {ratio:.2}x" |
| 302 | ); |
| 303 | |
| 304 | let decoded = decode(&encoded).unwrap(); |
| 305 | for (a, b) in values.iter().zip(decoded.iter()) { |
| 306 | assert_eq!(a.to_bits(), b.to_bits()); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | #[test] |
| 311 | fn special_values() { |