From bcdb88165b9a9e670d94595216a735a2c5c910ca Mon Sep 17 00:00:00 2001 From: Fabian Murariu Date: Tue, 9 Jul 2024 11:46:15 +0100 Subject: [PATCH] use assert_graph_equals --- raphtory/src/db/api/view/serialise.rs | 32 +++++++++-------- raphtory/src/db/graph/graph.rs | 49 ++++++++++++++++----------- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/raphtory/src/db/api/view/serialise.rs b/raphtory/src/db/api/view/serialise.rs index 9f6fc0409..4e7b19b03 100644 --- a/raphtory/src/db/api/view/serialise.rs +++ b/raphtory/src/db/api/view/serialise.rs @@ -736,7 +736,10 @@ mod proto_test { use crate::{ core::DocumentInput, - db::api::{mutation::DeletionOps, properties::internal::ConstPropertiesOps}, + db::{ + api::{mutation::DeletionOps, properties::internal::ConstPropertiesOps}, + graph::graph::assert_graph_equal, + }, prelude::*, }; @@ -749,7 +752,7 @@ mod proto_test { g1.add_node(1, "Alice", NO_PROPS, None).unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -761,7 +764,7 @@ mod proto_test { .unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -778,7 +781,7 @@ mod proto_test { g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -790,7 +793,7 @@ mod proto_test { g1.add_edge(3, "Alice", "Bob", NO_PROPS, None).unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -801,10 +804,9 @@ mod proto_test { g1.delete_edge(19, "Alice", "Bob", None).unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = PersistentGraph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); let edge = g2.edge("Alice", "Bob").expect("Failed to get edge"); - let deletions = edge.deletions().iter().copied().collect::>(); assert_eq!(deletions, vec![19]); } @@ -819,7 +821,7 @@ mod proto_test { .unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -831,7 +833,7 @@ mod proto_test { .expect("Failed to update constant properties"); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -844,7 +846,7 @@ mod proto_test { .unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); } #[test] @@ -857,7 +859,7 @@ mod proto_test { g1.add_node(1, "Alice", props.clone(), None).unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); let node = g2.node("Alice").expect("Failed to get node"); @@ -883,7 +885,7 @@ mod proto_test { g1.add_edge(1, "Alice", "Bob", props.clone(), None).unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); let edge = g2.edge("Alice", "Bob").expect("Failed to get edge"); @@ -911,7 +913,7 @@ mod proto_test { .expect("Failed to update constant properties"); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); let edge = g2 .edge("Alice", "Bob") @@ -940,7 +942,7 @@ mod proto_test { .expect("Failed to update constant properties"); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); - assert_eq!(&g1, &g2); + assert_graph_equal(&g1, &g2); let node = g2.node("Alice").expect("Failed to get node"); @@ -965,6 +967,7 @@ mod proto_test { let temp_file = tempfile::NamedTempFile::new().unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); + assert_graph_equal(&g1, &g2); props.into_iter().for_each(|(name, prop)| { let id = g2.get_const_prop_id(name).expect("Failed to get prop id"); @@ -986,6 +989,7 @@ mod proto_test { let temp_file = tempfile::NamedTempFile::new().unwrap(); g1.stable_serialise(&temp_file).unwrap(); let g2 = Graph::decode(&temp_file).unwrap(); + assert_graph_equal(&g1, &g2); props .into_iter() diff --git a/raphtory/src/db/graph/graph.rs b/raphtory/src/db/graph/graph.rs index 70ec0556b..837531c27 100644 --- a/raphtory/src/db/graph/graph.rs +++ b/raphtory/src/db/graph/graph.rs @@ -46,26 +46,11 @@ pub fn graph_equal<'graph1, 'graph2, G1: GraphViewOps<'graph1>, G2: GraphViewOps ) -> bool { if g1.count_nodes() == g2.count_nodes() && g1.count_edges() == g2.count_edges() { g1.nodes().id().par_values().all(|v| g2.has_node(v)) && // all nodes exist in other - g1.nodes().par_iter().all(|v1| { - let c1 = v1.properties().constant().into_iter().count(); - let t1 = v1.properties().temporal().into_iter().count(); - g2.node(v1.id()).filter(|node|{ - c1 == node.properties().constant().into_iter().count() && - t1 == node.properties().temporal().into_iter().count() - }).is_some() - }) && g1.count_temporal_edges() == g2.count_temporal_edges() && // same number of exploded edges g1.edges().explode().iter().all(|e| { // all exploded edges exist in other - - let c1 = e.properties().constant().into_iter().count(); - let t1 = e.properties().temporal().into_iter().count(); g2 .edge(e.src().id(), e.dst().id()) - .filter(|ee| { - ee.active(e.time().expect("exploded")) && - c1 == e.properties().constant().into_iter().count() && - t1 == e.properties().temporal().into_iter().count() - }) + .filter(|ee| ee.active(e.time().expect("exploded"))) .is_some() }) } else { @@ -103,9 +88,22 @@ pub fn assert_graph_equal< g1.count_temporal_edges(), g2.count_temporal_edges() ); - for n_id in g1.nodes().id().values() { - assert!(g2.has_node(n_id), "missing node {n_id}"); + for n1 in g1.nodes() { + assert!(g2.has_node(n1.id()), "missing node {}", n1.id()); + + let c1 = n1.properties().constant().into_iter().count(); + let t1 = n1.properties().temporal().into_iter().count(); + let check = g2 + .node(n1.id()) + .filter(|node| { + c1 == node.properties().constant().into_iter().count() + && t1 == node.properties().temporal().into_iter().count() + }) + .is_some(); + + assert!(check, "node {:?} properties mismatch", n1.id()); } + for e in g1.edges().explode() { // all exploded edges exist in other let e2 = g2 @@ -116,7 +114,20 @@ pub fn assert_graph_equal< "exploded edge {:?} not active as expected at time {}", e2.id(), e.time().unwrap() - ) + ); + + let c1 = e.properties().constant().into_iter().count(); + let t1 = e.properties().temporal().into_iter().count(); + let check = g2 + .edge(e.src().id(), e.dst().id()) + .filter(|ee| { + ee.active(e.time().expect("exploded")) + && c1 == e.properties().constant().into_iter().count() + && t1 == e.properties().temporal().into_iter().count() + }) + .is_some(); + + assert!(check, "edge {:?} properties mismatch", e.id()); } }