added additional tests
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-01-22 12:53:39 +01:00
parent e081504b33
commit c59b015a20
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 19 additions and 2 deletions

View File

@ -996,7 +996,11 @@ fn add_for_max_ccsds_days_val<T: ProvidesDaysLength>(
_ => None,
}
} else {
increment_ms_of_day(&mut next_ms_of_day, duration.subsec_millis(), &mut next_ccsds_days);
increment_ms_of_day(
&mut next_ms_of_day,
duration.subsec_millis(),
&mut next_ccsds_days,
);
None
};
// The subsecond millisecond were already handled.

View File

@ -382,7 +382,12 @@ fn get_new_stamp_after_addition(
new_subsec_millis -= 1000;
increment_seconds(1);
}
increment_seconds(duration.as_secs().try_into().expect("duration seconds exceeds u32::MAX"));
increment_seconds(
duration
.as_secs()
.try_into()
.expect("duration seconds exceeds u32::MAX"),
);
UnixTimestamp::const_new(new_unix_seconds, new_subsec_millis)
}
@ -534,6 +539,14 @@ mod tests {
assert_eq!(stamp1.subsecond_millis().unwrap(), 500);
}
#[test]
fn test_addition_on_ref() {
let stamp0 = &UnixTimestamp::new(20, 500).unwrap();
let stamp1 = stamp0 + Duration::from_millis(2500);
assert_eq!(stamp1.unix_seconds, 23);
assert!(stamp1.subsecond_millis().is_none());
}
#[test]
fn test_addition_spillover() {
let mut stamp0 = UnixTimestamp::new(1, 900).unwrap();