diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-08 18:59:02 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-08 18:59:02 +0100 |
commit | 8bc86b228f245e1056a79a7f7d6d97641f1bb745 (patch) | |
tree | 65d74182fa9bf8e0c3c03a050348e149013f83e9 /src | |
parent | 52dcc88c744f34ad928ebeca5f5161f3f55013e2 (diff) | |
download | ads1x1x-async-8bc86b228f245e1056a79a7f7d6d97641f1bb745.tar.gz ads1x1x-async-8bc86b228f245e1056a79a7f7d6d97641f1bb745.tar.xz ads1x1x-async-8bc86b228f245e1056a79a7f7d6d97641f1bb745.zip |
Add unit tests for measurement conversion
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/ads1x1x/mode/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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::<ic::Ads1013>(0)); + assert_eq!( 2047, convert_measurement::<ic::Ads1013>(0x7FFF)); + assert_eq!(-2048, convert_measurement::<ic::Ads1013>(0x8000)); + assert_eq!( -1, convert_measurement::<ic::Ads1013>(0xFFFF)); + } + + #[test] + fn convert_16_bits() { + assert_eq!( 0, convert_measurement::<ic::Ads1113>(0)); + assert_eq!( 32767, convert_measurement::<ic::Ads1113>(0x7FFF)); + assert_eq!(-32768, convert_measurement::<ic::Ads1113>(0x8000)); + assert_eq!( -1, convert_measurement::<ic::Ads1113>(0xFFFF)); + } +} |