| 291 | |
| 292 | #[test] |
| 293 | fn better_ratio_than_lz4() { |
| 294 | // Structured data where Zstd should beat LZ4. |
| 295 | let mut data = Vec::new(); |
| 296 | for i in 0..5000 { |
| 297 | let line = format!( |
| 298 | "{{\"timestamp\":{},\"level\":\"INFO\",\"msg\":\"request handled\",\"duration\":{}}}", |
| 299 | 1700000000 + i, |
| 300 | i % 100 |
| 301 | ); |
| 302 | data.extend_from_slice(line.as_bytes()); |
| 303 | data.push(b'\n'); |
| 304 | } |
| 305 | |
| 306 | let zstd_encoded = encode(&data).unwrap(); |
| 307 | let lz4_encoded = crate::lz4::encode(&data); |
| 308 | |
| 309 | // Zstd should compress better than LZ4. |
| 310 | assert!( |
| 311 | zstd_encoded.len() < lz4_encoded.len(), |
| 312 | "zstd ({}) should be smaller than lz4 ({})", |
| 313 | zstd_encoded.len(), |
| 314 | lz4_encoded.len() |
| 315 | ); |
| 316 | |
| 317 | // Both roundtrip correctly. |
| 318 | assert_eq!(decode(&zstd_encoded).unwrap(), data); |
| 319 | assert_eq!(crate::lz4::decode(&lz4_encoded).unwrap(), data); |
| 320 | } |
| 321 | |
| 322 | #[test] |
| 323 | fn streaming_encoder() { |