Skip to content

Commit

Permalink
#65 zero to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 17, 2023
1 parent 4d62bc2 commit f1a40d8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ impl Sodg {
}
}
let mut rename: HashMap<u32, u32> = HashMap::new();
if g.vertices.contains_key(&0) && self.vertices.contains_key(&0) {
rename.insert(0, 0);
}
for (_, vtx) in self.vertices.iter() {
for e in vtx.edges.iter() {
if toxic.contains(&e.to) {
Expand Down Expand Up @@ -306,6 +309,8 @@ fn understands_same_name_kids() -> Result<()> {
extra.bind(1, 2, "x")?;
g.merge(&extra)?;
assert_eq!(5, g.vertices.len());
assert_eq!(1, g.kid(0, "a").unwrap().0);
assert_eq!(2, g.kid(1, "x").unwrap().0);
Ok(())
}

Expand Down Expand Up @@ -371,3 +376,41 @@ fn mixed_injection() -> Result<()> {
assert_eq!(3, g.vertices.len());
Ok(())
}

#[test]
fn zero_to_zero() -> Result<()> {
let mut g = Sodg::empty();
g.add(0)?;
g.add(1)?;
g.bind(0, 1, "a")?;
g.bind(1, 0, "back")?;
g.add(2)?;
g.bind(0, 2, "b")?;
let mut extra = Sodg::empty();
extra.add(0)?;
extra.add(1)?;
extra.bind(0, 1, "c")?;
extra.bind(1, 0, "back")?;
g.merge(&extra)?;
assert_eq!(4, g.vertices.len());
Ok(())
}

#[cfg(test)]
use crate::Script;

#[test]
fn two_big_graphs() -> Result<()> {
let mut g = Sodg::empty();
Script::from_str(
"ADD(0); ADD(1); BIND(0, 1, foo);
ADD(2); BIND(0, 1, alpha);
BIND(1, 0, back);",
)
.deploy_to(&mut g)?;
let mut extra = Sodg::empty();
Script::from_str("ADD(0); ADD(1); BIND(0, 1, bar); BIND(1, 0, back);").deploy_to(&mut extra)?;
g.merge(&extra)?;
assert_eq!(4, g.vertices.len());
Ok(())
}

0 comments on commit f1a40d8

Please sign in to comment.