Skip to content

Commit

Permalink
add identity insertion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Aug 31, 2023
1 parent 9040264 commit 344d983
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions src/hugr/rewrite/insert_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,55 @@ impl Rewrite for IdentityInsertion {

#[cfg(test)]
mod tests {
use rstest::{fixture, rstest};
use rstest::rstest;

use crate::Hugr;
use super::super::simple_replace::test::dfg_hugr;
use super::*;
use crate::{
algorithm::nest_cfgs::test::build_conditional_in_loop_cfg, extension::prelude::QB_T,
ops::handle::NodeHandle, Hugr,
};

#[fixture]
fn sample() -> Hugr {
todo!()
}
#[rstest]
fn correct_insertion() {}
fn correct_insertion(dfg_hugr: Hugr) {
let mut h = dfg_hugr;

assert_eq!(h.node_count(), 6);

let final_node = h
.input_neighbours(h.get_io(h.root()).unwrap()[1])
.next()
.unwrap();

let final_node_port = h.node_inputs(final_node).next().unwrap();

let rw = IdentityInsertion::new(final_node, final_node_port);

let noop_node = h.apply_rewrite(rw).unwrap();

assert_eq!(h.node_count(), 7);

let noop: LeafOp = h.get_optype(noop_node).clone().try_into().unwrap();

assert_eq!(noop, LeafOp::Noop { ty: QB_T });
}

#[test]
fn incorrect_insertion() {
let (mut h, _, tail) = build_conditional_in_loop_cfg(false).unwrap();

let final_node = tail.node();

let final_node_port = h.node_inputs(final_node).next().unwrap();

let rw = IdentityInsertion::new(final_node, final_node_port);

let apply_result = h.apply_rewrite(rw);
assert_eq!(
apply_result,
Err(IdentityInsertionError::InvalidPortKind(Some(
EdgeKind::ControlFlow
)))
);
}
}

0 comments on commit 344d983

Please sign in to comment.