@@ -13,6 +13,10 @@ fn and_gate() -> Gate {
1313 Gate :: new_logical ( "AND" . into ( ) , vec ! [ "A" . into( ) , "B" . into( ) ] , "Y" . into ( ) )
1414}
1515
16+ fn reg ( ) -> Gate {
17+ Gate :: new_logical ( "REG" . into ( ) , vec ! [ "D" . into( ) ] , "Q" . into ( ) )
18+ }
19+
1620fn get_simple_example ( ) -> Rc < GateNetlist > {
1721 let netlist = Netlist :: new ( "example" . to_string ( ) ) ;
1822
@@ -28,6 +32,28 @@ fn get_simple_example() -> Rc<GateNetlist> {
2832 netlist
2933}
3034
35+ fn divider_netlist ( ) -> Rc < GateNetlist > {
36+ let netlist = Netlist :: new ( "example" . to_string ( ) ) ;
37+
38+ // Add the the input
39+ let a = netlist. insert_input ( "a" . into ( ) ) ;
40+
41+ // Instantiate a reg
42+ let reg = netlist. insert_gate_disconnected ( reg ( ) , "inst_0" . into ( ) ) ;
43+
44+ // And last val and input
45+ let and = netlist
46+ . insert_gate ( and_gate ( ) , "inst_1" . into ( ) , & [ a, reg. get_output ( 0 ) ] )
47+ . unwrap ( ) ;
48+
49+ reg. find_input ( & "D" . into ( ) ) . unwrap ( ) . connect ( and. into ( ) ) ;
50+
51+ // Make this Reg an output
52+ reg. expose_with_name ( "y" . into ( ) ) ;
53+
54+ netlist
55+ }
56+
3157#[ test]
3258fn test_detect_cycles ( ) {
3359 let netlist = get_simple_example ( ) ;
@@ -54,6 +80,14 @@ fn test_detect_cycles() {
5480 assert ! ( dfs_iter. detect_cycles( ) ) ;
5581}
5682
83+ #[ test]
84+ fn test_detect_cycles2 ( ) {
85+ let netlist = divider_netlist ( ) ;
86+
87+ let dfs_iter = DFSIterator :: new ( & netlist, netlist. last ( ) . unwrap ( ) ) ;
88+ assert ! ( dfs_iter. detect_cycles( ) ) ;
89+ }
90+
5791#[ test]
5892fn test_attr_filter ( ) {
5993 let netlist = GateNetlist :: new ( "example" . to_string ( ) ) ;
0 commit comments