From 93581fadb2ead777bec711e381925b5efe627529 Mon Sep 17 00:00:00 2001 From: molpopgen Date: Wed, 15 Dec 2021 14:49:54 -0800 Subject: [PATCH 1/3] Add Time, Position, Location to prelude. * Closes #209 --- src/prelude.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/prelude.rs b/src/prelude.rs index 74d9543fe..16159a826 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -8,6 +8,7 @@ pub use crate::TSK_NODE_IS_SAMPLE; pub use streaming_iterator::DoubleEndedStreamingIterator; pub use streaming_iterator::StreamingIterator; pub use { - crate::EdgeId, crate::IndividualId, crate::MigrationId, crate::MutationId, crate::NodeId, - crate::PopulationId, crate::SiteId, crate::SizeType, + crate::EdgeId, crate::IndividualId, crate::Location, crate::MigrationId, crate::MutationId, + crate::NodeId, crate::PopulationId, crate::Position, crate::SiteId, crate::SizeType, + crate::Time, }; From 724ba341b7270079f73b309b66cc7fc08691b113 Mon Sep 17 00:00:00 2001 From: molpopgen Date: Wed, 15 Dec 2021 15:08:13 -0800 Subject: [PATCH 2/3] Fix Display for f64-based newtypes --- src/_macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_macros.rs b/src/_macros.rs index f663e7fd0..e9db58982 100644 --- a/src/_macros.rs +++ b/src/_macros.rs @@ -368,7 +368,7 @@ macro_rules! impl_f64_newtypes { ($type: ty) => { impl std::fmt::Display for $type { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}({})", stringify!($idtype), self.0) + write!(f, "{}({})", stringify!($type), self.0) } } From b8103be43e34abf8346c75fc30bab9dc0653401f Mon Sep 17 00:00:00 2001 From: molpopgen Date: Wed, 15 Dec 2021 15:30:14 -0800 Subject: [PATCH 3/3] Add tests of Time/Position/Location Display * Closes #208 --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 03010cb2a..01d2a0fc0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -486,11 +486,33 @@ pub fn c_api_version() -> String { #[cfg(test)] mod tests { use super::c_api_version; + use super::Location; + use super::Position; + use super::Time; #[test] fn test_c_api_version() { let _ = c_api_version(); } + + #[test] + fn test_f64_newtype_Display() { + let x = Position::from(1.0); + let mut output = String::new(); + std::fmt::write(&mut output, format_args!("{}", x)) + .expect("Error occurred while trying to write in String"); + assert_eq!(output, "Position(1)".to_string()); + let x = Time::from(1.0); + let mut output = String::new(); + std::fmt::write(&mut output, format_args!("{}", x)) + .expect("Error occurred while trying to write in String"); + assert_eq!(output, "Time(1)".to_string()); + let x = Location::from(1.0); + let mut output = String::new(); + std::fmt::write(&mut output, format_args!("{}", x)) + .expect("Error occurred while trying to write in String"); + assert_eq!(output, "Location(1)".to_string()); + } } // Testing modules