-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-aom.lisp
81 lines (71 loc) · 2.62 KB
/
test-aom.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(in-package :clorb)
(define-test-suite "Active Object Map"
(variables
(aom (make-instance 'object-map))
(s1 "servant1")
(s2 "servant2")
(oid1 (string-to-oid "oid1"))
(oid2 (string-to-oid "oid2"))
(oid3 (string-to-oid "oid3")))
(define-test "basics"
(add-activation aom oid1 s1)
(ensure-eql (activation-count aom) 1)
(ensure (servant-active-p aom s1))
(ensure (not (servant-active-p aom s2)))
(ensure-eql (oid-servant aom oid1) s1)
(ensure-eql (servant-oid aom s1) oid1)
(ensure-eql (servant-oid aom s2) nil)
(ensure-equalp (servant-oid-list aom s1) (list oid1))
(add-activation aom oid2 s2)
(add-activation aom oid3 s2)
(ensure-eql (activation-count aom) 3)
(ensure (servant-active-p aom s1))
(ensure (servant-active-p aom s2))
(ensure-eql (oid-servant aom oid1) s1)
(ensure-eql (oid-servant aom oid2) s2)
(ensure-eql (oid-servant aom oid3) s2)
(ensure-eql (servant-oid aom s1) oid1)
(ensure-eql (servant-oid aom s2) t)
(ensure-equalp (servant-oid-list aom s1) (list oid1))
(ensure (null (set-exclusive-or (servant-oid-list aom s2) (list oid2 oid3))))
(remove-activation aom oid2)
(ensure-eql (activation-count aom) 2)
(ensure (servant-active-p aom s1))
(ensure (servant-active-p aom s2))
(ensure-eql (oid-servant aom oid1) s1)
(ensure-eql (oid-servant aom oid2) nil)
(ensure-eql (oid-servant aom oid3) s2)
(ensure-eql (servant-oid aom s1) oid1)
(ensure-eql (servant-oid aom s2) oid3))
(define-test "Map"
(add-activation aom oid1 s1)
(add-activation aom oid2 s2)
(add-activation aom oid3 s2)
(let ((oids nil)
(servants nil))
(map-activations aom
(lambda (oid servant)
(push oid oids)
(push servant servants)))
(ensure-eql (length oids) 3)
(ensure (member oid1 oids))
(ensure (member oid2 oids))
(ensure (member oid3 oids))
(ensure (null (set-exclusive-or servants (list s1 s2))))))
(define-test "Map Mutable"
(add-activation aom oid1 s1)
(add-activation aom oid2 s2)
(add-activation aom oid3 s2)
(let ((oids nil)
(servants nil))
(map-activations aom
(lambda (oid servant)
(remove-activation aom oid1)
(remove-activation aom oid2)
(remove-activation aom oid3)
(push oid oids)
(push servant servants))
t)
(ensure-eql (length oids) 1)
(ensure-eql (length servants) 1) ))
#|end|#)