summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2019-03-30 13:07:52 +0200
committerDiego Barrios Romero <eldruin@gmail.com>2019-03-31 13:41:26 +0200
commit3cb312f7daa59715497a93ba2888a958fc5cdc4e (patch)
tree90e6f41f50fddbff2f4ecd7289569192111c3ee1
parente6c1725b6a3419d5a28542d79bde271d0d5ef6f6 (diff)
downloadads1x1x-async-3cb312f7daa59715497a93ba2888a958fc5cdc4e.tar.gz
ads1x1x-async-3cb312f7daa59715497a93ba2888a958fc5cdc4e.tar.xz
ads1x1x-async-3cb312f7daa59715497a93ba2888a958fc5cdc4e.zip
Extract function
-rw-r--r--src/conversion.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/conversion.rs b/src/conversion.rs
index 644ed4a..fef80ac 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -83,19 +83,23 @@ mod tests {
assert_invalid_input_data::<()>(Ok(0));
}
+ fn convert_threshold<T: ConvertThreshold<()>>(value: i16) -> u16 {
+ T::convert_threshold(value).unwrap()
+ }
+
#[test]
fn convert_threshold_12_bits() {
assert_invalid_input_data::<()>(ic::Resolution12Bit::convert_threshold(2048));
assert_invalid_input_data::<()>(ic::Resolution12Bit::convert_threshold(-2049));
- assert_eq!( 0, <ic::Resolution12Bit as ConvertThreshold<()>>::convert_threshold(0).unwrap());
- assert_eq!(0x7FF0, <ic::Resolution12Bit as ConvertThreshold<()>>::convert_threshold(2047).unwrap());
- assert_eq!(0x8000, <ic::Resolution12Bit as ConvertThreshold<()>>::convert_threshold(-2048).unwrap());
- assert_eq!(0xFFF0, <ic::Resolution12Bit as ConvertThreshold<()>>::convert_threshold(-1).unwrap());
+ assert_eq!(0, convert_threshold::<ic::Resolution12Bit>(0));
+ assert_eq!(0x7FF0, convert_threshold::<ic::Resolution12Bit>(2047));
+ assert_eq!(0x8000, convert_threshold::<ic::Resolution12Bit>(-2048));
+ assert_eq!(0xFFF0, convert_threshold::<ic::Resolution12Bit>(-1));
}
#[test]
fn convert_threshold_16_bits() {
- assert_eq!(0x7FFF, <ic::Resolution16Bit as ConvertThreshold<()>>::convert_threshold(32767).unwrap());
- assert_eq!(0x8000, <ic::Resolution16Bit as ConvertThreshold<()>>::convert_threshold(-32768).unwrap());
+ assert_eq!(0x7FFF, convert_threshold::<ic::Resolution16Bit>(32767));
+ assert_eq!(0x8000, convert_threshold::<ic::Resolution16Bit>(-32768));
}
}