| 342 | |
| 343 | #[test] |
| 344 | fn compressible_log_data() { |
| 345 | // Highly repetitive log lines. |
| 346 | let line = "2024-01-15 ERROR database connection timeout host=db-prod-01 retry=3\n"; |
| 347 | let data: Vec<u8> = line.as_bytes().repeat(500); |
| 348 | let encoded = encode(&data); |
| 349 | let decoded = decode(&encoded).unwrap(); |
| 350 | assert_eq!(decoded, data); |
| 351 | |
| 352 | let ratio = data.len() as f64 / encoded.len() as f64; |
| 353 | assert!( |
| 354 | ratio > 3.0, |
| 355 | "highly repetitive logs should compress >3x, got {ratio:.1}x" |
| 356 | ); |
| 357 | } |
| 358 | |
| 359 | #[test] |
| 360 | fn incompressible_data() { |