OSDN Git Service

[1] The test for 'replace' was modified.
authorU-tackya-PC\tackya <yammouch@users.sourceforge.jp>
Fri, 26 Aug 2011 05:05:32 +0000 (14:05 +0900)
committerU-tackya-PC\tackya <yammouch@users.sourceforge.jp>
Fri, 26 Aug 2011 05:05:32 +0000 (14:05 +0900)
test/graph.clj

index 069b14e..8e45e6d 100755 (executable)
                                     [?n1 not1]
                                     ]))))))
 
-;(deftest test-replace
-;  (let [gr (struct gr/graph 7
-;                   '[[[]    [in-0 in a]   [e-1]]
-;                     [[e-1] [not1-2 not1] [e-3]]
-;                     [[e-3] [not1-4 not1] [e-5]]
-;                     [[e-5] [out-6 out z] []   ]])
-;        bfr '[[[?b0] [?b1 not1] [?b2]]
-;              [[?b2] [?b3 not1] [?b4]]]
-;        aft '[[[?b0] [?a1 short] [?b4]]]
-;        dep '[?b4]
-;        aft-gr (gr/replace gr {:bfr bfr, :aft aft, :dep dep})]
-;    (is (not= um/fail
-;              (um/unify (:conns aft-gr)
-;                        '[[[]    [in-0 in a]   [?x1]]
-;                          [[?x1] [out-6 out z] []   ]
-;                          ]))))
-;  (let [gr (struct gr/graph 5
-;                   '[[[]    [in-0 in a]   [e-1]]
-;                     [[e-1] [not1-2 not1] [e-3]]
-;                     [[e-3] [out-4 out z] []   ]])
-;        bfr '[[[?b0] [?b1 not1] [?b2]]]
-;        aft '[[[?b0] [?a1 not1] [?b2]]]
-;        dep '[?b2]
-;        aft-gr (gr/replace gr {:bfr bfr, :aft aft, :dep dep} 100)]
-;    (is (not= um/fail
-;              (um/unify (:conns aft-gr)
-;                        '[[[]    [in-0 in a]   [e-1]]
-;                          [[?x2] [out-4 out z] []   ]
-;                          [[e-1] [?x1 not1]    [?x2]]
-;                          ])))))
+; before
 ;
+;  _      |\        |\        _
+; |_|-----| >o------| >o-----|_|
+;         |/        |/
+;
+; after
+;  _                          _
+; |_|------------------------|_|
+;
+(deftest test-replace
+  (let [gr (struct gr/graph 7
+                   '[[n-0 in a]
+                     [n-2 not1]
+                     [n-4 not1]
+                     [n-6 out z]
+                     ]
+                   '[[e-1 [n-0 0] [n-2 0]]
+                     [e-3 [n-2 0] [n-4 0]]
+                     [e-5 [n-4 0] [n-6 0]]
+                     ])
+        bfr {:nodes '[[?bn2 not1]
+                      [?bn4 not1]
+                      ]
+             :edges '[[?be1 ?bt0     [?bn2 0]]
+                      [?be3 [?bn2 0] [?bn4 0]]
+                      [?be5 [?bn4 0] ?bt6    ]
+                      ]}
+        cut '[?be5]
+        aft {:nodes '[]
+             :edges '[[?ae1 ?bt0 ?bt6]]}
+        aft-gr (gr/replace gr {:bfr bfr, :cut cut, :aft aft})]
+    (is (not= um/fail
+              (um/unify (:edges aft-gr)
+                        '[[?e0 [n-0 0] [n-6 0]]
+                          ]
+                        (um/unify (:nodes aft-gr)
+                                  '[[n-0 in a]
+                                    [n-6 out z]
+                                    ])))))
+  (let [gr (struct gr/graph 7
+                   '[[n-0 in a]
+                     [n-2 not1]
+                     [n-4 out z]
+                     ]
+                   '[[e-1 [n-0 0] [n-2 0]]
+                     [e-3 [n-2 0] [n-4 0]]
+                     ])
+        bfr {:nodes '[[?bn2 not1]
+                      ]
+             :edges '[[?be1 ?bt0     [?bn2 0]]
+                      [?be3 [?bn2 0] ?bt4    ]
+                      ]}
+        cut '[?be3]
+        aft {:nodes '[?an2 not1]
+             :edges '[[?ae1 ?bt0     [?an2 0]]
+                      [?ae3 [?an2 0] ?bt4    ]
+                      ]}
+        aft-gr (gr/replace gr {:bfr bfr, :cut cut, :aft aft})]
+    (is (not= um/fail
+              (um/unify (:edges aft-gr)
+                        '[[?e1 [n-0 0] [?n2 0]]
+                          [?e3 [?n2 0] [n-4 0]]
+                          ]
+                        (um/unify (:nodes aft-gr)
+                                  '[[n-0 in a]
+                                    [?n2 not1]
+                                    [n-4 out z]
+                                    ]))))))
+
 ;(deftest test-can-be-bfr?
 ;  (let [gr0 (struct gr/graph 10
 ;                    '[[[]    [in-0 in a]   [e-1]]