MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / temperature_readings

Function temperature_readings

nodedb-codec/src/alp.rs:482–497  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 5

roundMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected