Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/sys/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ pub struct TableCollection(TskBox<tsk_table_collection_t>);

impl TableCollection {
pub fn new(sequence_length: f64) -> Result<Self, TskitError> {
if !sequence_length.is_finite() || sequence_length <= 0.0 {
return Err(TskitError::ValueError {
got: sequence_length.to_string(),
expected: "sequence_length >= 0.0".to_string(),
});
}
let mut tsk = TskBox::new(|tc: *mut tsk_table_collection_t| unsafe {
tsk_table_collection_init(tc, 0)
})?;
Expand Down Expand Up @@ -114,3 +120,18 @@ impl TableCollection {
self.0.into_raw()
}
}

#[test]
fn test_nan_sequence_length() {
assert!(TableCollection::new(f64::NAN).is_err())
}

#[test]
fn test_inf_sequence_length() {
assert!(TableCollection::new(f64::INFINITY).is_err())
}

#[test]
fn test_neg_inf_sequence_length() {
assert!(TableCollection::new(f64::NEG_INFINITY).is_err())
}
9 changes: 1 addition & 8 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ impl TableCollection {
/// let tables = tskit::TableCollection::new(-55.0).unwrap();
/// ```
pub fn new<P: Into<Position>>(sequence_length: P) -> Result<Self, TskitError> {
let sequence_length = sequence_length.into();
if sequence_length <= 0. {
return Err(TskitError::ValueError {
got: f64::from(sequence_length).to_string(),
expected: "sequence_length >= 0.0".to_string(),
});
}
let mut inner = LLTableCollection::new(sequence_length.into())?;
let mut inner = LLTableCollection::new(sequence_length.into().into())?;
let views = crate::table_views::TableViews::new_from_ll_table_collection(&mut inner)?;
Ok(Self {
inner,
Expand Down
Loading