(in-package #:topic-maps.ctm.tests) (defun run-association-graph-checks () ;; Reuse the independent graph reachability oracle from Slice 2. Construct a ;; binary Association first, then connect its four participating Topics. (let ((possible '((0 1) (0 2) (0 3) (1 2) (1 3) (2 3)))) (dotimes (mask 64) (let* ((edges (loop for edge in possible for bit from 0 when (logbitp bit mask) collect edge)) (components (graph-components '(0 1 2 3) edges))) (dolist (reverse-order '(nil t)) (let* ((map (topic-maps.tmdm:make-topic-map)) (topics (loop for i below 4 collect (api-topic map (format nil "node:~D" i)))) (association (topic-maps.tmdm:make-association map (first topics) (list (list (second topics) (third topics)) (list (third topics) (fourth topics))))) (retained (topic-maps.tmdm:association-roles association)) (label (format nil "association-graph:~D:~S:" mask reverse-order))) (dolist (edge (if reverse-order (reverse edges) edges)) (dolist (node edge) (topic-maps.tmdm:add-topic-identifier (nth node topics) :subject-identifier (format nil "urn:edge:~D:~D" (first edge) (second edge))))) (flet ((expected-root (node) (let ((component (find-if (lambda (c) (member node c)) components))) (topic-maps.tmdm:canonical-topic (nth (apply #'min component) topics))))) (let* ((roles (topic-maps.tmdm:association-roles association)) (expected (remove-duplicates (list (list (expected-root 1) (expected-root 2)) (list (expected-root 2) (expected-root 3))) :test #'equal))) (check (concatenate 'string label "association-type") (eq (expected-root 0) (topic-maps.tmdm::%association-type association))) (check (concatenate 'string label "role-signature-set") (and (= (length expected) (length roles)) (every (lambda (r) (member (list (topic-maps.tmdm::%association-role-type r) (topic-maps.tmdm::%association-role-player r)) expected :test #'equal)) roles))) (check (concatenate 'string label "retained-role-handles") (every (lambda (r) (member (topic-maps.tmdm:canonical-association-role r) roles :test #'eq)) retained)) (check (concatenate 'string label "raw-reference-integrity") (association-invariants map))))))))))