Skip to content

Commit 89058e1

Browse files
committed
update tests to use id
1 parent d21e938 commit 89058e1

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

src/table_collection.rs

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,11 @@ mod test {
631631
assert!(row.metadata.is_none());
632632
}
633633

634-
for (i, row) in tables.nodes_iter(true).enumerate() {
635-
assert!(close_enough(
636-
tables.nodes().time(i as tsk_id_t).unwrap(),
637-
row.time
638-
));
639-
assert_eq!(tables.nodes().flags(i as tsk_id_t).unwrap(), row.flags);
640-
assert_eq!(
641-
tables.nodes().population(i as tsk_id_t).unwrap(),
642-
row.population
643-
);
644-
assert_eq!(
645-
tables.nodes().individual(i as tsk_id_t).unwrap(),
646-
row.individual
647-
);
634+
for row in tables.nodes_iter(true) {
635+
assert!(close_enough(tables.nodes().time(row.id).unwrap(), row.time));
636+
assert_eq!(tables.nodes().flags(row.id).unwrap(), row.flags);
637+
assert_eq!(tables.nodes().population(row.id).unwrap(), row.population);
638+
assert_eq!(tables.nodes().individual(row.id).unwrap(), row.individual);
648639
assert!(row.metadata.is_none());
649640
}
650641
}
@@ -665,17 +656,14 @@ mod test {
665656
assert_eq!(tables.edges().child(i as tsk_id_t).unwrap(), row.child);
666657
assert!(row.metadata.is_none());
667658
}
668-
for (i, row) in tables.edges_iter(true).enumerate() {
659+
for row in tables.edges_iter(true) {
660+
assert!(close_enough(tables.edges().left(row.id).unwrap(), row.left));
669661
assert!(close_enough(
670-
tables.edges().left(i as tsk_id_t).unwrap(),
671-
row.left
672-
));
673-
assert!(close_enough(
674-
tables.edges().right(i as tsk_id_t).unwrap(),
662+
tables.edges().right(row.id).unwrap(),
675663
row.right
676664
));
677-
assert_eq!(tables.edges().parent(i as tsk_id_t).unwrap(), row.parent);
678-
assert_eq!(tables.edges().child(i as tsk_id_t).unwrap(), row.child);
665+
assert_eq!(tables.edges().parent(row.id).unwrap(), row.parent);
666+
assert_eq!(tables.edges().child(row.id).unwrap(), row.child);
679667
assert!(row.metadata.is_none());
680668
}
681669
}
@@ -728,15 +716,12 @@ mod test {
728716
}
729717
assert_eq!(no_anc_state, 1);
730718
no_anc_state = 0;
731-
for (i, row) in tables.sites_iter(true).enumerate() {
732-
assert!(close_enough(
733-
sites.position(i as tsk_id_t).unwrap(),
734-
row.position
735-
));
719+
for row in tables.sites_iter(true) {
720+
assert!(close_enough(sites.position(row.id).unwrap(), row.position));
736721
if row.ancestral_state.is_some() {
737-
if i == 0 {
722+
if row.id == 0 {
738723
assert_eq!(row.ancestral_state.unwrap(), b"Eggnog");
739-
} else if i == 2 {
724+
} else if row.id == 2 {
740725
assert_eq!(row.ancestral_state.unwrap(), longer_metadata.as_bytes());
741726
}
742727
} else {
@@ -803,16 +788,13 @@ mod test {
803788
assert_eq!(nmuts, 3);
804789

805790
nmuts = 0;
806-
for (i, row) in tables.mutations_iter(true).enumerate() {
807-
assert_eq!(row.site, tables.mutations().site(i as tsk_id_t).unwrap());
808-
assert_eq!(row.node, tables.mutations().node(i as tsk_id_t).unwrap());
809-
assert_eq!(
810-
row.parent,
811-
tables.mutations().parent(i as tsk_id_t).unwrap()
812-
);
791+
for row in tables.mutations_iter(true) {
792+
assert_eq!(row.site, tables.mutations().site(row.id).unwrap());
793+
assert_eq!(row.node, tables.mutations().node(row.id).unwrap());
794+
assert_eq!(row.parent, tables.mutations().parent(row.id).unwrap());
813795
assert!(close_enough(
814796
row.time,
815-
tables.mutations().time(i as tsk_id_t).unwrap()
797+
tables.mutations().time(row.id).unwrap()
816798
));
817799
assert!(row.metadata.is_none());
818800
nmuts += 1;
@@ -981,6 +963,7 @@ mod test {
981963
fn test_edge_table_row_equality() {
982964
let tables = make_small_table_collection();
983965
for (i, row) in tables.edges_iter(true).enumerate() {
966+
assert!(row.id == i as tsk_id_t);
984967
assert!(row == tables.edges().row(i as tsk_id_t, true).unwrap());
985968
assert!(!(row != tables.edges().row(i as tsk_id_t, true).unwrap()));
986969
if i > 0 {
@@ -993,6 +976,7 @@ mod test {
993976
fn test_node_table_row_equality() {
994977
let tables = make_small_table_collection();
995978
for (i, row) in tables.nodes_iter(true).enumerate() {
979+
assert!(row.id == i as tsk_id_t);
996980
assert!(row == tables.nodes().row(i as tsk_id_t, true).unwrap());
997981
assert!(!(row != tables.nodes().row(i as tsk_id_t, true).unwrap()));
998982
}

0 commit comments

Comments
 (0)