X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=unit-tests%2Ftest-graph-container.lisp;fp=unit-tests%2Ftest-graph-container.lisp;h=c2697da98419c16b2857e2f6b0d29dbf07878c7e;hb=900a931f109598249ebc33bea50b65abf998ed0b;hp=0000000000000000000000000000000000000000;hpb=5282d117ab0e8b7080bca9683e270f0d2a8f4d5c;p=cl-graph.git diff --git a/unit-tests/test-graph-container.lisp b/unit-tests/test-graph-container.lisp new file mode 100644 index 0000000..c2697da --- /dev/null +++ b/unit-tests/test-graph-container.lisp @@ -0,0 +1,77 @@ +(in-package metabang.graph) + +;;; --------------------------------------------------------------------------- +;;; utilities +;;; --------------------------------------------------------------------------- + +(defun make-simple-test-graph () + (let ((g (make-container 'graph-container))) + (loop for v in '(a b c d e) do + (add-vertex g v)) + (loop for (v1 . v2) in '((a . b) (a . c) (b . d) (c . e)) do + (add-edge-between-vertexes g v1 v2)) + g)) + +;;; --------------------------------------------------------------------------- +;;; tests +;;; --------------------------------------------------------------------------- + +(deftestsuite test-graph-container () ()) + +;;; --------------------------------------------------------------------------- + +(addtest (test-graph-container) + test-simple-copying + (let ((g1 (make-simple-test-graph)) + (g2 nil)) + (setf g2 (copy-top-level g1)) + (ensure-same (size g1) (size g2)) + (iterate-vertexes + g1 (lambda (v) + (ensure (find-vertex g2 (value v))))) + (iterate-edges + g1 (lambda (e) + (ensure (find-edge-between-vertexes + g2 (value (source-vertex e)) + (value (target-vertex e)))))))) + +;;; --------------------------------------------------------------------------- + +;; fails because find-edge-between-vertexes for graph containers doesn't +;; care about the graph... +(addtest (test-graph-container) + test-find-edge-between-vertexes + (let ((g1 (make-simple-test-graph)) + (g2 nil)) + (setf g2 (copy-top-level g1)) + + (ensure (not + (find-edge-between-vertexes g2 (find-vertex g1 'a) (find-vertex g1 'b)))))) + +;;; --------------------------------------------------------------------------- + +(addtest (test-graph-container) + test-empty! + (let ((g1 (make-simple-test-graph))) + (empty! g1) + (ensure-same (size g1) 0))) + +;;; --------------------------------------------------------------------------- +;;; vertex test +;;; --------------------------------------------------------------------------- + +;;?? should be in test-graph and work for every graph container type + +(addtest (test-graph-container) + no-vertex-test + (let ((g (make-container 'graph-container))) + (loop for (src dst) in '((a b) (a c) (c d) (a d) (d e) (e f) (b f)) do + (add-edge-between-vertexes g (list src) (list dst))) + (ensure-same (size g) 14 :test '=))) + +(addtest (test-graph-container) + vertex-test + (let ((g (make-container 'graph-container :vertex-test #'equal))) + (loop for (src dst) in '((a b) (a c) (c d) (a d) (d e) (e f) (b f)) do + (add-edge-between-vertexes g (list src) (list dst))) + (ensure-same (size g) 6 :test '=)))