|
| 1 | +#[test] |
| 2 | +fn simple_table_collection_creation_with_newtype() { |
| 3 | + // ANCHOR: create_table_collection_with_newtype |
| 4 | + let sequence_length = tskit::Position::from(100.0); |
| 5 | + if let Ok(tables) = tskit::TableCollection::new(sequence_length) { |
| 6 | + assert_eq!(tables.sequence_length(), sequence_length); |
| 7 | + // In tskit, the various newtypes can be compared to |
| 8 | + // the low-level types they wrap. |
| 9 | + assert_eq!(tables.sequence_length(), 100.0); |
| 10 | + } else { |
| 11 | + panic!( |
| 12 | + "TableCollection creation sequence length = {} failed", |
| 13 | + sequence_length |
| 14 | + ); |
| 15 | + } |
| 16 | + // ANCHOR_END: create_table_collection_with_newtype |
| 17 | +} |
| 18 | + |
| 19 | +#[test] |
| 20 | +fn simple_table_collection_creation() { |
| 21 | + // ANCHOR: create_table_collection |
| 22 | + let tables = tskit::TableCollection::new(100.0).unwrap(); |
| 23 | + // ANCHOR_END: create_table_collection |
| 24 | + assert_eq!(tables.sequence_length(), 100.0); |
| 25 | +} |
| 26 | + |
| 27 | +#[test] |
| 28 | +fn add_node_without_metadata() { |
| 29 | + { |
| 30 | + // ANCHOR: add_node_without_metadata |
| 31 | + let mut tables = tskit::TableCollection::new(100.0).unwrap(); |
| 32 | + if let Ok(node_id) = tables.add_node( |
| 33 | + 0, // Node flags |
| 34 | + tskit::Time::from(0.0), // Birth time |
| 35 | + tskit::PopulationId::NULL, // Population id |
| 36 | + tskit::IndividualId::NULL, // Individual id |
| 37 | + ) { |
| 38 | + assert_eq!(node_id, 0); |
| 39 | + } |
| 40 | + // ANCHOR_END: add_node_without_metadata |
| 41 | + } |
| 42 | + { |
| 43 | + let mut tables = tskit::TableCollection::new(100.0).unwrap(); |
| 44 | + // ANCHOR: add_node_without_metadata_using_into |
| 45 | + let node_id = tables.add_node(0, 0.0, -1, -1).unwrap(); |
| 46 | + // ANCHOR_END: add_node_without_metadata_using_into |
| 47 | + assert_eq!(node_id, 0); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +#[test] |
| 52 | +fn add_node_handle_error() { |
| 53 | + // ANCHOR: integrity_check |
| 54 | + let mut tables = tskit::TableCollection::new(100.0).unwrap(); |
| 55 | + // Everything about this edge is wrong... |
| 56 | + tables.add_edge(-1.0, 110.0, 0, 1).unwrap(); |
| 57 | + // ...and we can catch that here |
| 58 | + match tables.check_integrity(tskit::TableIntegrityCheckFlags::default()) { |
| 59 | + Ok(code) => panic!("expected Err(e) but got code: {}", code), |
| 60 | + // tskit::TskitError can be formatted into the same |
| 61 | + // error messages that tskit-c/tskit-python give. |
| 62 | + Err(e) => println!("{}", e), |
| 63 | + } |
| 64 | + // ANCHOR_END: integrity_check |
| 65 | + assert!(tables |
| 66 | + .check_integrity(tskit::TableIntegrityCheckFlags::default()) |
| 67 | + .is_err()); |
| 68 | +} |
0 commit comments