From 8bc86b228f245e1056a79a7f7d6d97641f1bb745 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 8 Nov 2018 18:59:02 +0100 Subject: Add unit tests for measurement conversion --- src/devices/ads1x1x/mode/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/devices/ads1x1x/mode/mod.rs b/src/devices/ads1x1x/mode/mod.rs index 1a01d27..81a5795 100644 --- a/src/devices/ads1x1x/mode/mod.rs +++ b/src/devices/ads1x1x/mode/mod.rs @@ -24,3 +24,24 @@ where mod oneshot; mod continuous; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn convert_12_bits() { + assert_eq!( 0, convert_measurement::(0)); + assert_eq!( 2047, convert_measurement::(0x7FFF)); + assert_eq!(-2048, convert_measurement::(0x8000)); + assert_eq!( -1, convert_measurement::(0xFFFF)); + } + + #[test] + fn convert_16_bits() { + assert_eq!( 0, convert_measurement::(0)); + assert_eq!( 32767, convert_measurement::(0x7FFF)); + assert_eq!(-32768, convert_measurement::(0x8000)); + assert_eq!( -1, convert_measurement::(0xFFFF)); + } +} -- cgit v1.2.3-54-g00ecf