]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/association-graphs.lisp
Implement CTM Include and source-preserving template import
[topic-maps.git] / tests / association-graphs.lisp
1 (in-package #:topic-maps.ctm.tests)
2
3 (defun run-association-graph-checks ()
4 ;; Reuse the independent graph reachability oracle from Slice 2. Construct a
5 ;; binary Association first, then connect its four participating Topics.
6 (let ((possible '((0 1) (0 2) (0 3) (1 2) (1 3) (2 3))))
7 (dotimes (mask 64)
8 (let* ((edges (loop for edge in possible for bit from 0 when (logbitp bit mask) collect edge))
9 (components (graph-components '(0 1 2 3) edges)))
10 (dolist (reverse-order '(nil t))
11 (let* ((map (topic-maps.tmdm:make-topic-map))
12 (topics (loop for i below 4 collect (api-topic map (format nil "node:~D" i))))
13 (association (topic-maps.tmdm:make-association map (first topics)
14 (list (list (second topics) (third topics)) (list (third topics) (fourth topics)))))
15 (retained (topic-maps.tmdm:association-roles association))
16 (label (format nil "association-graph:~D:~S:" mask reverse-order)))
17 (dolist (edge (if reverse-order (reverse edges) edges))
18 (dolist (node edge)
19 (topic-maps.tmdm:add-topic-identifier (nth node topics) :subject-identifier
20 (format nil "urn:edge:~D:~D" (first edge) (second edge)))))
21 (flet ((expected-root (node)
22 (let ((component (find-if (lambda (c) (member node c)) components)))
23 (topic-maps.tmdm:canonical-topic (nth (apply #'min component) topics)))))
24 (let* ((roles (topic-maps.tmdm:association-roles association))
25 (expected (remove-duplicates
26 (list (list (expected-root 1) (expected-root 2))
27 (list (expected-root 2) (expected-root 3))) :test #'equal)))
28 (check (concatenate 'string label "association-type")
29 (eq (expected-root 0) (topic-maps.tmdm::%association-type association)))
30 (check (concatenate 'string label "role-signature-set")
31 (and (= (length expected) (length roles))
32 (every (lambda (r)
33 (member (list (topic-maps.tmdm::%association-role-type r)
34 (topic-maps.tmdm::%association-role-player r)) expected :test #'equal)) roles)))
35 (check (concatenate 'string label "retained-role-handles")
36 (every (lambda (r) (member (topic-maps.tmdm:canonical-association-role r) roles :test #'eq)) retained))
37 (check (concatenate 'string label "raw-reference-integrity") (association-invariants map))))))))))