Something went wrong. Try again.
YAML-based live configuration of MicroFreak datyoma.tngl.io/mfctl
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465use super::*;
#[test]fn percentages_have_known_endpoints_and_preserve_every_unsigned_register() { for (value, raw) in [(0.0, 0), (50.0, 16384), (100.0, 32767)] { assert_eq!(Percent(value).encode(), StoredValue(raw)); } for raw in 0..=32767 { assert_eq!( Percent::decode(StoredValue(raw)).unwrap().encode(), StoredValue(raw) ); } assert!(Percent::decode(StoredValue(32768)).is_err());}
#[test]fn bipolar_values_use_signed_registers_not_offset_binary() { for (value, raw) in [ (-100.0, 0x8000), (-50.0, 0xc000), (0.0, 0), (50.0, 0x4000), (100.0, 0x7fff), ] { assert_eq!(Bipolar(value).encode(), StoredValue(raw)); assert_eq!(Bipolar::decode(StoredValue(raw)).unwrap().0, value); } for raw in 0..=u16::MAX { assert_eq!( Bipolar::decode(StoredValue(raw)).unwrap().encode(), StoredValue(raw) ); }}
macro_rules! check_integer_controls { ($($name:ident: $min:expr => $max:expr),+ $(,)?) => {$({ for value in $min..=$max { let control = $name(value); assert!(control.validate().is_ok()); assert_eq!($name::decode(control.encode()).unwrap(), control); } assert!($name::decode(StoredValue(32768)).is_err()); })+}; }
macro_rules! check_time_control { ($name:ident, $times:expr) => { for (index, time) in $times.into_iter().enumerate() { assert_eq!($name(time).encode(), StoredValue(index as u16 * 3640)); assert_eq!( $name::decode(StoredValue(index as u16 * 3640)).unwrap().0, time ); } for raw in 32760..=32767 { assert_eq!($name::decode(StoredValue(raw)).unwrap().0, $times[9]); } assert!($name::decode(StoredValue(32768)).is_err()); };}
pub(crate) use {check_integer_controls, check_time_control};