From 17e89b20418bc290e8b6716e0d35fb1e45dc1dc9 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 24 Sep 2020 20:59:04 +0200 Subject: [PATCH] config: add test_fit_eeprom --- src/config.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 25c8dc8..7773583 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,7 +33,7 @@ impl Config { } } -#[derive(Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize)] pub struct ChannelConfig { center: CenterPoint, pid: pid::Parameters, @@ -53,3 +53,29 @@ impl ChannelConfig { } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_fit_eeprom() { + let channel_config = ChannelConfig { + center: CenterPoint::Override(1.5), + pid: pid::Parameters::default(), + pid_target: 93.7, + sh: steinhart_hart::Parameters::default(), + }; + let config = Config { + channels: [ + channel_config.clone(), + channel_config.clone(), + ], + }; + + const EEPROM_SIZE: usize = 0x80; + let mut buffer = [0; EEPROM_SIZE]; + let buffer = config.encode(&mut buffer).unwrap(); + assert!(buffer.len() <= EEPROM_SIZE); + } +}