From c29e61b4b7c68f867851f7fe3ac0f1542e5512da Mon Sep 17 00:00:00 2001 From: molpopgen Date: Thu, 2 Jun 2022 07:49:13 -0700 Subject: [PATCH] Add new_sample and is_sample to NodeFlags public API. --- src/flags.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/flags.rs b/src/flags.rs index 78ceecb1f..02756eaa5 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -251,12 +251,23 @@ impl From for IndividualFlags { } impl NodeFlags { + /// Create a new flags instance with `IS_SAMPLE` set. + pub fn new_sample() -> Self { + Self::IS_SAMPLE + } + /// We do not enforce valid flags in the library. /// This function will return `true` if any bits /// are set that do not correspond to allowed flags. pub fn is_valid(&self) -> bool { true } + + /// Returns `true` if flags contains `IS_SAMPLE`, + /// and `false` otherwise. + pub fn is_sample(&self) -> bool { + self.contains(NodeFlags::IS_SAMPLE) + } } impl IndividualFlags { @@ -267,3 +278,20 @@ impl IndividualFlags { true } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn node_is_not_sample() { + let n = NodeFlags::default(); + assert!(!n.is_sample()); + } + + #[test] + fn node_is_sample() { + let n = NodeFlags::new_sample(); + assert!(n.is_sample()); + } +}