From 445cde6ae8a0b4a1ceb1a3b3a238c91e30e58093 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 30 Sep 2020 18:00:37 +0200 Subject: [PATCH] channels: add test report_to_json --- src/channels.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/channels.rs b/src/channels.rs index 4a96130..63a3c0f 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -463,3 +463,31 @@ impl Report { serde_json_core::to_vec(self) } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn report_to_json() { + // `/ 1.1` results in values with a really long serialization + let report = Report { + channel: 0, + time: 3200, + adc: Some(ElectricPotential::new::(0.65 / 1.1)), + sens: Some(ElectricalResistance::new::(10000.0 / 1.1)), + temperature: Some(30.0 / 1.1), + pid_engaged: false, + i_set: ElectricCurrent::new::(0.5 / 1.1), + vref: ElectricPotential::new::(1.5 / 1.1), + dac_feedback: ElectricPotential::new::(2.0 / 1.1), + i_tec: ElectricPotential::new::(2.0 / 1.1), + tec_i: ElectricCurrent::new::(0.2 / 1.1), + tec_u_meas: ElectricPotential::new::(2.0 / 1.1), + pid_output: Some(ElectricCurrent::new::(0.5 / 1.1)), + }; + let buf = report.to_json().unwrap(); + assert_eq!(buf[0], b'{'); + assert_eq!(buf[buf.len() - 1], b'}'); + } +}