11module TestRelationalPrograms
2+
23using Test
34
45using Catlab. CategoricalAlgebra. CSets
@@ -49,14 +50,16 @@ d = RelationDiagram(0)
4950add_box! (d, 0 , name= :A )
5051@test parsed == d
5152
52- # Typed
53+
54+ # Typed by Symbols
5355# ------
5456
5557parsed = @relation (x,y,z) where (x:: X , y:: Y , z:: Z , w:: W ) begin
5658 R (x,w)
5759 S (y,w)
5860 T (z,w)
5961end
62+
6063d = RelationDiagram ([:X ,:Y ,:Z ])
6164add_box! (d, [:X ,:W ], name= :R )
6265add_box! (d, [:Y ,:W ], name= :S )
@@ -66,6 +69,67 @@ set_junction!(d, [1,4,2,4,3,4])
6669set_junction! (d, [1 ,2 ,3 ], outer= true )
6770@test parsed == d
6871
72+
73+ # Typed by Integers
74+ # ------
75+
76+ parsed = @relation (x,y,z) where (x: :1 , y: :2 , z: :3 , w: :4 ) begin
77+ R (x,w)
78+ S (y,w)
79+ T (z,w)
80+ end
81+
82+ d = RelationDiagram ([:1 ,:2 ,:3 ])
83+ add_box! (d, [:1 ,:4 ], name= :R )
84+ add_box! (d, [:2 ,:4 ], name= :S )
85+ add_box! (d, [:3 ,:4 ], name= :T )
86+ add_junctions! (d, [:1 ,:2 ,:3 ,:4 ], variable= [:x ,:y ,:z ,:w ])
87+ set_junction! (d, [1 ,4 ,2 ,4 ,3 ,4 ])
88+ set_junction! (d, [1 ,2 ,3 ], outer= true )
89+ @test parsed == d
90+
91+
92+
93+ # Typed by Expressions
94+ # ------
95+
96+ parsed = @relation (x,y,z) where (x:: n (1 ), y:: n (2 ), z:: n (3 ), w:: n (4 )) begin
97+ R (x,w)
98+ S (y,w)
99+ T (z,w)
100+ end
101+
102+ d = RelationDiagram ([:(n (1 )), :(n (2 )), :(n (3 ))])
103+ add_box! (d, [:(n (1 )),:(n (4 ))], name= :R )
104+ add_box! (d, [:(n (2 )),:(n (4 ))], name= :S )
105+ add_box! (d, [:(n (3 )),:(n (4 ))], name= :T )
106+ add_junctions! (d, [:(n (1 )),:(n (2 )),:(n (3 )),:(n (4 ))], variable= [:x ,:y ,:z ,:w ])
107+ set_junction! (d, [1 ,4 ,2 ,4 ,3 ,4 ])
108+ set_junction! (d, [1 ,2 ,3 ], outer= true )
109+ @test parsed == d
110+
111+ # Mixed types
112+ # ------
113+
114+ parsed = @relation (x,y,z) where (x:: n (1 ), y: :2 , z:: C , w:: nothing ) begin
115+ R (x,w)
116+ S (y,w)
117+ T (z,w)
118+ end
119+
120+ d = RelationDiagram ([:(n (1 )), :2 , :C ])
121+ add_box! (d, [:(n (1 )),:nothing ], name= :R )
122+ add_box! (d, [:2 ,:nothing ], name= :S )
123+ add_box! (d, [:C ,:nothing ], name= :T )
124+ add_junctions! (d, [:(n (1 )),:2 ,:C ,:nothing ], variable= [:x ,:y ,:z ,:w ])
125+ set_junction! (d, [1 ,4 ,2 ,4 ,3 ,4 ])
126+ set_junction! (d, [1 ,2 ,3 ], outer= true )
127+ @test parsed == d
128+
129+
130+
131+
132+
69133# Special case: closed diagram.
70134sird_uwd = @relation () where (S:: Pop , I:: Pop , R:: Pop , D:: Pop ) begin
71135 infect (S,I,I,I) # inf
0 commit comments