| 480 | |
| 481 | #[test] |
| 482 | fn temperature_readings() { |
| 483 | // Temperatures: -40.0 to 50.0 with 0.01 resolution. |
| 484 | let mut values = Vec::with_capacity(10_000); |
| 485 | let mut rng: u64 = 99; |
| 486 | for _ in 0..10_000 { |
| 487 | rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1); |
| 488 | let temp = ((rng >> 33) as f64 / (u32::MAX as f64)) * 90.0 - 40.0; |
| 489 | let temp = (temp * 100.0).round() / 100.0; |
| 490 | values.push(temp); |
| 491 | } |
| 492 | let encoded = encode(&values); |
| 493 | let decoded = decode(&encoded).unwrap(); |
| 494 | for (i, (a, b)) in values.iter().zip(decoded.iter()).enumerate() { |
| 495 | assert_eq!(a.to_bits(), b.to_bits(), "mismatch at {i}: {a} vs {b}"); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | #[test] |
| 500 | fn exception_handling() { |