use sparrowdb_bench::realworld::{self, ReactomeConfig};
use sparrowdb_execution::types::Value;
fn setup_reactome() -> (
tempfile::TempDir,
sparrowdb::GraphDb,
realworld::RealWorldStats,
u64, // first pathway pid
u64, // first sub-pathway pid
) {
let dir = tempfile::tempdir().expect("tempdir");
let db = sparrowdb::open(dir.path()).expect("open db");
let cfg = ReactomeConfig {
pathways: 5,
reactions_per_pathway: 4,
entities: 20,
seed: 42,
};
let stats = realworld::load_reactome(&db, &cfg).expect("load reactome");
db.checkpoint().expect("checkpoint");
let first_pid = cfg.entities as u64 + 1;
let first_sub_pid = cfg.entities as u64 + 2;
(dir, db, stats, first_pid, first_sub_pid)
}
#[test]
fn reactome_loads_expected_node_counts() {
let (_dir, db, stats, _, _) = setup_reactome();
assert_eq!(
stats.nodes_created, 50,
"expected 50 nodes, got {}",
stats.nodes_created
);
assert!(
stats.edges_created > 0,
"should create edges, got {}",
stats.edges_created
);
let result = db
.execute("MATCH (e:PhysicalEntity) RETURN COUNT(e)")
.expect("count PhysicalEntity");
let count = match &result.rows[0][0] {
Value::Int64(n) => *n,
other => panic!("expected Int64, got {:?}", other),
};
assert_eq!(count, 20, "PhysicalEntity count should be 20, got {count}");
let result = db
.execute("MATCH (p:Pathway) RETURN COUNT(p)")
.expect("count Pathway");
let count = match &result.rows[0][0] {
Value::Int64(n) => *n,
other => panic!("expected Int64, got {:?}", other),
};
assert_eq!(count, 10, "Pathway count should be 10, got {count}");
let result = db
.execute("MATCH (r:Reaction) RETURN COUNT(r)")
.expect("count Reaction");
let count = match &result.rows[0][0] {
Value::Int64(n) => *n,
other => panic!("expected Int64, got {:?}", other),
};
assert_eq!(count, 20, "Reaction count should be 20, got {count}");
}
#[test]
fn reactome_q3_1hop_returns_components() {
let (_dir, db, _, first_pid, _) = setup_reactome();
let components = realworld::q3_pathway_components(&db, first_pid).expect("q3");
assert_eq!(
components.len(),
1,
"parent pathway should have 1 direct component (sub-pathway), got {:?}",
components
);
}
#[test]
fn reactome_q4_2hop_finds_reactions() {
let (_dir, db, _, _, first_sub_pid) = setup_reactome();
let count = realworld::q4_pathway_reactions_2hop(&db, first_sub_pid).expect("q4");
assert_eq!(
count, 4,
"sub-pathway should have 4 direct reaction components, got {count}"
);
}
#[test]
fn reactome_q8_shared_catalysts_returns_results() {
let (_dir, db, _, _, first_sub_pid) = setup_reactome();
let count = realworld::q8_shared_catalysts(&db, first_sub_pid).expect("q8");
assert!(
count > 0,
"should find at least one catalyst in the sub-pathway, got {count}"
);
}
#[test]
fn reactome_has_component_edges_present() {
let (_dir, db, _, _, _) = setup_reactome();
let result = db
.execute("MATCH ()-[r:HAS_COMPONENT]->() RETURN COUNT(r)")
.expect("count HAS_COMPONENT");
let count = match &result.rows[0][0] {
Value::Int64(n) => *n,
other => panic!("expected Int64, got {:?}", other),
};
assert_eq!(count, 25, "should have 25 HAS_COMPONENT edges, got {count}");
}
#[test]
fn reactome_next_step_chain_present() {
let (_dir, db, _, _, _) = setup_reactome();
let result = db
.execute("MATCH ()-[r:NEXT_STEP]->() RETURN COUNT(r)")
.expect("count NEXT_STEP");
let count = match &result.rows[0][0] {
Value::Int64(n) => *n,
other => panic!("expected Int64, got {:?}", other),
};
assert_eq!(count, 15, "should have 15 NEXT_STEP edges, got {count}");
}