| 398 | |
| 399 | #[test] |
| 400 | fn monotonic_with_jitter() { |
| 401 | let mut values = Vec::with_capacity(10_000); |
| 402 | let mut ts = 1_700_000_000_000i64; |
| 403 | let mut rng: u64 = 42; |
| 404 | for _ in 0..10_000 { |
| 405 | values.push(ts); |
| 406 | rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1); |
| 407 | let jitter = ((rng >> 33) as i64 % 101) - 50; |
| 408 | ts += 10_000 + jitter; |
| 409 | } |
| 410 | let encoded = encode(&values); |
| 411 | let decoded = decode(&encoded).unwrap(); |
| 412 | assert_eq!(decoded, values); |
| 413 | |
| 414 | let bytes_per_sample = encoded.len() as f64 / values.len() as f64; |
| 415 | assert!( |
| 416 | bytes_per_sample < 2.0, |
| 417 | "jittered timestamps should compress to <2 bytes/sample, got {bytes_per_sample:.2}" |
| 418 | ); |
| 419 | } |
| 420 | |
| 421 | #[test] |
| 422 | fn non_monotonic_values() { |