|
| 1 | +use safety_net::netlist::Gate; |
| 2 | +use safety_net::netlist::GateNetlist; |
| 3 | +use safety_net::netlist::Netlist; |
| 4 | +use std::rc::Rc; |
| 5 | + |
| 6 | +fn and_gate() -> Gate { |
| 7 | + Gate::new_logical("AND".into(), vec!["A".into(), "B".into()], "Y".into()) |
| 8 | +} |
| 9 | + |
| 10 | +fn get_simple_example() -> Rc<GateNetlist> { |
| 11 | + let netlist = Netlist::new("example".to_string()); |
| 12 | + |
| 13 | + let a = netlist.insert_input("a".into()); |
| 14 | + let b = netlist.insert_input("b".into()); |
| 15 | + |
| 16 | + let instance = netlist |
| 17 | + .insert_gate(and_gate(), "inst_0".into(), &[a, b]) |
| 18 | + .unwrap(); |
| 19 | + |
| 20 | + instance.expose_with_name("y".into()); |
| 21 | + |
| 22 | + netlist |
| 23 | +} |
| 24 | + |
| 25 | +#[test] |
| 26 | +fn test_clean() { |
| 27 | + let netlist = get_simple_example(); |
| 28 | + assert!(netlist.verify().is_ok()); |
| 29 | + assert!(!netlist.clean().unwrap()); |
| 30 | + let inputs: Vec<_> = netlist.inputs().collect(); |
| 31 | + assert_eq!(inputs.len(), 2); |
| 32 | + let _new_cell = netlist |
| 33 | + .insert_gate(and_gate(), "inst_1".into(), &inputs) |
| 34 | + .unwrap(); |
| 35 | + assert!(netlist.verify().is_ok()); |
| 36 | + assert_eq!(netlist.objects().count(), 4); |
| 37 | + assert!(netlist.clean().unwrap()); |
| 38 | + assert_eq!(netlist.objects().count(), 3); |
| 39 | + assert!(!netlist.clean().unwrap()); |
| 40 | +} |
0 commit comments